[FIX] Read Receipt for Livechat Messages fixed#13832
[FIX] Read Receipt for Livechat Messages fixed#13832renatobecker-zz merged 9 commits intoRocketChat:developfrom
Conversation
| if (this.user) { | ||
| return (settings.get('UI_Use_Real_Name') && this.user.name) || this.user.username; | ||
| } | ||
| return this.guest.name; |
There was a problem hiding this comment.
If the Livechat registration form is not enabled, then the name of the guest will not be defined.
Anyway, we don't need to create another property to display the user data, let's use the user property for both regular users and Livechat users.
| {{#each receipts}} | ||
| <li class="read-receipts__user background-transparent-dark-hover"> | ||
| {{> avatar username=user.username}} | ||
| {{#if user}} |
There was a problem hiding this comment.
@renatobecker Do you want an avatar with guest name or username, cause if it is the guest name, it will change accordingly, otherwise it will always be G
There was a problem hiding this comment.
We don't have Avatars for Livechat users.
It's ok showing the default avatar as you just described.
| @@ -81,6 +81,7 @@ export const ReadReceipt = { | |||
| return ReadReceipts.findByMessageId(message._id).map((receipt) => ({ | |||
| ...receipt, | |||
| user: Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), | |||
There was a problem hiding this comment.
We can check the receipt object to ensure that it came from a Livechat user or not. If the receipt.token exists, then you need to get the guest by finding it with the LivechatVisitors model, as you can see below:
| user: Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), | |
| user: message.token? LivechatVisitors.findById(receipt.userId, { fields: { username: 1, name: 1 } }) : Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }) , |
There was a problem hiding this comment.
Ok, let me update that.
fc9963d to
607929f
Compare
|
|
||
| // mark message as read as well | ||
| ReadReceipt.markMessageAsReadBySender(message, room._id, message.u._id); | ||
| ReadReceipt.markMessageAsReadBySender(message, room._id, message.u._id, message.token); |
There was a problem hiding this comment.
This is not a good approach.
The token needs to come from a specific Livechat Room Type method since this package is not the Livechat package.
In addition, the markMessageAsReadBySender needs to expect an object, not a regular variable.
| }, | ||
|
|
||
| markMessageAsReadBySender(message, roomId, userId) { | ||
| markMessageAsReadBySender(message, roomId, userId, extraData) { |
There was a problem hiding this comment.
| markMessageAsReadBySender(message, roomId, userId, extraData) { | |
| markMessageAsReadBySender(message, roomId, userId, extraData = {}) { |
| userId, | ||
| messageId: message._id, | ||
| ts, | ||
| token: extraData, |
There was a problem hiding this comment.
| token: extraData, | |
| ...extraData, |
| return ReadReceipts.findByMessageId(message._id).map((receipt) => ({ | ||
| ...receipt, | ||
| user: Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), | ||
| user: (receipt.token && !(Object.keys(receipt.token).length === 0 && receipt.token.constructor === Object)) ? LivechatVisitors.getVisitorByToken(message.token, { fields: { username: 1, name: 1 } }) : Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), |
There was a problem hiding this comment.
| user: (receipt.token && !(Object.keys(receipt.token).length === 0 && receipt.token.constructor === Object)) ? LivechatVisitors.getVisitorByToken(message.token, { fields: { username: 1, name: 1 } }) : Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), | |
| user: receipt.token ? LivechatVisitors.getVisitorByToken(receipt.token, { fields: { username: 1, name: 1 } }) : Users.findOneById(receipt.userId, { fields: { username: 1, name: 1 } }), |
54ee6eb to
91e3ed8
Compare
app/utils/lib/RoomTypeConfig.js
Outdated
| } | ||
|
|
||
| /** | ||
| * Get receipt's extra token for livechat users |
There was a problem hiding this comment.
These comments are related to Livechat stuff, not the default Room Type Config
app/utils/lib/RoomTypeConfig.js
Outdated
| * @return {object} Token for user | ||
| */ | ||
| getReadReceiptsExtraData(message) { | ||
| if (!Meteor.isServer) { |
There was a problem hiding this comment.
Here the return will be always return {};
There was a problem hiding this comment.
@knrt10, are you sure? The code has not changed to me.
3412bc5 to
c1c61f3
Compare
| if (message.unread && message.ts < firstSubscription.ls) { | ||
| Messages.setAsReadById(message._id, firstSubscription.ls); | ||
| } | ||
| const extraData = roomTypes.getConfig('l').getReadReceiptsExtraData(message); |
There was a problem hiding this comment.
He discussed about it last week:
| const extraData = roomTypes.getConfig('l').getReadReceiptsExtraData(message); | |
| const extraData = roomTypes.getConfig(room.t).getReadReceiptsExtraData(message); |
You need to find the room and get the room type field:
const room = Rooms.findOneById(roomId, { fields: { t: 1 } });
|
Rebased and updated, latest changes |
Closes #13302
cc @renatobecker please review.