Update timers whenever we mark messages read
This commit is contained in:
		
					parent
					
						
							
								cd35a29638
							
						
					
				
			
			
				commit
				
					
						7761d83055
					
				
			
		
					 16 changed files with 70 additions and 150 deletions
				
			
		| 
						 | 
				
			
			@ -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');
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    })
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,6 @@ const { isFunction, isNumber } = require('lodash');
 | 
			
		|||
const Message = require('./types/message');
 | 
			
		||||
 | 
			
		||||
exports.processNext = async ({
 | 
			
		||||
  BackboneMessage,
 | 
			
		||||
  BackboneMessageCollection,
 | 
			
		||||
  numMessagesPerBatch,
 | 
			
		||||
  upgradeMessageSchema,
 | 
			
		||||
| 
						 | 
				
			
			@ -18,12 +17,6 @@ exports.processNext = async ({
 | 
			
		|||
  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)" +
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,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';
 | 
			
		||||
| 
						 | 
				
			
			@ -859,7 +859,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,
 | 
			
		||||
| 
						 | 
				
			
			@ -1770,9 +1769,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');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2564,9 +2561,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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1718,7 +1718,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);
 | 
			
		||||
| 
						 | 
				
			
			@ -2864,7 +2863,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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1601,9 +1601,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);
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -2414,9 +2412,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2454,9 +2450,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2492,9 +2486,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2552,9 +2544,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2613,9 +2603,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2666,9 +2654,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -2702,9 +2688,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({
 | 
			
		||||
| 
						 | 
				
			
			@ -3579,7 +3563,6 @@ export class ConversationModel extends window.Backbone
 | 
			
		|||
      const messageId = message.id;
 | 
			
		||||
      await window.Signal.Data.saveMessage(message.attributes, {
 | 
			
		||||
        forceSave: true,
 | 
			
		||||
        Message: window.Whisper.Message,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const draftProperties = dontClearDraft
 | 
			
		||||
| 
						 | 
				
			
			@ -4082,9 +4065,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 });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -4182,9 +4163,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 });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -4212,9 +4191,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);
 | 
			
		||||
| 
						 | 
				
			
			@ -4257,9 +4234,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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -985,9 +983,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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    await window.Signal.Data.deleteSentProtoByMessageId(this.id);
 | 
			
		||||
| 
						 | 
				
			
			@ -1167,9 +1163,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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1242,9 +1236,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(
 | 
			
		||||
| 
						 | 
				
			
			@ -1553,9 +1545,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) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1756,9 +1746,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();
 | 
			
		||||
| 
						 | 
				
			
			@ -1815,9 +1803,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;
 | 
			
		||||
      });
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			@ -2360,9 +2346,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(
 | 
			
		||||
| 
						 | 
				
			
			@ -2496,9 +2480,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;
 | 
			
		||||
| 
						 | 
				
			
			@ -3186,9 +3168,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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3294,9 +3274,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;
 | 
			
		||||
| 
						 | 
				
			
			@ -3390,11 +3368,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>) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1068,25 +1068,27 @@ async function hasUserInitiatedMessages(conversationId: string) {
 | 
			
		|||
 | 
			
		||||
async function saveMessage(
 | 
			
		||||
  data: MessageType,
 | 
			
		||||
  { forceSave, Message }: { forceSave?: boolean; Message: typeof MessageModel }
 | 
			
		||||
  options?: { forceSave?: boolean }
 | 
			
		||||
) {
 | 
			
		||||
  const id = await channels.saveMessage(_cleanMessageData(data), {
 | 
			
		||||
    forceSave,
 | 
			
		||||
  });
 | 
			
		||||
  Message.updateTimers();
 | 
			
		||||
  const id = await channels.saveMessage(_cleanMessageData(data), options);
 | 
			
		||||
 | 
			
		||||
  window.Whisper.ExpiringMessagesListener.update();
 | 
			
		||||
  window.Whisper.TapToViewMessagesListener.update();
 | 
			
		||||
 | 
			
		||||
  return id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function saveMessages(
 | 
			
		||||
  arrayOfMessages: Array<MessageType>,
 | 
			
		||||
  { forceSave, Message }: { forceSave?: boolean; Message: typeof MessageModel }
 | 
			
		||||
  options?: { forceSave?: boolean }
 | 
			
		||||
) {
 | 
			
		||||
  await channels.saveMessages(
 | 
			
		||||
    arrayOfMessages.map(message => _cleanMessageData(message)),
 | 
			
		||||
    { forceSave }
 | 
			
		||||
    options
 | 
			
		||||
  );
 | 
			
		||||
  Message.updateTimers();
 | 
			
		||||
 | 
			
		||||
  window.Whisper.ExpiringMessagesListener.update();
 | 
			
		||||
  window.Whisper.TapToViewMessagesListener.update();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function removeMessage(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -293,6 +293,14 @@ export type DataInterface = {
 | 
			
		|||
    options?: { limit?: number }
 | 
			
		||||
  ) => Promise<Array<ConversationType>>;
 | 
			
		||||
 | 
			
		||||
  saveMessage: (
 | 
			
		||||
    data: MessageType,
 | 
			
		||||
    options?: { forceSave?: boolean }
 | 
			
		||||
  ) => Promise<string>;
 | 
			
		||||
  saveMessages: (
 | 
			
		||||
    arrayOfMessages: Array<MessageType>,
 | 
			
		||||
    options?: { forceSave?: boolean }
 | 
			
		||||
  ) => Promise<void>;
 | 
			
		||||
  getMessageCount: (conversationId?: string) => Promise<number>;
 | 
			
		||||
  hasUserInitiatedMessages: (conversationId: string) => Promise<boolean>;
 | 
			
		||||
  getAllMessageIds: () => Promise<Array<string>>;
 | 
			
		||||
| 
						 | 
				
			
			@ -487,14 +495,6 @@ export type ServerInterface = DataInterface & {
 | 
			
		|||
    conversationId: string,
 | 
			
		||||
    options?: { limit?: number }
 | 
			
		||||
  ) => Promise<Array<SearchResultMessageType>>;
 | 
			
		||||
  saveMessage: (
 | 
			
		||||
    data: MessageType,
 | 
			
		||||
    options: { forceSave?: boolean }
 | 
			
		||||
  ) => Promise<string>;
 | 
			
		||||
  saveMessages: (
 | 
			
		||||
    arrayOfMessages: Array<MessageType>,
 | 
			
		||||
    options: { forceSave?: boolean }
 | 
			
		||||
  ) => Promise<void>;
 | 
			
		||||
  updateConversation: (data: ConversationType) => Promise<void>;
 | 
			
		||||
 | 
			
		||||
  // For testing only
 | 
			
		||||
| 
						 | 
				
			
			@ -599,14 +599,6 @@ export type ClientInterface = DataInterface & {
 | 
			
		|||
    ids: Array<string>,
 | 
			
		||||
    options: { Message: typeof MessageModel }
 | 
			
		||||
  ) => Promise<void>;
 | 
			
		||||
  saveMessage: (
 | 
			
		||||
    data: MessageType,
 | 
			
		||||
    options: { forceSave?: boolean; Message: typeof MessageModel }
 | 
			
		||||
  ) => Promise<string>;
 | 
			
		||||
  saveMessages: (
 | 
			
		||||
    arrayOfMessages: Array<MessageType>,
 | 
			
		||||
    options: { forceSave?: boolean; Message: typeof MessageModel }
 | 
			
		||||
  ) => Promise<void>;
 | 
			
		||||
  searchMessages: (
 | 
			
		||||
    query: string,
 | 
			
		||||
    options?: { limit?: number }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3496,11 +3496,11 @@ async function hasUserInitiatedMessages(
 | 
			
		|||
 | 
			
		||||
function saveMessageSync(
 | 
			
		||||
  data: MessageType,
 | 
			
		||||
  options: { forceSave?: boolean; alreadyInTransaction?: boolean } = {}
 | 
			
		||||
  options?: { forceSave?: boolean; alreadyInTransaction?: boolean }
 | 
			
		||||
): string {
 | 
			
		||||
  const db = getInstance();
 | 
			
		||||
 | 
			
		||||
  const { forceSave, alreadyInTransaction } = options;
 | 
			
		||||
  const { forceSave, alreadyInTransaction } = options || {};
 | 
			
		||||
 | 
			
		||||
  if (!alreadyInTransaction) {
 | 
			
		||||
    return db.transaction(() => {
 | 
			
		||||
| 
						 | 
				
			
			@ -3657,16 +3657,17 @@ function saveMessageSync(
 | 
			
		|||
 | 
			
		||||
async function saveMessage(
 | 
			
		||||
  data: MessageType,
 | 
			
		||||
  options: { forceSave?: boolean; alreadyInTransaction?: boolean }
 | 
			
		||||
  options?: { forceSave?: boolean; alreadyInTransaction?: boolean }
 | 
			
		||||
): Promise<string> {
 | 
			
		||||
  return saveMessageSync(data, options);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function saveMessages(
 | 
			
		||||
  arrayOfMessages: Array<MessageType>,
 | 
			
		||||
  { forceSave }: { forceSave?: boolean } = {}
 | 
			
		||||
  options?: { forceSave?: boolean }
 | 
			
		||||
): Promise<void> {
 | 
			
		||||
  const db = getInstance();
 | 
			
		||||
  const { forceSave } = options || {};
 | 
			
		||||
 | 
			
		||||
  db.transaction(() => {
 | 
			
		||||
    for (const message of arrayOfMessages) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,6 @@ describe('Conversations', () => {
 | 
			
		|||
    // Saving to db and updating the convo's last message
 | 
			
		||||
    await window.Signal.Data.saveMessage(message.attributes, {
 | 
			
		||||
      forceSave: true,
 | 
			
		||||
      Message: window.Whisper.Message,
 | 
			
		||||
    });
 | 
			
		||||
    message = window.MessageController.register(message.id, message);
 | 
			
		||||
    await window.Signal.Data.saveConversation(conversation.attributes);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -111,7 +111,7 @@ describe('sendLog', () => {
 | 
			
		|||
        timestamp,
 | 
			
		||||
        type: 'outgoing',
 | 
			
		||||
      },
 | 
			
		||||
      { forceSave: true, Message: window.Whisper.Message }
 | 
			
		||||
      { forceSave: true }
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    const bytes = Buffer.from(getRandomBytes(128));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -130,5 +130,8 @@ export async function markConversationRead(
 | 
			
		|||
    await sendReadReceiptsFor(conversationAttrs, unreadMessagesSyncData);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  window.Whisper.ExpiringMessagesListener.update();
 | 
			
		||||
  window.Whisper.TapToViewMessagesListener.update();
 | 
			
		||||
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,9 +11,7 @@ const updateMessageBatcher = createBatcher<MessageAttributesType>({
 | 
			
		|||
  maxSize: 50,
 | 
			
		||||
  processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
 | 
			
		||||
    window.log.info('updateMessageBatcher', messageAttrs.length);
 | 
			
		||||
    await window.Signal.Data.saveMessages(messageAttrs, {
 | 
			
		||||
      Message: window.Whisper.Message,
 | 
			
		||||
    });
 | 
			
		||||
    await window.Signal.Data.saveMessages(messageAttrs);
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,9 +21,7 @@ export function queueUpdateMessage(messageAttr: MessageAttributesType): void {
 | 
			
		|||
  if (shouldBatch) {
 | 
			
		||||
    updateMessageBatcher.add(messageAttr);
 | 
			
		||||
  } else {
 | 
			
		||||
    window.Signal.Data.saveMessage(messageAttr, {
 | 
			
		||||
      Message: window.Whisper.Message,
 | 
			
		||||
    });
 | 
			
		||||
    window.Signal.Data.saveMessage(messageAttr);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +37,6 @@ export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
 | 
			
		|||
    window.log.info('saveNewMessageBatcher', messageAttrs.length);
 | 
			
		||||
    await window.Signal.Data.saveMessages(messageAttrs, {
 | 
			
		||||
      forceSave: true,
 | 
			
		||||
      Message: window.Whisper.Message,
 | 
			
		||||
    });
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1150,9 +1150,7 @@ Whisper.ConversationView = Whisper.View.extend({
 | 
			
		|||
        const upgradedMessage = await upgradeMessageSchema(attributes);
 | 
			
		||||
        message.set(upgradedMessage);
 | 
			
		||||
        // eslint-disable-next-line no-await-in-loop
 | 
			
		||||
        await window.Signal.Data.saveMessage(upgradedMessage, {
 | 
			
		||||
          Message: Whisper.Message,
 | 
			
		||||
        });
 | 
			
		||||
        await window.Signal.Data.saveMessage(upgradedMessage);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2543,9 +2541,7 @@ Whisper.ConversationView = Whisper.View.extend({
 | 
			
		|||
          // eslint-disable-next-line no-await-in-loop
 | 
			
		||||
          rawMedia[i] = await upgradeMessageSchema(message);
 | 
			
		||||
          // eslint-disable-next-line no-await-in-loop
 | 
			
		||||
          await window.Signal.Data.saveMessage(rawMedia[i], {
 | 
			
		||||
            Message: Whisper.Message,
 | 
			
		||||
          });
 | 
			
		||||
          await window.Signal.Data.saveMessage(rawMedia[i]);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								ts/window.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								ts/window.d.ts
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -559,10 +559,7 @@ export type LoggerType = {
 | 
			
		|||
export type LogFunctionType = (...args: Array<unknown>) => void;
 | 
			
		||||
 | 
			
		||||
export type WhisperType = {
 | 
			
		||||
  events: {
 | 
			
		||||
    on: (name: string, callback: (param1: any, param2?: any) => void) => void;
 | 
			
		||||
    trigger: (name: string, param1?: any, param2?: any) => void;
 | 
			
		||||
  };
 | 
			
		||||
  events: Backbone.Events;
 | 
			
		||||
  Database: {
 | 
			
		||||
    open: () => Promise<IDBDatabase>;
 | 
			
		||||
    handleDOMException: (
 | 
			
		||||
| 
						 | 
				
			
			@ -620,8 +617,15 @@ export type WhisperType = {
 | 
			
		|||
 | 
			
		||||
  IdenticonSVGView: WhatIsThis;
 | 
			
		||||
 | 
			
		||||
  ExpiringMessagesListener: WhatIsThis;
 | 
			
		||||
  TapToViewMessagesListener: WhatIsThis;
 | 
			
		||||
  ExpiringMessagesListener: {
 | 
			
		||||
    init: (events: Backbone.Events) => void;
 | 
			
		||||
    update: () => void;
 | 
			
		||||
  };
 | 
			
		||||
  TapToViewMessagesListener: {
 | 
			
		||||
    nextCheck: null | number;
 | 
			
		||||
    init: (events: Backbone.Events) => void;
 | 
			
		||||
    update: () => void;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  deliveryReceiptQueue: PQueue;
 | 
			
		||||
  deliveryReceiptBatcher: BatcherType<DeliveryReceiptBatcherItemType>;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue