Merge pull request #2331 from Bilb/fix-send-readable-messages-focused

fix: send read receipt when settings ON and window focused
pull/2332/head
Audric Ackermann 3 years ago committed by GitHub
commit f457595fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -144,9 +144,18 @@ export const ReadableMessage = (props: ReadableMessageProps) => {
const found = await getMessageById(messageId);
if (found && Boolean(found.get('unread'))) {
const foundReceivedAt = found.get('received_at');
// mark the message as read.
// this will trigger the expire timer.
await found.markRead(Date.now());
// we should stack those and send them in a single message once every 5secs or something.
// this would be part of an redesign of the sending pipeline
if (foundReceivedAt) {
void getConversationController()
.get(found.id)
?.sendReadReceiptsIfNeeded([foundReceivedAt]);
}
}
}
}

@ -1146,7 +1146,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// conversation is viewed, another error message shows up for the contact
read = read.filter(item => !item.hasErrors);
if (!this.isPrivate() || !read.length || !options.sendReadReceipts) {
if (read.length && options.sendReadReceipts) {
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
await this.sendReadReceiptsIfNeeded(timestamps);
}
}
public async sendReadReceiptsIfNeeded(timestamps: Array<number>) {
if (!this.isPrivate() || !timestamps.length) {
return;
}
const settingsReadReceiptEnabled = Storage.get(SettingsKey.settingsReadReceipt) || false;
@ -1154,9 +1161,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
settingsReadReceiptEnabled && !this.isBlocked() && !this.isIncomingRequest();
if (sendReceipt) {
window?.log?.info(`Sending ${read.length} read receipts.`);
window?.log?.info(`Sending ${timestamps.length} read receipts.`);
// we should probably stack read receipts and send them every 5 seconds for instance per conversation
const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array<number>;
const receiptMessage = new ReadReceiptMessage({
timestamp: Date.now(),
timestamps,

Loading…
Cancel
Save