Adds API parsing of unread threads notifications

This commit is contained in:
ericdecanini 2022-10-07 11:16:41 -04:00
parent 9827ffb1e5
commit 00bfbe9bc6
6 changed files with 62 additions and 7 deletions

View File

@ -47,6 +47,12 @@ 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)
*/
@Json(name = "org.matrix.msc3773.unread_thread_notifications") val unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null,
/** /**
* The room summary. * The room summary.
*/ */

View File

@ -0,0 +1,33 @@
/*
* Copyright 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.api.session.sync.model
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class RoomSyncUnreadThreadNotifications(
/**
* The number of threads with unread messages that match the push notification rules.
*/
@Json(name = "notification_count") val notificationCount: Int? = null,
/**
* The number of threads with highlighted unread messages (subset of notifications).
*/
@Json(name = "highlight_count") val highlightCount: Int? = null
)

View File

@ -28,7 +28,8 @@ internal object FilterFactory {
limit = numberOfEvents, limit = numberOfEvents,
// 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,
) )
} }
@ -37,7 +38,8 @@ internal object FilterFactory {
limit = numberOfEvents, limit = numberOfEvents,
containsUrl = true, containsUrl = true,
types = listOf(EventType.MESSAGE), types = listOf(EventType.MESSAGE),
lazyLoadMembers = true lazyLoadMembers = true,
enableUnreadThreadNotifications = true,
) )
} }
@ -62,7 +64,8 @@ internal object FilterFactory {
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()
) )
@ -77,7 +80,8 @@ internal object FilterFactory {
private fun createElementStateFilter(): RoomEventFilter { private fun createElementStateFilter(): RoomEventFilter {
return RoomEventFilter( return RoomEventFilter(
lazyLoadMembers = true lazyLoadMembers = true,
enableUnreadThreadNotifications = true,
) )
} }

View File

@ -17,6 +17,7 @@ package org.matrix.android.sdk.internal.session.filter
import com.squareup.moshi.Json import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.session.sync.model.RoomSync
import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.MoshiProvider
/** /**
@ -76,7 +77,11 @@ internal data class RoomEventFilter(
/** /**
* If true, enables lazy-loading of membership events. See Lazy-loading room members for more information. Defaults to false. * If true, enables lazy-loading of membership events. See Lazy-loading room members for more information. Defaults to false.
*/ */
@Json(name = "lazy_load_members") val lazyLoadMembers: Boolean? = null @Json(name = "lazy_load_members") val lazyLoadMembers: Boolean? = null,
/**
* 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,
) { ) {
fun toJSONString(): String { fun toJSONString(): String {
@ -92,6 +97,7 @@ internal data class RoomEventFilter(
rooms != null || rooms != null ||
notRooms != null || notRooms != null ||
containsUrl != null || containsUrl != null ||
lazyLoadMembers != null) lazyLoadMembers != null ||
enableUnreadThreadNotifications != null)
} }
} }

View File

@ -39,6 +39,7 @@ import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.send.SendState import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.api.session.sync.model.RoomSyncSummary import org.matrix.android.sdk.api.session.sync.model.RoomSyncSummary
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadNotifications import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadNotifications
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadThreadNotifications
import org.matrix.android.sdk.internal.crypto.EventDecryptor import org.matrix.android.sdk.internal.crypto.EventDecryptor
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService
import org.matrix.android.sdk.internal.database.mapper.ContentMapper import org.matrix.android.sdk.internal.database.mapper.ContentMapper
@ -91,6 +92,7 @@ internal class RoomSummaryUpdater @Inject constructor(
membership: Membership? = null, membership: Membership? = null,
roomSummary: RoomSyncSummary? = null, roomSummary: RoomSyncSummary? = null,
unreadNotifications: RoomSyncUnreadNotifications? = null, unreadNotifications: RoomSyncUnreadNotifications? = null,
unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null,
updateMembers: Boolean = false, updateMembers: Boolean = false,
inviterId: String? = null, inviterId: String? = null,
aggregator: SyncResponsePostTreatmentAggregator? = null aggregator: SyncResponsePostTreatmentAggregator? = null
@ -111,6 +113,8 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.highlightCount = unreadNotifications?.highlightCount ?: 0 roomSummaryEntity.highlightCount = unreadNotifications?.highlightCount ?: 0
roomSummaryEntity.notificationCount = unreadNotifications?.notificationCount ?: 0 roomSummaryEntity.notificationCount = unreadNotifications?.notificationCount ?: 0
// TODO: Handle unreadThreadNotifications
if (membership != null) { if (membership != null) {
roomSummaryEntity.membership = membership roomSummaryEntity.membership = membership
} }

View File

@ -287,6 +287,7 @@ internal class RoomSyncHandler @Inject constructor(
Membership.JOIN, Membership.JOIN,
roomSync.summary, roomSync.summary,
roomSync.unreadNotifications, roomSync.unreadNotifications,
roomSync.unreadThreadNotifications,
updateMembers = hasRoomMember, updateMembers = hasRoomMember,
aggregator = aggregator aggregator = aggregator
) )
@ -372,7 +373,8 @@ internal class RoomSyncHandler @Inject constructor(
roomEntity.chunks.clearWith { it.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) } roomEntity.chunks.clearWith { it.deleteOnCascade(deleteStateEvents = true, canDeleteRoot = true) }
roomTypingUsersHandler.handle(realm, roomId, null) roomTypingUsersHandler.handle(realm, roomId, null)
roomChangeMembershipStateDataSource.setMembershipFromSync(roomId, Membership.LEAVE) roomChangeMembershipStateDataSource.setMembershipFromSync(roomId, Membership.LEAVE)
roomSummaryUpdater.update(realm, roomId, membership, roomSync.summary, roomSync.unreadNotifications, aggregator = aggregator) roomSummaryUpdater.update(realm, roomId, membership, roomSync.summary,
roomSync.unreadNotifications, roomSync.unreadThreadNotifications, aggregator = aggregator)
return roomEntity return roomEntity
} }