From 3381c2651138ad648254c6cf0758b2ebba4af9ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 5 Oct 2018 14:57:01 +0200 Subject: [PATCH] Expose the lastReadMessage in the API and use it for lookIntoTheFuture Signed-off-by: Joas Schilling --- docs/api-v1.md | 1 + js/app.js | 2 +- js/models/chatmessagecollection.js | 6 ++++-- js/signaling.js | 4 ++-- lib/Controller/RoomController.php | 2 ++ 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/api-v1.md b/docs/api-v1.md index 72876c5ecf6e..3556cd44ec22 100644 --- a/docs/api-v1.md +++ b/docs/api-v1.md @@ -145,6 +145,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1` `isFavorite` | bool | Flag if the room is favorited by the user `unreadMessages` | int | Number of unread chat messages in the room (only available with `chat-v2` capability) `unreadMention` | bool | Flag if the user was mentioned since their last visit + `lastReadMessage` | int | ID of the last read message in a room `lastMessage` | message | Last message in a room if available, otherwise empty `objectType` | string | The type of object that the room is associated with; "share:password" if the room is used to request a password for a share, otherwise empty `objectId` | string | Share token if "objectType" is "share:password", otherwise empty diff --git a/js/app.js b/js/app.js index e9dd7f242123..aebe5f087ac1 100644 --- a/js/app.js +++ b/js/app.js @@ -523,7 +523,7 @@ }); this._sidebarView.setCallInfoView(callInfoView); - this._messageCollection.setRoomToken(this.activeRoom.get('token')); + this._messageCollection.setRoomToken(this.activeRoom.get('token'), this.activeRoom.get('lastReadMessage')); this._messageCollection.receiveMessages(); }, setPageTitle: function(title){ diff --git a/js/models/chatmessagecollection.js b/js/models/chatmessagecollection.js index 0410139a1a9a..c0f06c4ecdb9 100644 --- a/js/models/chatmessagecollection.js +++ b/js/models/chatmessagecollection.js @@ -77,11 +77,13 @@ * explicitly called if needed. * * @param {?string} token the token of the room. + * @param {?int} lastReadMessage the last read message in that room */ - setRoomToken: function(token) { + setRoomToken: function(token, lastReadMessage) { this.stopReceivingMessages(); this.token = token; + this.lastReadMessage = lastReadMessage || 0; if (token !== null) { this.signaling = OCA.SpreedMe.app.signaling; @@ -103,7 +105,7 @@ receiveMessages: function() { if (this.signaling) { this.signaling.on("chatMessagesReceived", this._handler); - this.signaling.startReceiveMessages(); + this.signaling.startReceiveMessages(this.lastReadMessage); } }, diff --git a/js/signaling.js b/js/signaling.js index 4d50f3be16ca..cac0c7bf5b0a 100644 --- a/js/signaling.js +++ b/js/signaling.js @@ -348,10 +348,10 @@ return defer; }; - OCA.Talk.Signaling.Base.prototype.startReceiveMessages = function() { + OCA.Talk.Signaling.Base.prototype.startReceiveMessages = function(lastKnownMessageId) { this._waitTimeUntilRetry = 1; this.receiveMessagesAgain = true; - this.lastKnownMessageId = 0; + this.lastKnownMessageId = lastKnownMessageId; this._receiveChatMessages(); }; diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index bc3b95019756..f029c72a580b 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -205,6 +205,7 @@ protected function formatRoom(Room $room, Participant $participant = null): arra 'hasPassword' => $room->hasPassword(), 'hasCall' => $room->getActiveSince() instanceof \DateTimeInterface, 'lastActivity' => $lastActivity, + 'lastReadMessage' => 0, 'unreadMessages' => 0, 'unreadMention' => false, 'isFavorite' => $favorite, @@ -246,6 +247,7 @@ protected function formatRoom(Room $room, Participant $participant = null): arra $lastMention = $participant->getLastMentionMessage(); $roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention; + $roomData['lastReadMessage'] = $lastReadMessage; } // Sort by lastPing