Adds filter event to opt in to thread notifications

This commit is contained in:
ericdecanini 2022-10-19 17:02:32 -04:00
parent ed9ecb7fc9
commit 2379ce673b
7 changed files with 41 additions and 22 deletions

View File

@ -47,11 +47,10 @@ data class RoomSync(
*/ */
@Json(name = "unread_notifications") val unreadNotifications: RoomSyncUnreadNotifications? = null, @Json(name = "unread_notifications") val unreadNotifications: RoomSyncUnreadNotifications? = null,
/** /**
* The count of threads with unread notifications (not the total # of notifications in all threads) * The count of threads with unread notifications (not the total # of notifications in all threads)
*/ */
@Json(name = "org.matrix.msc3773.unread_thread_notifications") val unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null, @Json(name = "unread_thread_notifications") val unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null,
/** /**
* The room summary. * The room summary.

View File

@ -56,6 +56,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo036
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo037 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo037
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo038 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo038
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo039 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo039
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo041
import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.Normalizer
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject import javax.inject.Inject
@ -64,7 +65,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
private val normalizer: Normalizer private val normalizer: Normalizer
) : MatrixRealmMigration( ) : MatrixRealmMigration(
dbName = "Session", dbName = "Session",
schemaVersion = 39L, schemaVersion = 41L,
) { ) {
/** /**
* Forces all RealmSessionStoreMigration instances to be equal. * Forces all RealmSessionStoreMigration instances to be equal.
@ -113,5 +114,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldVersion < 37) MigrateSessionTo037(realm).perform() if (oldVersion < 37) MigrateSessionTo037(realm).perform()
if (oldVersion < 38) MigrateSessionTo038(realm).perform() if (oldVersion < 38) MigrateSessionTo038(realm).perform()
if (oldVersion < 39) MigrateSessionTo039(realm).perform() if (oldVersion < 39) MigrateSessionTo039(realm).perform()
if (oldVersion < 41) MigrateSessionTo041(realm).perform()
} }
} }

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.database.migration
import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import org.matrix.android.sdk.internal.util.database.RealmMigrator
internal class MigrateSessionTo041(realm: DynamicRealm) : RealmMigrator(realm, 41) {
override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("RoomSummaryEntity")
?.addField(RoomSummaryEntityFields.THREAD_HIGHLIGHT_COUNT, Int::class.java)
?.addField(RoomSummaryEntityFields.THREAD_NOTIFICATION_COUNT, Int::class.java)
}
}

View File

@ -110,8 +110,7 @@ internal fun RealmQuery<TimelineEventEntity>.filterEvents(filters: TimelineEvent
endGroup() endGroup()
} }
if (filters.filterUseless) { if (filters.filterUseless) {
not() not().equalTo(TimelineEventEntityFields.ROOT.IS_USELESS, true)
.equalTo(TimelineEventEntityFields.ROOT.IS_USELESS, true)
} }
if (filters.filterEdits) { if (filters.filterEdits) {
not().like(TimelineEventEntityFields.ROOT.CONTENT, TimelineEventFilter.Content.EDIT) not().like(TimelineEventEntityFields.ROOT.CONTENT, TimelineEventFilter.Content.EDIT)

View File

@ -29,7 +29,6 @@ internal object FilterFactory {
// senders = listOf(userId), // senders = listOf(userId),
// relationSenders = userId?.let { listOf(it) }, // relationSenders = userId?.let { listOf(it) },
relationTypes = listOf(RelationType.THREAD), relationTypes = listOf(RelationType.THREAD),
enableUnreadThreadNotifications = true,
) )
} }
@ -39,7 +38,6 @@ internal object FilterFactory {
containsUrl = true, containsUrl = true,
types = listOf(EventType.MESSAGE), types = listOf(EventType.MESSAGE),
lazyLoadMembers = true, lazyLoadMembers = true,
enableUnreadThreadNotifications = true,
) )
} }
@ -57,32 +55,23 @@ internal object FilterFactory {
} }
fun createDefaultRoomFilter(): RoomEventFilter { fun createDefaultRoomFilter(): RoomEventFilter {
return RoomEventFilter( return RoomEventFilter(lazyLoadMembers = true)
lazyLoadMembers = true
)
} }
fun createElementRoomFilter(): RoomEventFilter { fun createElementRoomFilter(): RoomEventFilter {
return RoomEventFilter( return RoomEventFilter(
lazyLoadMembers = true, lazyLoadMembers = true,
enableUnreadThreadNotifications = true,
// TODO Enable this for optimization // TODO Enable this for optimization
// types = (listOfSupportedEventTypes + listOfSupportedStateEventTypes).toMutableList() // types = (listOfSupportedEventTypes + listOfSupportedStateEventTypes).toMutableList()
) )
} }
private fun createElementTimelineFilter(): RoomEventFilter? { private fun createElementTimelineFilter(): RoomEventFilter? {
return null // RoomEventFilter().apply { return RoomEventFilter(enableUnreadThreadNotifications = true)
// TODO Enable this for optimization
// types = listOfSupportedEventTypes.toMutableList()
// }
} }
private fun createElementStateFilter(): RoomEventFilter { private fun createElementStateFilter(): RoomEventFilter {
return RoomEventFilter( return RoomEventFilter(lazyLoadMembers = true)
lazyLoadMembers = true,
enableUnreadThreadNotifications = true,
)
} }
// Get only managed types by Element // Get only managed types by Element

View File

@ -81,7 +81,7 @@ internal data class RoomEventFilter(
/** /**
* If true, this will opt-in for the server to return unread threads notifications in [RoomSync] * If true, this will opt-in for the server to return unread threads notifications in [RoomSync]
*/ */
@Json(name = "org.matrix.msc3773.unread_thread_notifications") val enableUnreadThreadNotifications: Boolean? = null, @Json(name = "unread_thread_notifications") val enableUnreadThreadNotifications: Boolean? = null,
) { ) {
fun toJSONString(): String { fun toJSONString(): String {

View File

@ -140,7 +140,7 @@ internal class DefaultSyncTask @Inject constructor(
executeRequest(globalErrorReceiver) { executeRequest(globalErrorReceiver) {
syncAPI.sync( syncAPI.sync(
params = requestParams, params = requestParams,
readTimeOut = readTimeOut readTimeOut = readTimeOut,
) )
} }
} }
@ -178,7 +178,7 @@ internal class DefaultSyncTask @Inject constructor(
syncRequestStateTracker.setSyncRequestState( syncRequestStateTracker.setSyncRequestState(
SyncRequestState.IncrementalSyncParsing( SyncRequestState.IncrementalSyncParsing(
rooms = nbRooms, rooms = nbRooms,
toDevice = nbToDevice toDevice = nbToDevice,
) )
) )
syncResponseHandler.handleResponse(syncResponse, token, null) syncResponseHandler.handleResponse(syncResponse, token, null)