Automatic session reset

This commit is contained in:
Scott Nonnenberg 2021-02-18 08:40:26 -08:00 committed by Josh Perez
parent fe187226bb
commit 98e7e65d25
26 changed files with 803 additions and 225 deletions

View file

@ -2277,6 +2277,35 @@ export class ConversationModel extends window.Backbone.Model<
return this.setVerified();
}
async addChatSessionRefreshed(receivedAt: number): Promise<void> {
window.log.info(
`addChatSessionRefreshed: adding for ${this.idForLogging()}`
);
const message = ({
conversationId: this.id,
type: 'chat-session-refreshed',
sent_at: receivedAt,
received_at: receivedAt,
unread: 1,
// TODO: DESKTOP-722
// 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 model = window.MessageController.register(
id,
new window.Whisper.Message({
...message,
id,
})
);
this.trigger('newmessage', model);
}
async addKeyChange(keyChangedId: string): Promise<void> {
window.log.info(
'adding key change advisory for',

View file

@ -201,6 +201,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
isNormalBubble(): boolean {
return (
!this.isCallHistory() &&
!this.isChatSessionRefreshed() &&
!this.isEndSession() &&
!this.isExpirationTimerUpdate() &&
!this.isGroupUpdate() &&
@ -282,6 +283,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
data: this.getPropsForProfileChange(),
};
}
if (this.isChatSessionRefreshed()) {
return {
type: 'chatSessionRefreshed',
data: null,
};
}
return {
type: 'message',
@ -461,6 +468,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
return this.get('type') === 'call-history';
}
isChatSessionRefreshed(): boolean {
return this.get('type') === 'chat-session-refreshed';
}
isProfileChange(): boolean {
return this.get('type') === 'profile-change';
}
@ -1178,6 +1189,13 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}
getNotificationData(): { emoji?: string; text: string } {
if (this.isChatSessionRefreshed()) {
return {
emoji: '🔁',
text: window.i18n('ChatRefresh--notification'),
};
}
if (this.isUnsupportedMessage()) {
return {
text: window.i18n('message--getDescription--unsupported-message'),
@ -1695,6 +1713,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
// Rendered sync messages
const isCallHistory = this.isCallHistory();
const isChatSessionRefreshed = this.isChatSessionRefreshed();
const isGroupUpdate = this.isGroupUpdate();
const isGroupV2Change = this.isGroupV2Change();
const isEndSession = this.isEndSession();
@ -1723,6 +1742,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
isSticker ||
// Rendered sync messages
isCallHistory ||
isChatSessionRefreshed ||
isGroupUpdate ||
isGroupV2Change ||
isEndSession ||