Skip to content

Commit ba3fbdf

Browse files
authored
Merge pull request #2008 from nextcloud/fix/noid/background-fetching
fix: Correctly process system messages in background fetch
2 parents 5cd6fd3 + ae4ce34 commit ba3fbdf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

NextcloudTalk/NCChatController.m

+18-3
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,27 @@ - (void)updateHistoryInBackgroundWithCompletionBlock:(UpdateHistoryInBackgroundC
402402

403403
// Store new messages
404404
if (messages.count > 0) {
405-
[self storeMessages:messages];
406-
[self checkLastCommonReadMessage:lastCommonReadMessage];
407-
408405
// In case we finish after the app already got active again, notify any potential view controller
409406
NSMutableDictionary *userInfo = [NSMutableDictionary new];
410407
[userInfo setObject:self->_room.token forKey:@"room"];
408+
409+
for (NSDictionary *messageDict in messages) {
410+
NCChatMessage *message = [NCChatMessage messageWithDictionary:messageDict andAccountId:self->_account.accountId];
411+
412+
if (message && [message.systemMessage isEqualToString:@"history_cleared"]) {
413+
[self clearHistoryAndResetChatController];
414+
415+
[userInfo setObject:message forKey:@"historyCleared"];
416+
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatControllerDidReceiveHistoryClearedNotification
417+
object:self
418+
userInfo:userInfo];
419+
return;
420+
}
421+
}
422+
423+
[self storeMessages:messages];
424+
[self checkLastCommonReadMessage:lastCommonReadMessage];
425+
411426
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatControllerDidReceiveMessagesInBackgroundNotification
412427
object:self
413428
userInfo:userInfo];

0 commit comments

Comments
 (0)