Skip to content

Commit

Permalink
Expose the lastReadMessage in the API and use it for lookIntoTheFuture
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 5, 2018
1 parent 67483d7 commit 3381c26
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
6 changes: 4 additions & 2 deletions js/models/chatmessagecollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -103,7 +105,7 @@
receiveMessages: function() {
if (this.signaling) {
this.signaling.on("chatMessagesReceived", this._handler);
this.signaling.startReceiveMessages();
this.signaling.startReceiveMessages(this.lastReadMessage);
}
},

Expand Down
4 changes: 2 additions & 2 deletions js/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3381c26

Please sign in to comment.