Skip to content

Commit

Permalink
Update timers whenever we mark messages read
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 19, 2021
1 parent 1badc02 commit 385bcc4
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 149 deletions.
4 changes: 2 additions & 2 deletions js/modules/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only

/* eslint-env node */
/* global log, Signal, Whisper */
/* global log, Signal */

const fs = require('fs-extra');
const path = require('path');
Expand Down Expand Up @@ -60,7 +60,7 @@ exports.createConversation = async ({
await sleep(index * 100);
log.info(`Create message ${index + 1}`);
const message = await createRandomMessage({ conversationId });
return Signal.Data.saveMessage(message, { Message: Whisper.Message });
return Signal.Data.saveMessage(message);
})
);
};
Expand Down
13 changes: 1 addition & 12 deletions js/modules/messages_data_migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ const { isFunction, isNumber } = require('lodash');
const Message = require('./types/message');

exports.processNext = async ({
BackboneMessage,
BackboneMessageCollection,
numMessagesPerBatch,
upgradeMessageSchema,
getMessagesNeedingUpgrade,
saveMessage,
maxVersion = Message.CURRENT_SCHEMA_VERSION,
} = {}) => {
if (!isFunction(BackboneMessage)) {
throw new TypeError(
"'BackboneMessage' (Whisper.Message) constructor is required"
);
}

if (!isFunction(BackboneMessageCollection)) {
throw new TypeError(
"'BackboneMessageCollection' (Whisper.MessageCollection)" +
Expand Down Expand Up @@ -72,11 +65,7 @@ exports.processNext = async ({
const upgradeDuration = Date.now() - upgradeStartTime;

const saveStartTime = Date.now();
await Promise.all(
upgradedMessages.map(message =>
saveMessage(message, { Message: BackboneMessage })
)
);
await Promise.all(upgradedMessages.map(message => saveMessage(message)));
const saveDuration = Date.now() - saveStartTime;

const totalDuration = Date.now() - startTime;
Expand Down
11 changes: 3 additions & 8 deletions ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { routineProfileRefresh } from './routineProfileRefresh';
import { isMoreRecentThan, isOlderThan } from './util/timestamp';
import { isValidReactionEmoji } from './reactions/isValidReactionEmoji';
import { ConversationModel } from './models/conversations';
import { getMessageById, MessageModel } from './models/messages';
import { getMessageById } from './models/messages';
import { createBatcher } from './util/batcher';
import { updateConversationsWithUuidLookup } from './updateConversationsWithUuidLookup';
import { initializeAllJobQueues } from './jobs/initializeAllJobQueues';
Expand Down Expand Up @@ -858,7 +858,6 @@ export async function startApp(): Promise<void> {

if (!isMigrationWithIndexComplete) {
const batchWithIndex = await MessageDataMigrator.processNext({
BackboneMessage: window.Whisper.Message,
BackboneMessageCollection: window.Whisper.MessageCollection,
numMessagesPerBatch: NUM_MESSAGES_PER_BATCH,
upgradeMessageSchema,
Expand Down Expand Up @@ -1736,9 +1735,7 @@ export async function startApp(): Promise<void> {
}
);

await window.Signal.Data.saveMessages(newMessageAttributes, {
Message: MessageModel,
});
await window.Signal.Data.saveMessages(newMessageAttributes);
}
window.log.info('Expiration start timestamp cleanup: complete');

Expand Down Expand Up @@ -2514,9 +2511,7 @@ export async function startApp(): Promise<void> {
messagesToSave.push(message.attributes);
}
});
await window.Signal.Data.saveMessages(messagesToSave, {
Message: MessageModel,
});
await window.Signal.Data.saveMessages(messagesToSave);
}
function onReconnect() {
// We disable notifications on first connect, but the same applies to reconnect. In
Expand Down
2 changes: 0 additions & 2 deletions ts/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,6 @@ export async function createGroupV2({
};
await window.Signal.Data.saveMessages([createdTheGroupMessage], {
forceSave: true,
Message: window.Whisper.Message,
});
const model = new window.Whisper.Message(createdTheGroupMessage);
window.MessageController.register(model.id, model);
Expand Down Expand Up @@ -2837,7 +2836,6 @@ async function updateGroup(
if (changeMessagesToSave.length > 0) {
await window.Signal.Data.saveMessages(changeMessagesToSave, {
forceSave: true,
Message: window.Whisper.Message,
});
changeMessagesToSave.forEach(changeMessage => {
const model = new window.Whisper.Message(changeMessage);
Expand Down
4 changes: 1 addition & 3 deletions ts/messageModifiers/AttachmentDownloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ async function _finishJob(
): Promise<void> {
if (message) {
logger.info(`attachment_downloads/_finishJob for job id: ${id}`);
await saveMessage(message.attributes, {
Message: window.Whisper.Message,
});
await saveMessage(message.attributes);
}

await removeAttachmentDownloadJob(id);
Expand Down
49 changes: 12 additions & 37 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1598,9 +1598,7 @@ export class ConversationModel extends window.Backbone
const registered = window.MessageController.register(m.id, m);
const shouldSave = await registered.queueAttachmentDownloads();
if (shouldSave) {
await window.Signal.Data.saveMessage(registered.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(registered.attributes);
}
})
);
Expand Down Expand Up @@ -2399,9 +2397,7 @@ export class ConversationModel extends window.Backbone
// this type does not fully implement the interface it is expected to
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2439,9 +2435,7 @@ export class ConversationModel extends window.Backbone
// this type does not fully implement the interface it is expected to
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2477,9 +2471,7 @@ export class ConversationModel extends window.Backbone
// this type does not fully implement the interface it is expected to
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2537,9 +2529,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2598,9 +2588,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2651,9 +2639,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -2687,9 +2673,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as typeof window.Whisper.MessageAttributesType;

const id = await window.Signal.Data.saveMessage(message, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(message);
const model = window.MessageController.register(
id,
new window.Whisper.Message({
Expand Down Expand Up @@ -3539,7 +3523,6 @@ export class ConversationModel extends window.Backbone
const message = window.MessageController.register(model.id, model);
await window.Signal.Data.saveMessage(message.attributes, {
forceSave: true,
Message: window.Whisper.Message,
});

const draftProperties = dontClearDraft
Expand Down Expand Up @@ -4035,9 +4018,7 @@ export class ConversationModel extends window.Backbone
if (isDirectConversation(this.attributes)) {
model.set({ destination: this.getSendTarget() });
}
const id = await window.Signal.Data.saveMessage(model.attributes, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(model.attributes);

model.set({ id });

Expand Down Expand Up @@ -4130,9 +4111,7 @@ export class ConversationModel extends window.Backbone
if (isDirectConversation(this.attributes)) {
model.set({ destination: this.id });
}
const id = await window.Signal.Data.saveMessage(model.attributes, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(model.attributes);

model.set({ id });

Expand Down Expand Up @@ -4160,9 +4139,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as MessageAttributesType);

const id = await window.Signal.Data.saveMessage(model.attributes, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(model.attributes);
model.set({ id });

const message = window.MessageController.register(model.id, model);
Expand Down Expand Up @@ -4205,9 +4182,7 @@ export class ConversationModel extends window.Backbone
// TODO: DESKTOP-722
} as unknown) as MessageAttributesType);

const id = await window.Signal.Data.saveMessage(model.attributes, {
Message: window.Whisper.Message,
});
const id = await window.Signal.Data.saveMessage(model.attributes);
model.set({ id });

const message = window.MessageController.register(model.id, model);
Expand Down
47 changes: 10 additions & 37 deletions ts/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ export function isQuoteAMatch(
}

export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
static updateTimers: () => void;

static getLongMessageAttachment: (
attachment: typeof window.WhatIsThis
) => typeof window.WhatIsThis;
Expand Down Expand Up @@ -983,9 +981,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
this.getConversation()?.debouncedUpdateLastMessage?.();

if (shouldPersist) {
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
}
}

Expand Down Expand Up @@ -1163,9 +1159,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}

if (!skipSave && !this.doNotSave) {
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
}
}

Expand Down Expand Up @@ -1238,9 +1232,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (!recipients.length) {
window.log.warn('retrySend: Nobody to send to!');

return window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
return window.Signal.Data.saveMessage(this.attributes);
}

const attachmentsWithData = await Promise.all(
Expand Down Expand Up @@ -1536,9 +1528,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
});

if (!this.doNotSave) {
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
}

if (updateLeftPane) {
Expand Down Expand Up @@ -1741,9 +1731,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
// We don't save because we're about to save below.
this.saveErrors(errors, { skipSave: true });
} finally {
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);

if (updateLeftPane) {
updateLeftPane();
Expand Down Expand Up @@ -1798,9 +1786,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
return result;
}

await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
return result;
});
};
Expand Down Expand Up @@ -2343,9 +2329,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
originalMessage.attributes
);
originalMessage.set(upgradedMessage);
await window.Signal.Data.saveMessage(upgradedMessage, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(upgradedMessage);
}
} catch (error) {
window.log.error(
Expand Down Expand Up @@ -2479,9 +2463,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
unidentifiedDeliveries
),
});
await window.Signal.Data.saveMessage(toUpdate.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(toUpdate.attributes);

confirm();
return;
Expand Down Expand Up @@ -3188,9 +3170,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
window.log.info(
`modifyTargetMessage/${this.idForLogging()}: Changes in second run; saving.`
);
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
}
}

Expand Down Expand Up @@ -3295,9 +3275,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
);

if (shouldPersist) {
await window.Signal.Data.saveMessage(this.attributes, {
Message: window.Whisper.Message,
});
await window.Signal.Data.saveMessage(this.attributes);
}

return oldReaction;
Expand Down Expand Up @@ -3391,11 +3369,6 @@ window.Whisper.Message.getLongMessageAttachment = ({
};
};

window.Whisper.Message.updateTimers = () => {
window.Whisper.ExpiringMessagesListener.update();
window.Whisper.TapToViewMessagesListener.update();
};

window.Whisper.MessageCollection = window.Backbone.Collection.extend({
model: window.Whisper.Message,
comparator(left: Readonly<MessageModel>, right: Readonly<MessageModel>) {
Expand Down

0 comments on commit 385bcc4

Please sign in to comment.