Add updateLastMessage to NCRoomsManager

Use updatePendingMessage instead of updateRoomLocal

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2021-03-06 17:30:48 +01:00
Родитель 28a269e7b5
Коммит 63e0eebcf6
3 изменённых файлов: 40 добавлений и 7 удалений

Просмотреть файл

@ -355,8 +355,11 @@ NSString * const NCChatControllerDidReceiveDeletedMessageNotification
userInfo:userInfo];
if (lastCommonReadMessage > 0) {
BOOL newerCommonReadReceived = lastCommonReadMessage > self->_room.lastCommonReadMessage;
self->_room.lastCommonReadMessage = lastCommonReadMessage;
if (newerCommonReadReceived) {
self->_room.lastCommonReadMessage = lastCommonReadMessage;
[[NCRoomsManager sharedInstance] updateLastCommonReadMessage:lastCommonReadMessage forRoom:self->_room];
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatControllerDidReceiveNewerCommonReadMessageNotification
object:self
userInfo:userInfo];
@ -502,14 +505,11 @@ NSString * const NCChatControllerDidReceiveDeletedMessageNotification
for (NCChatMessage *message in storedMessages) {
// Update the current room with the new message
// The stored information about this room will be updated by calling savePendingMessage
// in NCChatViewController -> a transaction wouldn't make sense here, as it would be overriden again
if (message.messageId == lastKnownMessage && message.timestamp > self->_room.lastActivity) {
self->_room.lastMessageId = message.internalId;
self->_room.lastActivity = message.timestamp;
self->_room.unreadMention = NO;
self->_room.unreadMessages = 0;
[[NCRoomsManager sharedInstance] updateLastMessage:message withNoUnreadMessages:YES forRoom:self->_room];
}
// Notify if "deleted messages" have been received
if ([message.systemMessage isEqualToString:@"message_deleted"]) {
[userInfo setObject:message forKey:@"deleteMessage"];
@ -525,8 +525,11 @@ NSString * const NCChatControllerDidReceiveDeletedMessageNotification
userInfo:userInfo];
if (lastCommonReadMessage > 0) {
BOOL newerCommonReadReceived = lastCommonReadMessage > self->_room.lastCommonReadMessage;
self->_room.lastCommonReadMessage = lastCommonReadMessage;
if (newerCommonReadReceived) {
self->_room.lastCommonReadMessage = lastCommonReadMessage;
[[NCRoomsManager sharedInstance] updateLastCommonReadMessage:lastCommonReadMessage forRoom:self->_room];
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatControllerDidReceiveNewerCommonReadMessageNotification
object:self
userInfo:userInfo];

Просмотреть файл

@ -59,6 +59,8 @@ typedef void (^UpdateRoomsAndChatsCompletionBlock)(NSError *error);
- (void)updateRoomsUpdatingUserStatus:(BOOL)updateStatus;
- (void)updateRoom:(NSString *)token;
- (void)updatePendingMessage:(NSString *)message forRoom:(NCRoom *)room;
- (void)updateLastMessage:(NCChatMessage *)message withNoUnreadMessages:(BOOL)noUnreadMessages forRoom:(NCRoom *)room;
- (void)updateLastCommonReadMessage:(NSInteger)messageId forRoom:(NCRoom *)room;
- (void)joinRoom:(NSString *)token;
- (void)rejoinRoom:(NSString *)token;
// Chat

Просмотреть файл

@ -437,6 +437,34 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
}];
}
- (void)updateLastMessage:(NCChatMessage *)message withNoUnreadMessages:(BOOL)noUnreadMessages forRoom:(NCRoom *)room
{
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
NCRoom *managedRoom = [NCRoom objectsWhere:@"internalId = %@", room.internalId].firstObject;
if (managedRoom) {
managedRoom.lastMessageId = message.internalId;
managedRoom.lastActivity = message.timestamp;
if (noUnreadMessages) {
managedRoom.unreadMention = NO;
managedRoom.unreadMessages = 0;
}
}
}];
}
- (void)updateLastCommonReadMessage:(NSInteger)messageId forRoom:(NCRoom *)room
{
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
NCRoom *managedRoom = [NCRoom objectsWhere:@"internalId = %@", room.internalId].firstObject;
if (managedRoom && messageId > managedRoom.lastCommonReadMessage) {
managedRoom.lastCommonReadMessage = messageId;
}
}];
}
#pragma mark - Chat
- (void)startChatInRoom:(NCRoom *)room