Skip to content

Commit e6ffbda

Browse files
authored
Merge pull request #1411 from matrix-org/ismail/5843_thread_list_dots
Fix thread list dots
2 parents 3abf46f + fec44e0 commit e6ffbda

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

MatrixSDK/Threads/MXThreadingService.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ public class MXThreadingService: NSObject {
264264
}
265265

266266
private func thread(forRootEvent rootEvent: MXEvent, session: MXSession) -> MXThreadModel {
267-
let notificationCount: UInt
268-
let highlightCount: UInt
267+
var notificationCount: UInt = 0
268+
var highlightCount: UInt = 0
269269
if let store = session.store {
270270
notificationCount = store.localUnreadEventCount(rootEvent.roomId,
271271
threadId: rootEvent.eventId,
@@ -274,9 +274,10 @@ public class MXThreadingService: NSObject {
274274
threadId: rootEvent.eventId,
275275
withTypeIn: session.unreadEventTypes)
276276
highlightCount = UInt(newEvents.filter { $0.shouldBeHighlighted(inSession: session) }.count)
277-
} else {
278-
notificationCount = 0
279-
highlightCount = 0
277+
}
278+
if let localThread = thread(withId: rootEvent.eventId) {
279+
notificationCount = max(notificationCount, localThread.notificationCount)
280+
highlightCount = max(highlightCount, localThread.highlightCount)
280281
}
281282
let thread = MXThreadModel(withRootEvent: rootEvent,
282283
notificationCount: notificationCount,
@@ -303,14 +304,17 @@ public class MXThreadingService: NSObject {
303304
completion?(handled)
304305
} else {
305306
// create the thread for the first time
306-
var thread: MXThread = MXThread(withSession: session, identifier: threadId, roomId: event.roomId)
307+
let thread = MXThread(withSession: session, identifier: threadId, roomId: event.roomId)
308+
self.saveThread(thread)
309+
self.notifyDidCreateThread(thread, direction: direction)
310+
self.notifyDidUpdateThreads()
307311
let dispatchGroup = DispatchGroup()
308312
// try to find the root event in the session store
309313
dispatchGroup.enter()
310314
session.event(withEventId: threadId, inRoom: event.roomId) { response in
311315
switch response {
312316
case .success(let rootEvent):
313-
thread = MXThread(withSession: session, rootEvent: rootEvent)
317+
thread.addEvent(rootEvent, direction: direction)
314318
case .failure(let error):
315319
MXLog.error("[MXThreadingService] handleInThreadEvent: root event not found: \(error)")
316320
}
@@ -319,8 +323,6 @@ public class MXThreadingService: NSObject {
319323

320324
dispatchGroup.notify(queue: .main) {
321325
let handled = thread.addEvent(event, direction: direction)
322-
self.saveThread(thread)
323-
self.notifyDidCreateThread(thread, direction: direction)
324326
self.notifyDidUpdateThreads()
325327
completion?(handled)
326328
}

changelog.d/5843.change

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MXThreadingService: Fix number of replies & notification/highlight counts for threads.

0 commit comments

Comments
 (0)