-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] Read Receipt for Livechat Messages fixed #13832
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -6,7 +6,11 @@ | |||
<ul class="read-receipts"> | |||
{{#each receipts}} | |||
<li class="read-receipts__user background-transparent-dark-hover"> | |||
{{> avatar username=user.username}} | |||
{{#if user}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, undo this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me update that.
fc9963d
to
607929f
Compare
@@ -13,7 +13,7 @@ callbacks.add('afterSaveMessage', (message, room) => { | |||
Subscriptions.setAsReadByRoomIdAndUserId(room._id, message.u._id); | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -40,7 +40,7 @@ export const ReadReceipt = { | |||
updateMessages(roomId); | |||
}, | |||
|
|||
markMessageAsReadBySender(message, roomId, userId) { | |||
markMessageAsReadBySender(message, roomId, userId, extraData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
markMessageAsReadBySender(message, roomId, userId, extraData) { | |
markMessageAsReadBySender(message, roomId, userId, extraData = {}) { |
@@ -63,6 +63,7 @@ export const ReadReceipt = { | |||
userId, | |||
messageId: message._id, | |||
ts, | |||
token: extraData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
token: extraData, | |
...extraData, |
@@ -80,7 +81,7 @@ export const ReadReceipt = { | |||
getReceipts(message) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -264,4 +264,17 @@ export class RoomTypeConfig { | |||
return false; | |||
} | |||
|
|||
/** | |||
* Get receipt's extra token for livechat users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the return will be always return {}
;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@knrt10, are you sure? The code has not changed to me.
3412bc5
to
c1c61f3
Compare
@@ -50,11 +51,12 @@ export const ReadReceipt = { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.