fix: read receipts handling for private chats

pull/2319/head
Audric Ackermann 3 years ago
parent ea24da0f28
commit d5e3f73035

@ -231,7 +231,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (newestUnreadDate > lastReadTimestamp) { if (newestUnreadDate > lastReadTimestamp) {
this.lastReadTimestamp = newestUnreadDate; this.lastReadTimestamp = newestUnreadDate;
} }
void markReadDebounced(newestUnreadDate);
if (newestUnreadDate !== lastReadTimestamp) {
void markReadDebounced(newestUnreadDate);
}
}; };
// Listening for out-of-band data updates // Listening for out-of-band data updates
@ -1059,6 +1062,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
// tslint:disable-next-line: cyclomatic-complexity
public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) {
const lastReadTimestamp = this.lastReadTimestamp; const lastReadTimestamp = this.lastReadTimestamp;
if (newestUnreadDate < lastReadTimestamp) { if (newestUnreadDate < lastReadTimestamp) {
@ -1107,7 +1111,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const realUnreadCount = await this.getUnreadCount(); const realUnreadCount = await this.getUnreadCount();
if (read.length === 0) { if (read.length === 0) {
const cachedUnreadCountOnConvo = this.get('unreadCount'); const cachedUnreadCountOnConvo = this.get('unreadCount');
if (cachedUnreadCountOnConvo !== read.length) { if (cachedUnreadCountOnConvo !== realUnreadCount) {
// reset the unreadCount on the convo to the real one coming from markRead messages on the db // reset the unreadCount on the convo to the real one coming from markRead messages on the db
this.set({ unreadCount: realUnreadCount }); this.set({ unreadCount: realUnreadCount });
await this.commit(); await this.commit();
@ -1142,25 +1146,24 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// conversation is viewed, another error message shows up for the contact // conversation is viewed, another error message shows up for the contact
read = read.filter(item => !item.hasErrors); read = read.filter(item => !item.hasErrors);
if (this.isPublic()) { if (!this.isPrivate() || !read.length || !options.sendReadReceipts) {
return; return;
} }
if (this.isPrivate() && read.length && options.sendReadReceipts) { const settingsReadReceiptEnabled = Storage.get(SettingsKey.settingsReadReceipt) || false;
window?.log?.info( const sendReceipt =
`Sending ${read.length} read receipts?`, settingsReadReceiptEnabled && !this.isBlocked() && !this.isIncomingRequest();
Storage.get(SettingsKey.settingsReadReceipt) || false
);
const dontSendReceipt = this.isBlocked() || this.isIncomingRequest();
if (Storage.get(SettingsKey.settingsReadReceipt) && !dontSendReceipt) {
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
const receiptMessage = new ReadReceiptMessage({
timestamp: Date.now(),
timestamps,
});
const device = new PubKey(this.id); if (sendReceipt) {
await getMessageQueue().sendToPubKey(device, receiptMessage); window?.log?.info(`Sending ${read.length} read receipts.`);
}
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
const receiptMessage = new ReadReceiptMessage({
timestamp: Date.now(),
timestamps,
});
const device = new PubKey(this.id);
await getMessageQueue().sendToPubKey(device, receiptMessage);
} }
} }

@ -447,11 +447,9 @@ export async function innerHandleSwarmContentMessage(
} }
function onReadReceipt(readAt: number, timestamp: number, source: string) { function onReadReceipt(readAt: number, timestamp: number, source: string) {
const { storage } = window;
window?.log?.info('read receipt', source, timestamp); window?.log?.info('read receipt', source, timestamp);
if (!storage.get(SettingsKey.settingsReadReceipt)) { if (!Storage.get(SettingsKey.settingsReadReceipt)) {
return; return;
} }

@ -201,7 +201,7 @@ export async function handleSwarmDataMessage(
); );
window?.log?.info( window?.log?.info(
`Handle dataMessage about convo ${convoIdToAddTheMessageTo} from user: ${convoIdOfSender}: ${cleanDataMessage}` `Handle dataMessage about convo ${convoIdToAddTheMessageTo} from user: ${convoIdOfSender}`
); );
// remove the prefix from the source object so this is correct for all other // remove the prefix from the source object so this is correct for all other

Loading…
Cancel
Save