never filter own posts (#4742)

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
This commit is contained in:
Konrad Pozniak 2024-11-05 20:43:52 +01:00 committed by GitHub
parent a56c14340e
commit 0d34804359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 12 deletions

View File

@ -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
}

View File

@ -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. */

View File

@ -304,7 +304,7 @@ class NetworkTimelineViewModel @Inject constructor(
}
override fun clearWarning(status: StatusViewData.Concrete) {
updateStatusByActionableId(status.id) {
updateStatusByActionableId(status.actionableId) {
it.copy(filtered = emptyList())
}
}

View File

@ -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
@ -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) ||

View File

@ -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()
@ -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 ->
@ -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")
@ -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
)
@ -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)