mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
Use MSC 2654 server-reported unread counts
Change-Id: I6569f9c07c109bcb17dab48ad7f32480a22efb54
This commit is contained in:
parent
bcc59b3b09
commit
45746dfbbf
3 changed files with 16 additions and 6 deletions
|
@ -80,6 +80,7 @@ internal class RoomSummaryUpdater @Inject constructor(
|
|||
membership: Membership? = null,
|
||||
roomSummary: RoomSyncSummary? = null,
|
||||
unreadNotifications: RoomSyncUnreadNotifications? = null,
|
||||
unreadCount: Int? = null,
|
||||
updateMembers: Boolean = false,
|
||||
inviterId: String? = null) {
|
||||
val roomSummaryEntity = RoomSummaryEntity.getOrCreate(realm, roomId)
|
||||
|
@ -97,6 +98,7 @@ internal class RoomSummaryUpdater @Inject constructor(
|
|||
}
|
||||
roomSummaryEntity.highlightCount = unreadNotifications?.highlightCount ?: 0
|
||||
roomSummaryEntity.notificationCount = unreadNotifications?.notificationCount ?: 0
|
||||
roomSummaryEntity.unreadCount = unreadCount ?: 0
|
||||
|
||||
if (membership != null) {
|
||||
roomSummaryEntity.membership = membership
|
||||
|
@ -132,16 +134,18 @@ internal class RoomSummaryUpdater @Inject constructor(
|
|||
roomSummaryEntity.lastActivityTime = lastActivityFromEvent
|
||||
}
|
||||
|
||||
// If unreadCount == null, the server likely just doesn't support MSC 2654, so we need to check manually either way
|
||||
val hasUnreadEvents = unreadCount == null || unreadCount > 0
|
||||
roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0
|
||||
// avoid this call if we are sure there are unread events
|
||||
|| !isEventRead(realm.configuration, userId, roomId, latestPreviewableEvent?.eventId)
|
||||
// avoid this call if we are sure there are (no) unread events
|
||||
|| (hasUnreadEvents && !isEventRead(realm.configuration, userId, roomId, latestPreviewableEvent?.eventId))
|
||||
roomSummaryEntity.hasUnreadContentMessages = roomSummaryEntity.notificationCount > 0
|
||||
// avoid this call if we are sure there are unread events
|
||||
|| (latestPreviewableContentEvent != null
|
||||
// avoid this call if we are sure there are (no) unread events
|
||||
|| (hasUnreadEvents && latestPreviewableContentEvent != null
|
||||
&& !isEventRead(realm.configuration, userId, roomId, latestPreviewableContentEvent.eventId))
|
||||
roomSummaryEntity.hasUnreadOriginalContentMessages = roomSummaryEntity.notificationCount > 0
|
||||
// avoid this call if we are sure there are unread events
|
||||
|| (latestPreviewableOriginalContentEvent != null
|
||||
// avoid this call if we are sure there are (no) unread events
|
||||
|| (hasUnreadEvents && latestPreviewableOriginalContentEvent != null
|
||||
&& !isEventRead(realm.configuration, userId, roomId, latestPreviewableOriginalContentEvent.eventId))
|
||||
|
||||
roomSummaryEntity.displayName = roomDisplayNameResolver.resolve(realm, roomId)
|
||||
|
|
|
@ -252,6 +252,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
|||
Membership.JOIN,
|
||||
roomSync.summary,
|
||||
roomSync.unreadNotifications,
|
||||
roomSync.unreadCount,
|
||||
updateMembers = hasRoomMember
|
||||
)
|
||||
return roomEntity
|
||||
|
|
|
@ -46,6 +46,11 @@ internal data class RoomSync(
|
|||
*/
|
||||
@Json(name = "unread_notifications") val unreadNotifications: RoomSyncUnreadNotifications? = null,
|
||||
|
||||
/**
|
||||
* The unread count for the room.
|
||||
*/
|
||||
@Json(name = "org.matrix.msc2654.unread_count") val unreadCount: Int? = null,
|
||||
|
||||
/**
|
||||
* The room summary
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue