Skip to content

Commit

Permalink
Finally working, fixed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
knrt10 committed Mar 22, 2019
1 parent 3525f56 commit 91e3ed8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/livechat/server/roomType.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class LivechatRoomTypeServer extends LivechatRoomType {
canAccessUploadedFile({ rc_token, rc_rid } = {}) {
return rc_token && rc_rid && Rooms.findOneOpenByRoomIdAndVisitorToken(rc_rid, rc_token);
}

getReadReceiptsExtraData(message) {
const { token } = message;
return { token };
}
}

roomTypes.add(new LivechatRoomTypeServer());
13 changes: 13 additions & 0 deletions app/utils/lib/RoomTypeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,17 @@ export class RoomTypeConfig {
return false;
}

/**
* Get receipt's extra token for livechat users
* @param {object} message
* @return {object} Token for user
*/
getReadReceiptsExtraData(message) {
if (!Meteor.isServer) {
return {};
}
const { token } = message;
return { token };
}

}
2 changes: 1 addition & 1 deletion imports/message-read-receipt/server/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, message.token);
ReadReceipt.markMessageAsReadBySender(message, room._id, message.u._id);
});

callbacks.add('afterReadMessages', (rid, { userId, lastSeen }) => {
Expand Down
8 changes: 5 additions & 3 deletions imports/message-read-receipt/server/lib/ReadReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { ReadReceipts, Subscriptions, Messages, Rooms, Users, LivechatVisitors } from '../../../../app/models';
import { settings } from '../../../../app/settings';
import { roomTypes } from '../../../../app/utils';

const rawReadReceipts = ReadReceipts.model.rawCollection();

Expand Down Expand Up @@ -40,7 +41,7 @@ export const ReadReceipt = {
updateMessages(roomId);
},

markMessageAsReadBySender(message, roomId, userId, extraData) {
markMessageAsReadBySender(message, roomId, userId) {
if (!settings.get('Message_Read_Receipt_Enabled')) {
return;
}
Expand All @@ -50,6 +51,7 @@ export const ReadReceipt = {
if (message.unread && message.ts < firstSubscription.ls) {
Messages.setAsReadById(message._id, firstSubscription.ls);
}
const extraData = roomTypes.getConfig('l').getReadReceiptsExtraData(message);

this.storeReadReceipts([{ _id: message._id }], roomId, userId, extraData);
},
Expand All @@ -63,7 +65,7 @@ export const ReadReceipt = {
userId,
messageId: message._id,
ts,
token: extraData,
...extraData,
}));

if (receipts.length === 0) {
Expand All @@ -81,7 +83,7 @@ export const ReadReceipt = {
getReceipts(message) {
return ReadReceipts.findByMessageId(message._id).map((receipt) => ({
...receipt,
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 } }),
}));
},
};

0 comments on commit 91e3ed8

Please sign in to comment.