Change Phone Number notifications
This commit is contained in:
parent
4b82ac387b
commit
a001882d58
17 changed files with 277 additions and 39 deletions
|
@ -152,8 +152,6 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
jobQueue?: typeof window.PQueueType;
|
||||
|
||||
ourNumber?: string;
|
||||
|
||||
ourUuid?: string;
|
||||
|
||||
storeName?: string | null;
|
||||
|
@ -234,7 +232,6 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
this.storeName = 'conversations';
|
||||
|
||||
this.ourNumber = window.textsecure.storage.user.getNumber();
|
||||
this.ourUuid = window.textsecure.storage.user.getUuid();
|
||||
this.verifiedEnum = window.textsecure.storage.protocol.VerifiedStatus;
|
||||
|
||||
|
@ -1497,6 +1494,11 @@ export class ConversationModel extends window.Backbone
|
|||
const oldValue = this.get('e164');
|
||||
if (e164 && e164 !== oldValue) {
|
||||
this.set('e164', e164);
|
||||
|
||||
if (oldValue) {
|
||||
this.addChangeNumberNotification();
|
||||
}
|
||||
|
||||
window.Signal.Data.updateConversation(this.attributes);
|
||||
this.trigger('idUpdated', this, 'e164', oldValue);
|
||||
}
|
||||
|
@ -2688,7 +2690,7 @@ export class ConversationModel extends window.Backbone
|
|||
sent_at: now,
|
||||
received_at: window.Signal.Util.incrementMessageCounter(),
|
||||
received_at_ms: now,
|
||||
unread: 0,
|
||||
unread: false,
|
||||
changedId: conversationId || this.id,
|
||||
profileChange,
|
||||
// TODO: DESKTOP-722
|
||||
|
@ -2716,23 +2718,30 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
}
|
||||
|
||||
async addUniversalTimerNotification(): Promise<string> {
|
||||
async addNotification(
|
||||
type: MessageAttributesType['type'],
|
||||
extra: Partial<MessageAttributesType> = {}
|
||||
): Promise<string> {
|
||||
const now = Date.now();
|
||||
const message = ({
|
||||
const message: Partial<MessageAttributesType> = {
|
||||
...extra,
|
||||
|
||||
conversationId: this.id,
|
||||
type: 'universal-timer-notification',
|
||||
type,
|
||||
sent_at: now,
|
||||
received_at: window.Signal.Util.incrementMessageCounter(),
|
||||
received_at_ms: now,
|
||||
unread: 0,
|
||||
// TODO: DESKTOP-722
|
||||
} as unknown) as typeof window.Whisper.MessageAttributesType;
|
||||
unread: false,
|
||||
};
|
||||
|
||||
const id = await window.Signal.Data.saveMessage(message);
|
||||
const id = await window.Signal.Data.saveMessage(
|
||||
// TODO: DESKTOP-722
|
||||
message as MessageAttributesType
|
||||
);
|
||||
const model = window.MessageController.register(
|
||||
id,
|
||||
new window.Whisper.Message({
|
||||
...message,
|
||||
...(message as MessageAttributesType),
|
||||
id,
|
||||
})
|
||||
);
|
||||
|
@ -2764,7 +2773,9 @@ export class ConversationModel extends window.Backbone
|
|||
return;
|
||||
}
|
||||
|
||||
const notificationId = await this.addUniversalTimerNotification();
|
||||
const notificationId = await this.addNotification(
|
||||
'universal-timer-notification'
|
||||
);
|
||||
this.set('pendingUniversalTimer', notificationId);
|
||||
}
|
||||
|
||||
|
@ -2797,6 +2808,27 @@ export class ConversationModel extends window.Backbone
|
|||
this.set('pendingUniversalTimer', undefined);
|
||||
}
|
||||
|
||||
async addChangeNumberNotification(): Promise<void> {
|
||||
window.log.info(
|
||||
`Conversation ${this.idForLogging()}: adding change number notification`
|
||||
);
|
||||
|
||||
const convos = [
|
||||
this,
|
||||
...(await window.ConversationController.getAllGroupsInvolvingId(this.id)),
|
||||
];
|
||||
|
||||
const sourceUuid = this.get('uuid');
|
||||
|
||||
await Promise.all(
|
||||
convos.map(convo => {
|
||||
return convo.addNotification('change-number-notification', {
|
||||
sourceUuid,
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async onReadMessage(
|
||||
message: MessageModel,
|
||||
readAt?: number
|
||||
|
|
|
@ -178,8 +178,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
INITIAL_PROTOCOL_VERSION?: number;
|
||||
|
||||
OUR_NUMBER?: string;
|
||||
|
||||
OUR_UUID?: string;
|
||||
|
||||
isSelected?: boolean;
|
||||
|
@ -209,7 +207,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
this.CURRENT_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.CURRENT;
|
||||
this.INITIAL_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.INITIAL;
|
||||
this.OUR_NUMBER = window.textsecure.storage.user.getNumber();
|
||||
this.OUR_UUID = window.textsecure.storage.user.getUuid();
|
||||
|
||||
this.on('change', this.notifyRedux);
|
||||
|
@ -364,7 +361,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
this.attributes,
|
||||
findAndFormatContact,
|
||||
ourConversationId,
|
||||
this.OUR_NUMBER,
|
||||
window.textsecure.storage.user.getNumber(),
|
||||
this.OUR_UUID,
|
||||
undefined,
|
||||
undefined,
|
||||
|
@ -1066,7 +1063,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
}
|
||||
|
||||
return this.OUR_NUMBER;
|
||||
return window.textsecure.storage.user.getNumber();
|
||||
}
|
||||
|
||||
getSourceDevice(): string | number | undefined {
|
||||
|
@ -1280,11 +1277,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const quoteWithData = await loadQuoteData(this.get('quote'));
|
||||
const previewWithData = await loadPreviewData(this.get('preview'));
|
||||
const stickerWithData = await loadStickerData(this.get('sticker'));
|
||||
const ourNumber = window.textsecure.storage.user.getNumber();
|
||||
|
||||
// Special-case the self-send case - we send only a sync message
|
||||
if (
|
||||
recipients.length === 1 &&
|
||||
(recipients[0] === this.OUR_NUMBER || recipients[0] === this.OUR_UUID)
|
||||
(recipients[0] === ourNumber || recipients[0] === this.OUR_UUID)
|
||||
) {
|
||||
const dataMessage = await window.textsecure.messaging.getDataMessage({
|
||||
attachments,
|
||||
|
@ -1434,9 +1432,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const quoteWithData = await loadQuoteData(this.get('quote'));
|
||||
const previewWithData = await loadPreviewData(this.get('preview'));
|
||||
const stickerWithData = await loadStickerData(this.get('sticker'));
|
||||
const ourNumber = window.textsecure.storage.user.getNumber();
|
||||
|
||||
// Special-case the self-send case - we send only a sync message
|
||||
if (identifier === this.OUR_NUMBER || identifier === this.OUR_UUID) {
|
||||
if (identifier === ourNumber || identifier === this.OUR_UUID) {
|
||||
const dataMessage = await window.textsecure.messaging.getDataMessage({
|
||||
attachments,
|
||||
body,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue