Skip to content

Commit

Permalink
never filter own posts (#4742)
Browse files Browse the repository at this point in the history
This is to match Mastodon web behavior.

Also, make revealing filtered boosts in non-cached timelines work (can
only happen on user profiles, other timelines don't have boosts).

found thanks to this: https://tech.lgbt/@darkfox/113378644538792719
  • Loading branch information
connyduck authored Nov 5, 2024
1 parent a56c143 commit 0d34804
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class NotificationsViewModel @Inject constructor(
return when ((notificationViewData as? NotificationViewData.Concrete)?.type) {
Notification.Type.MENTION, Notification.Type.POLL -> {
notificationViewData.statusViewData?.let { statusViewData ->
if (statusViewData.status.account.id == account.accountId) {
return Filter.Action.NONE
}
statusViewData.filterAction = filterModel.shouldFilterStatus(statusViewData.actionable)
return statusViewData.filterAction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class CachedTimelineViewModel @Inject constructor(
filterModel
) {

private val account = accountManager.activeAccount!!

private var currentPagingSource: PagingSource<Int, HomeTimelineData>? = null

/** Map from status id to translation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class NetworkTimelineViewModel @Inject constructor(
}

override fun clearWarning(status: StatusViewData.Concrete) {
updateStatusByActionableId(status.id) {
updateStatusByActionableId(status.actionableId) {
it.copy(filtered = emptyList())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ abstract class TimelineViewModel(
private val filterModel: FilterModel
) : ViewModel() {

protected val account = accountManager.activeAccount!!

abstract val statuses: Flow<PagingData<StatusViewData>>

var kind: Kind = Kind.HOME
Expand Down Expand Up @@ -179,6 +181,10 @@ abstract class TimelineViewModel(

protected fun shouldFilterStatus(statusViewData: StatusViewData): Filter.Action {
val status = statusViewData.asStatusOrNull()?.status ?: return Filter.Action.NONE
if (status.actionableStatus.account.id == account.accountId) {
// never filter own posts
return Filter.Action.NONE
}
return if (
(status.inReplyToId != null && filterRemoveReplies) ||
(status.reblog != null && filterRemoveReblogs) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class ViewThreadViewModel @Inject constructor(
private val moshi: Moshi
) : ViewModel() {

private val activeAccount = accountManager.activeAccount!!

private val _uiState = MutableStateFlow(ThreadUiState.Loading as ThreadUiState)
val uiState: Flow<ThreadUiState> = _uiState.asStateFlow()

Expand All @@ -80,14 +82,10 @@ class ViewThreadViewModel @Inject constructor(

var isInitialLoad: Boolean = true

private val alwaysShowSensitiveMedia: Boolean
private val alwaysOpenSpoiler: Boolean
private val alwaysShowSensitiveMedia: Boolean = activeAccount.alwaysShowSensitiveMedia
private val alwaysOpenSpoiler: Boolean = activeAccount.alwaysOpenSpoiler

init {
val activeAccount = accountManager.activeAccount
alwaysShowSensitiveMedia = activeAccount?.alwaysShowSensitiveMedia ?: false
alwaysOpenSpoiler = activeAccount?.alwaysOpenSpoiler ?: false

viewModelScope.launch {
eventHub.events
.collect { event ->
Expand All @@ -109,7 +107,7 @@ class ViewThreadViewModel @Inject constructor(
val filterCall = async { filterModel.init(Filter.Kind.THREAD) }

val contextCall = async { api.statusContext(id) }
val statusAndAccount = db.timelineStatusDao().getStatusWithAccount(accountManager.activeAccount!!.id, id)
val statusAndAccount = db.timelineStatusDao().getStatusWithAccount(activeAccount.id, id)

var detailedStatus = if (statusAndAccount != null) {
Log.d(TAG, "Loaded status from local timeline")
Expand Down Expand Up @@ -142,7 +140,7 @@ class ViewThreadViewModel @Inject constructor(
if (statusAndAccount != null) {
api.status(id).onSuccess { result ->
db.timelineStatusDao().update(
tuskyAccountId = accountManager.activeAccount!!.id,
tuskyAccountId = activeAccount.id,
status = result,
moshi = moshi
)
Expand Down Expand Up @@ -421,7 +419,7 @@ class ViewThreadViewModel @Inject constructor(

private fun List<StatusViewData.Concrete>.filter(): List<StatusViewData.Concrete> {
return filter { status ->
if (status.isDetailed) {
if (status.isDetailed || status.status.account.id == activeAccount.accountId) {
true
} else {
status.filterAction = filterModel.shouldFilterStatus(status.status)
Expand Down

0 comments on commit 0d34804

Please sign in to comment.