@@ -63,14 +63,14 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
6363 *
6464 * Events are unique by their properties, we should be careful not to insert multiple events with the same event-id
6565 */
66- private val eventList = loadEventInfo()
66+ private val queuedEvents = loadEventInfo()
6767
6868 /* *
6969 * The last known rendered notifiable events
7070 * we keep track of them in order to know which events have been removed from the eventList
7171 * allowing us to cancel any notifications previous displayed by now removed events
7272 */
73- private var renderedEventsList = emptyList<ProcessedEvent <NotifiableEvent >>()
73+ private var renderedEvents = emptyList<ProcessedEvent <NotifiableEvent >>()
7474 private val avatarSize = context.resources.getDimensionPixelSize(R .dimen.profile_avatar_size)
7575 private var currentRoomId: String? = null
7676
@@ -105,8 +105,8 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
105105 } else {
106106 Timber .d(" onNotifiableEventReceived(): is push: ${notifiableEvent.canBeReplaced} " )
107107 }
108- synchronized(eventList ) {
109- val existing = eventList .firstOrNull { it.eventId == notifiableEvent.eventId }
108+ synchronized(queuedEvents ) {
109+ val existing = queuedEvents .firstOrNull { it.eventId == notifiableEvent.eventId }
110110 if (existing != null ) {
111111 if (existing.canBeReplaced) {
112112 // Use the event coming from the event stream as it may contains more info than
@@ -117,16 +117,16 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
117117 // Use setOnlyAlertOnce to ensure update notification does not interfere with sound
118118 // from first notify invocation as outlined in:
119119 // https://developer.android.com/training/notify-user/build-notification#Updating
120- eventList .remove(existing)
121- eventList .add(notifiableEvent)
120+ queuedEvents .remove(existing)
121+ queuedEvents .add(notifiableEvent)
122122 } else {
123123 // keep the existing one, do not replace
124124 }
125125 } else {
126126 // Check if this is an edit
127127 if (notifiableEvent.editedEventId != null ) {
128128 // This is an edition
129- val eventBeforeEdition = eventList .firstOrNull {
129+ val eventBeforeEdition = queuedEvents .firstOrNull {
130130 // Edition of an event
131131 it.eventId == notifiableEvent.editedEventId ||
132132 // or edition of an edition
@@ -135,9 +135,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
135135
136136 if (eventBeforeEdition != null ) {
137137 // Replace the existing notification with the new content
138- eventList .remove(eventBeforeEdition)
138+ queuedEvents .remove(eventBeforeEdition)
139139
140- eventList .add(notifiableEvent)
140+ queuedEvents .add(notifiableEvent)
141141 } else {
142142 // Ignore an edit of a not displayed event in the notification drawer
143143 }
@@ -148,16 +148,16 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
148148 Timber .d(" onNotifiableEventReceived(): skipping event, already seen" )
149149 } else {
150150 seenEventIds.put(notifiableEvent.eventId)
151- eventList .add(notifiableEvent)
151+ queuedEvents .add(notifiableEvent)
152152 }
153153 }
154154 }
155155 }
156156 }
157157
158158 fun onEventRedacted (eventId : String ) {
159- synchronized(eventList ) {
160- eventList .replace(eventId) {
159+ synchronized(queuedEvents ) {
160+ queuedEvents .replace(eventId) {
161161 when (it) {
162162 is InviteNotifiableEvent -> it.copy(isRedacted = true )
163163 is NotifiableMessageEvent -> it.copy(isRedacted = true )
@@ -171,8 +171,8 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
171171 * Clear all known events and refresh the notification drawer
172172 */
173173 fun clearAllEvents () {
174- synchronized(eventList ) {
175- eventList .clear()
174+ synchronized(queuedEvents ) {
175+ queuedEvents .clear()
176176 }
177177 refreshNotificationDrawer()
178178 }
@@ -194,7 +194,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
194194 */
195195 fun setCurrentRoom (roomId : String? ) {
196196 var hasChanged: Boolean
197- synchronized(eventList ) {
197+ synchronized(queuedEvents ) {
198198 hasChanged = roomId != currentRoomId
199199 currentRoomId = roomId
200200 }
@@ -211,8 +211,8 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
211211 }
212212
213213 private fun removeAll (predicate : (NotifiableEvent ) -> Boolean ): Boolean {
214- return synchronized(eventList ) {
215- eventList .removeAll(predicate)
214+ return synchronized(queuedEvents ) {
215+ queuedEvents .removeAll(predicate)
216216 }
217217 }
218218
@@ -247,17 +247,17 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
247247 useCompleteNotificationFormat = newSettings
248248 }
249249
250- val eventsToRender = synchronized(eventList ) {
251- notifiableEventProcessor.process(eventList , currentRoomId, renderedEventsList ).also {
252- eventList .clear()
253- eventList .addAll(it.onlyKeptEvents())
250+ val eventsToRender = synchronized(queuedEvents ) {
251+ notifiableEventProcessor.process(queuedEvents , currentRoomId, renderedEvents ).also {
252+ queuedEvents .clear()
253+ queuedEvents .addAll(it.onlyKeptEvents())
254254 }
255255 }
256256
257- if (renderedEventsList == eventsToRender) {
257+ if (renderedEvents == eventsToRender) {
258258 Timber .d(" Skipping notification update due to event list not changing" )
259259 } else {
260- renderedEventsList = eventsToRender
260+ renderedEvents = eventsToRender
261261 val session = currentSession ? : return
262262 val user = session.getUser(session.myUserId)
263263 // myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
@@ -277,16 +277,16 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
277277 }
278278
279279 fun persistInfo () {
280- synchronized(eventList ) {
281- if (eventList .isEmpty()) {
280+ synchronized(queuedEvents ) {
281+ if (queuedEvents .isEmpty()) {
282282 deleteCachedRoomNotifications()
283283 return
284284 }
285285 try {
286286 val file = File (context.applicationContext.cacheDir, ROOMS_NOTIFICATIONS_FILE_NAME )
287287 if (! file.exists()) file.createNewFile()
288288 FileOutputStream (file).use {
289- currentSession?.securelyStoreObject(eventList , KEY_ALIAS_SECRET_STORAGE , it)
289+ currentSession?.securelyStoreObject(queuedEvents , KEY_ALIAS_SECRET_STORAGE , it)
290290 }
291291 } catch (e: Throwable ) {
292292 Timber .e(e, " ## Failed to save cached notification info" )
0 commit comments