fix: improved logging

made some progress with fixing things but other things broke
pull/2971/head
William Grant 2 years ago
parent 3d2c1fbe78
commit 50f144a8c3

@ -739,13 +739,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async sendMessage(msg: SendMessageType) { public async sendMessage(msg: SendMessageType) {
const { attachments, body, groupInvitation, preview, quote } = msg; const { attachments, body, groupInvitation, preview, quote } = msg;
this.clearTypingTimers(); this.clearTypingTimers();
const expireTimer = this.get('expireTimer');
const expirationType = changeToDisappearingMessageType(
this,
expireTimer,
this.get('expirationType')
);
const networkTimestamp = GetNetworkTime.getNowWithNetworkOffset(); const networkTimestamp = GetNetworkTime.getNowWithNetworkOffset();
window?.log?.info( window?.log?.info(
@ -761,8 +754,12 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
preview, preview,
attachments, attachments,
sent_at: networkTimestamp, sent_at: networkTimestamp,
expirationType, expirationType: changeToDisappearingMessageType(
expireTimer, this,
this.get('expireTimer'),
this.get('expirationType')
),
expireTimer: this.get('expireTimer'),
serverTimestamp: this.isPublic() ? networkTimestamp : undefined, serverTimestamp: this.isPublic() ? networkTimestamp : undefined,
groupInvitation, groupInvitation,
}); });
@ -783,6 +780,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
lastMessageStatus: 'sending', lastMessageStatus: 'sending',
active_at: networkTimestamp, active_at: networkTimestamp,
}); });
await this.commit(); await this.commit();
void this.queueJob(async () => { void this.queueJob(async () => {
@ -853,13 +851,16 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
// NOTE: We don' mind if the message is the same, we still want to update the conversation because we want to show visible control messages we receive an ExpirationTimerUpdate // NOTE: We don' mind if the message is the same, we still want to update the conversation because we want to show visible control messages we receive an ExpirationTimerUpdate
// Compare mode and timestamp
if ( if (
fromConfigMessage &&
isEqual(expirationType, this.get('expirationType')) && isEqual(expirationType, this.get('expirationType')) &&
isEqual(expireTimer, this.get('expireTimer')) isEqual(expireTimer, this.get('expireTimer'))
) { ) {
window.log.info( window.log.info(
'WIP: conversation: updateExpireTimer() Dropping ExpireTimerUpdate message as we already have the same one set.' `WIP: conversation: updateExpireTimer() Ignoring ExpireTimerUpdate ${
fromSync ? 'sync ' : ''
}message as we already have the same one set.`,
fromConfigMessage && 'This came from libsession.'
); );
return; return;
} }
@ -894,41 +895,38 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer, expireTimer,
expirationType expirationType
); );
window.log.debug(`WIP: updateExpireTimer() messageExpirationType: ${messageExpirationType}`);
// we don't have info about who made the change and when, when we get a change from a config message, so do not add a control message // we don't have info about who made the change and when, when we get a change from a config message, so do not add a control message
// TODO NOTE We might not show it in the UI but still need to process it using the senttimestamp as the lastchange timestamp for config messages // TODO NOTE We might not show it in the UI but still need to process it using the sentTimestamp as the lastChange timestamp for config messages
if (!fromConfigMessage) { const commonAttributes = {
const commonAttributes = { flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE, expirationTimerUpdate: {
expirationTimerUpdate: {
expirationType: messageExpirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
expirationType: messageExpirationType, expirationType: messageExpirationType,
expireTimer, expireTimer,
}; lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
expirationType: messageExpirationType,
expireTimer,
};
if (!message) { if (!message) {
if (isOutgoing) { if (isOutgoing) {
message = await this.addSingleOutgoingMessage({ message = await this.addSingleOutgoingMessage({
...commonAttributes, ...commonAttributes,
sent_at: timestamp, sent_at: timestamp,
}); });
} else { } else {
message = await this.addSingleIncomingMessage({ message = await this.addSingleIncomingMessage({
...commonAttributes, ...commonAttributes,
// Even though this isn't reflected to the user, we want to place the last seen // Even though this isn't reflected to the user, we want to place the last seen
// indicator above it. We set it to 'unread' to trigger that placement. // indicator above it. We set it to 'unread' to trigger that placement.
unread: READ_MESSAGE_STATE.unread, unread: READ_MESSAGE_STATE.unread,
source, source,
sent_at: timestamp, sent_at: timestamp,
received_at: timestamp, received_at: timestamp,
}); });
}
} }
} }
@ -944,7 +942,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// if change was made remotely, don't send it to the contact/group // if change was made remotely, don't send it to the contact/group
if (fromSync || fromConfigMessage) { if (fromSync || fromConfigMessage) {
window.log.debug( window.log.debug(
`WIP: updateExpireTimer() Not sending an ExpireTimerUpdate message because the change was made remotely receivedAt:${receivedAt} fromSync:${fromSync} fromConfigMessage:${fromConfigMessage} ` `WIP: updateExpireTimer() Not sending an ExpireTimerUpdate message because change was made remotely receivedAt:${receivedAt} fromSync:${fromSync} fromConfigMessage:${fromConfigMessage} `
); );
return; return;
} }
@ -966,10 +964,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate); const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate);
window.log.debug( // window.log.debug(
`WIP: updateExpireTimer() isMe() expirationTimerMessage`, // `WIP: updateExpireTimer() isMe() expirationTimerMessage`,
JSON.stringify(expirationTimerMessage) // JSON.stringify(expirationTimerMessage)
); // );
await message?.sendSyncMessageOnly(expirationTimerMessage); await message?.sendSyncMessageOnly(expirationTimerMessage);
return; return;
@ -977,10 +975,12 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (this.isPrivate()) { if (this.isPrivate()) {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate); const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate);
window.log.debug(
`WIP: updateExpireTimer() isPrivate() expirationTimerMessage`, // window.log.debug(
JSON.stringify(expirationTimerMessage) // `WIP: updateExpireTimer() isPrivate() expirationTimerMessage`,
); // JSON.stringify(expirationTimerMessage)
// );
const pubkey = new PubKey(this.get('id')); const pubkey = new PubKey(this.get('id'));
await getMessageQueue().sendToPubKey( await getMessageQueue().sendToPubKey(
pubkey, pubkey,
@ -997,10 +997,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdateForGroup); const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdateForGroup);
window.log.debug( // window.log.debug(
`WIP: updateExpireTimer() isClosedGroup() expirationTimerMessage`, // `WIP: updateExpireTimer() isClosedGroup() expirationTimerMessage`,
JSON.stringify(expirationTimerMessage) // JSON.stringify(expirationTimerMessage)
); // );
await getMessageQueue().sendToGroup({ await getMessageQueue().sendToGroup({
message: expirationTimerMessage, message: expirationTimerMessage,
@ -1812,8 +1812,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// we are trying to send a message to someone. Make sure this convo is not hidden // we are trying to send a message to someone. Make sure this convo is not hidden
await this.unhideIfNeeded(true); await this.unhideIfNeeded(true);
const expirationType = message.get('expirationType');
const expireTimer = message.get('expireTimer');
// an OpenGroupV2 message is just a visible message // an OpenGroupV2 message is just a visible message
const chatMessageParams: VisibleMessageParams = { const chatMessageParams: VisibleMessageParams = {
@ -1821,9 +1819,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
identifier: id, identifier: id,
timestamp: sentAt, timestamp: sentAt,
attachments, attachments,
// TODO not supported in open groups expirationType: message.get('expirationType'),
expirationType, expireTimer: message.get('expireTimer'),
expireTimer,
preview: preview ? [preview] : [], preview: preview ? [preview] : [],
quote, quote,
lokiProfile: UserUtils.getOurProfile(), lokiProfile: UserUtils.getOurProfile(),
@ -1897,8 +1894,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
timestamp: sentAt, timestamp: sentAt,
name: groupInvitation.name, name: groupInvitation.name,
url: groupInvitation.url, url: groupInvitation.url,
expirationType, expirationType: chatMessageParams.expirationType,
expireTimer, expireTimer: chatMessageParams.expireTimer,
}); });
// we need the return await so that errors are caught in the catch {} // we need the return await so that errors are caught in the catch {}
await getMessageQueue().sendToPubKey( await getMessageQueue().sendToPubKey(

@ -1023,6 +1023,8 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
throw new Error('Cannot trigger syncMessage with unknown convo.'); throw new Error('Cannot trigger syncMessage with unknown convo.');
} }
// TODO things be broken
// debugger;
const expireUpdate = await checkForExpireUpdateInContentMessage(content, conversation); const expireUpdate = await checkForExpireUpdateInContentMessage(content, conversation);
const syncMessage = buildSyncMessage( const syncMessage = buildSyncMessage(
@ -1100,7 +1102,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
public markMessageReadNoCommit(readAt: number) { public markMessageReadNoCommit(readAt: number) {
window.log.debug(`WIP: markMessageReadNoCommit ${this.idForLogging()}`, this);
this.set({ unread: READ_MESSAGE_STATE.read }); this.set({ unread: READ_MESSAGE_STATE.read });
const convo = this.getConversation(); const convo = this.getConversation();
@ -1109,7 +1110,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const expireTimer = this.get('expireTimer'); const expireTimer = this.get('expireTimer');
if (canBeDeleteAfterRead && expirationType && expireTimer > 0) { if (canBeDeleteAfterRead && expirationType && expireTimer > 0) {
window.log.debug(`WIP: markMessageReadNoCommit ${this.idForLogging()} is deleteAfterRead`); window.log.debug(
`WIP: markMessageReadNoCommit ${this.idForLogging()} is deleteAfterRead starting expiration`
);
const expirationMode = changeToDisappearingMessageConversationType( const expirationMode = changeToDisappearingMessageConversationType(
convo, convo,
expirationType, expirationType,

@ -223,12 +223,12 @@ async function handleUserProfileUpdate(result: IncomingConfResult): Promise<Inco
const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache()); const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
if (ourConvo) { if (ourConvo) {
window.log.debug(`WIP: [userProfileWrapper] Checking for disappearing messages changes`);
let changes = false; let changes = false;
const expireTimer = ourConvo.get('expireTimer'); const expireTimer = ourConvo.get('expireTimer');
const wrapperNoteToSelfExpirySeconds = await UserConfigWrapperActions.getNoteToSelfExpiry(); const wrapperNoteToSelfExpirySeconds = await UserConfigWrapperActions.getNoteToSelfExpiry();
// TODO Should use updateExpireTimer instead
if (wrapperNoteToSelfExpirySeconds !== expireTimer) { if (wrapperNoteToSelfExpirySeconds !== expireTimer) {
// we trust the wrapper more than the DB, so let's update the DB but we don't show it in the UI // we trust the wrapper more than the DB, so let's update the DB but we don't show it in the UI
ourConvo.set('expireTimer', wrapperNoteToSelfExpirySeconds); ourConvo.set('expireTimer', wrapperNoteToSelfExpirySeconds);
@ -591,13 +591,6 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
continue; continue;
} }
window.log.debug(
`WIP: handleLegacyGroupUpdate for ${fromWrapper.pubkeyHex}legacyGroupConvo `,
legacyGroupConvo,
'fromWrapper',
fromWrapper
);
const members = fromWrapper.members.map(m => m.pubkeyHex); const members = fromWrapper.members.map(m => m.pubkeyHex);
const admins = fromWrapper.members.filter(m => m.isAdmin).map(m => m.pubkeyHex); const admins = fromWrapper.members.filter(m => m.isAdmin).map(m => m.pubkeyHex);
// then for all the existing legacy group in the wrapper, we need to override the field of what we have in the DB with what is in the wrapper // then for all the existing legacy group in the wrapper, we need to override the field of what we have in the DB with what is in the wrapper
@ -619,8 +612,6 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
expireTimer: fromWrapper.disappearingTimerSeconds, expireTimer: fromWrapper.disappearingTimerSeconds,
}; };
window.log.debug(`WIP: groupDetails for ${fromWrapper.pubkeyHex} `, groupDetails);
await ClosedGroup.updateOrCreateClosedGroup(groupDetails); await ClosedGroup.updateOrCreateClosedGroup(groupDetails);
let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false); let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false);

@ -474,15 +474,17 @@ export async function innerHandleSwarmContentMessage(
if (isEmpty(content.dataMessage.profileKey)) { if (isEmpty(content.dataMessage.profileKey)) {
content.dataMessage.profileKey = null; content.dataMessage.profileKey = null;
} }
window.log.debug(`WIP: innerHandleSwarmContentMessage: ${JSON.stringify(content)}`);
const expireUpdate = await checkForExpireUpdateInContentMessage( const expireUpdate = await checkForExpireUpdateInContentMessage(
content, content,
conversationModelForUIUpdate conversationModelForUIUpdate
); );
window.log.debug( window.log.debug(
`WIP:innerHandleSwarmContentMessage expireUpdate: ${JSON.stringify(expireUpdate)}` `WIP:innerHandleSwarmContentMessage: ${
content.dataMessage.syncTarget ? 'This is a sync message.\n' : ''
} content: ${JSON.stringify(content)} ${
expireUpdate ? `\nexpireUpdate: ${JSON.stringify(expireUpdate)}` : ''
}`
); );
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
@ -494,7 +496,7 @@ export async function innerHandleSwarmContentMessage(
); );
if (expireUpdate.isLegacyConversationSettingMessage) { if (expireUpdate.isLegacyConversationSettingMessage) {
window.log.debug( window.log.debug(
`WIP: The legacy message is an expiration timer update. Ignoring it. ${JSON.stringify( `WIP: The legacy message is an expiration timer update. Ignoring it.\ncontent:${JSON.stringify(
content content
)}}` )}}`
); );

@ -25,7 +25,7 @@ import { isUsFromCache } from '../session/utils/User';
import { Action, Reaction } from '../types/Reaction'; import { Action, Reaction } from '../types/Reaction';
import { toLogFormat } from '../types/attachments/Errors'; import { toLogFormat } from '../types/attachments/Errors';
import { Reactions } from '../util/reactions'; import { Reactions } from '../util/reactions';
import { DisappearingMessageUpdate, updateMessageModelToExpire } from '../util/expiringMessages'; import { DisappearingMessageUpdate, getMessageReadyToDisappear } from '../util/expiringMessages';
function cleanAttachment(attachment: any) { function cleanAttachment(attachment: any) {
return { return {
@ -262,8 +262,7 @@ export async function handleSwarmDataMessage(
}); });
if (!isEmpty(expireUpdate)) { if (!isEmpty(expireUpdate)) {
msgModel = updateMessageModelToExpire(convoToAddMessageTo, msgModel, expireUpdate); msgModel = getMessageReadyToDisappear(convoToAddMessageTo, msgModel, expireUpdate);
window.log.debug(`WIP: innerHandleSwarmContentMessage msgModel ${JSON.stringify(msgModel)}`);
} }
await handleSwarmMessage( await handleSwarmMessage(

@ -1,4 +1,4 @@
import _, { isEmpty, isEqual, isNumber } from 'lodash'; import _, { isEmpty, isNumber } from 'lodash';
import { queueAttachmentDownloads } from './attachments'; import { queueAttachmentDownloads } from './attachments';
import { Data } from '../data/data'; import { Data } from '../data/data';
@ -10,7 +10,6 @@ import { Quote } from './types';
import { ConversationTypeEnum, READ_MESSAGE_STATE } from '../models/conversationAttributes'; import { ConversationTypeEnum, READ_MESSAGE_STATE } from '../models/conversationAttributes';
import { MessageDirection } from '../models/messageType'; import { MessageDirection } from '../models/messageType';
import { SignalService } from '../protobuf'; import { SignalService } from '../protobuf';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { ProfileManager } from '../session/profile_manager/ProfileManager'; import { ProfileManager } from '../session/profile_manager/ProfileManager';
import { showMessageRequestBannerOutsideRedux } from '../state/ducks/userConfig'; import { showMessageRequestBannerOutsideRedux } from '../state/ducks/userConfig';
import { getHideMessageRequestBannerOutsideRedux } from '../state/selectors/userConfig'; import { getHideMessageRequestBannerOutsideRedux } from '../state/selectors/userConfig';
@ -23,7 +22,6 @@ import { LinkPreviews } from '../util/linkPreviews';
import { ReleasedFeatures } from '../util/releaseFeature'; import { ReleasedFeatures } from '../util/releaseFeature';
import { PropsForMessageWithoutConvoProps, lookupQuote } from '../state/ducks/conversations'; import { PropsForMessageWithoutConvoProps, lookupQuote } from '../state/ducks/conversations';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils';
function contentTypeSupported(type: string): boolean { function contentTypeSupported(type: string): boolean {
const Chrome = GoogleChrome; const Chrome = GoogleChrome;
@ -194,10 +192,6 @@ function updateReadStatus(message: MessageModel) {
); );
if (expirationMode === 'legacy' || expirationMode === 'deleteAfterRead') { if (expirationMode === 'legacy' || expirationMode === 'deleteAfterRead') {
window.log.debug(
`WIP: updateReadStatus ${message.idForLogging()} is deleteAfterRead`,
message
);
message.set({ message.set({
expirationStartTimestamp: setExpirationStartTimestamp(expirationMode), expirationStartTimestamp: setExpirationStartTimestamp(expirationMode),
}); });
@ -396,46 +390,42 @@ export async function handleMessageJob(
try { try {
messageModel.set({ flags: regularDataMessage.flags }); messageModel.set({ flags: regularDataMessage.flags });
const expirationType = messageModel.get('expirationType');
const expireTimer = messageModel.get('expireTimer');
// NOTE we handle incoming disappear afer send messages and sync messages here // NOTE we handle incoming disappear afer send messages and sync messages here
if ( if (
conversation && conversation &&
expireTimer > 0 && messageModel.get('expireTimer') > 0 &&
Boolean(messageModel.get('expirationStartTimestamp')) === false Boolean(messageModel.get('expirationStartTimestamp')) === false
) { ) {
const expirationMode = changeToDisappearingMessageConversationType( const expirationMode = changeToDisappearingMessageConversationType(
conversation, conversation,
expirationType, messageModel.get('expirationType'),
expireTimer messageModel.get('expireTimer')
); );
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// NOTE if the expirationMode is deleteAfterRead then legacy sync messages need to explicitly set the expirationStartTimestamp since they are alread marked as read // NOTE if the expirationMode is deleteAfterRead then legacy sync messages need to explicitly set the expirationStartTimestamp since they are alread marked as read
const legacySyncMessageMustDisappearAfterRead = // NOTE 2: Not sure about this code needs retested
expirationMode === 'deleteAfterRead' && // const legacySyncMessageMustDisappearAfterRead =
source === UserUtils.getOurPubKeyStrFromCache() && // expirationMode === 'deleteAfterRead' &&
messageModel.get('type') === 'outgoing'; // source === UserUtils.getOurPubKeyStrFromCache() &&
// messageModel.get('type') === 'outgoing';
if ( if (
expirationMode === 'legacy' || expirationMode === 'legacy' ||
expirationMode === 'deleteAfterSend' || expirationMode === 'deleteAfterSend'
legacySyncMessageMustDisappearAfterRead // ||
// legacySyncMessageMustDisappearAfterRead
) { ) {
messageModel.set({ messageModel.set({
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
expirationMode, expirationMode,
!legacySyncMessageMustDisappearAfterRead ? messageModel.get('sent_at') : undefined messageModel.get('sent_at')
// !legacySyncMessageMustDisappearAfterRead ? messageModel.get('sent_at') : undefined
), ),
}); });
} }
} }
window.log.debug(
`WIP: handleMessageJob ${messageModel.idForLogging()} is ${JSON.stringify(messageModel)}`
);
if (messageModel.isExpirationTimerUpdate()) { if (messageModel.isExpirationTimerUpdate()) {
// NOTE if we turn off disappearing messages from a legacy client expirationTimerUpdate can be undefined but the flags value is correctly set // NOTE if we turn off disappearing messages from a legacy client expirationTimerUpdate can be undefined but the flags value is correctly set
const expirationTimerUpdate = messageModel.get('expirationTimerUpdate'); const expirationTimerUpdate = messageModel.get('expirationTimerUpdate');
@ -443,10 +433,10 @@ export async function handleMessageJob(
messageModel.get('flags') !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE && messageModel.get('flags') !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
(!expirationTimerUpdate || isEmpty(expirationTimerUpdate)) (!expirationTimerUpdate || isEmpty(expirationTimerUpdate))
) { ) {
window.log.info( window.log.debug(
'There is a problem with the expiration timer update', `WIP: There is a problem with the expiration timer update.\nmessage model: ${JSON.stringify(
messageModel, messageModel
expirationTimerUpdate )}\nexpirationTimerUpdte: ${JSON.stringify(expirationTimerUpdate)}`
); );
return; return;
} }
@ -458,17 +448,13 @@ export async function handleMessageJob(
expireTimerUpdate expireTimerUpdate
); );
const lastDisappearingMessageChangeTimestamp = const lastDisappearingMessageChangeTimestamp =
expirationTimerUpdate?.lastDisappearingMessageChangeTimestamp || expirationTimerUpdate?.lastDisappearingMessageChangeTimestamp;
GetNetworkTime.getNowWithNetworkOffset();
// Compare mode and timestamp if (!lastDisappearingMessageChangeTimestamp) {
if ( window.log.debug(
isEqual(expirationTypeUpdate, conversation.get('expirationType')) && `WIP: There is a problem with the expiration timer update. The lastDisappearingMessageChangeTimestamp is missing.\nmessage model: ${JSON.stringify(
isEqual(expireTimerUpdate, conversation.get('expireTimer')) messageModel
) { )}\nexpirationTimerUpdte: ${JSON.stringify(expirationTimerUpdate)}`
confirm?.();
window?.log?.info(
'WIP: queuedJob: Dropping ExpireTimerUpdate message as we already have the same one set.'
); );
return; return;
} }

@ -4,7 +4,10 @@ import { Storage } from '../../../../util/storage';
import { VisibleMessage, VisibleMessageParams } from './VisibleMessage'; import { VisibleMessage, VisibleMessageParams } from './VisibleMessage';
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
export type OpenGroupVisibleMessageParams = VisibleMessageParams & {}; export type OpenGroupVisibleMessageParams = Omit<
VisibleMessageParams,
'expirationType' | 'expireTimer'
>;
export class OpenGroupVisibleMessage extends VisibleMessage { export class OpenGroupVisibleMessage extends VisibleMessage {
private readonly blocksCommunityMessageRequests: boolean; private readonly blocksCommunityMessageRequests: boolean;

@ -218,7 +218,6 @@ export class MessageQueue {
} }
const ourPubKey = UserUtils.getOurPubKeyStrFromCache(); const ourPubKey = UserUtils.getOurPubKeyStrFromCache();
await this.process(PubKey.cast(ourPubKey), message, namespace, sentCb); await this.process(PubKey.cast(ourPubKey), message, namespace, sentCb);
} }

@ -148,10 +148,6 @@ async function handleMessageSentSuccess(
// NOTE we treat all outbound disappearing messages as read as soon as they are sent. // NOTE we treat all outbound disappearing messages as read as soon as they are sent.
if (expirationMode !== 'off') { if (expirationMode !== 'off') {
window.log.debug(
`WIP: handleMessageSentSuccess ${fetchedMessage.idForLogging()} is deleteAfterRead`,
fetchedMessage
);
fetchedMessage.set({ fetchedMessage.set({
expirationStartTimestamp: setExpirationStartTimestamp( expirationStartTimestamp: setExpirationStartTimestamp(
expirationMode, expirationMode,

@ -346,7 +346,7 @@ export function changeToDisappearingMessageConversationType(
expirationType?: DisappearingMessageType, expirationType?: DisappearingMessageType,
expireTimer?: number expireTimer?: number
): DisappearingMessageConversationType { ): DisappearingMessageConversationType {
if (expirationType === 'unknown') { if (!expirationType || expirationType === 'unknown') {
return expireTimer && expireTimer > 0 ? 'legacy' : 'off'; return expireTimer && expireTimer > 0 ? 'legacy' : 'off';
} }
@ -359,10 +359,11 @@ export function changeToDisappearingMessageConversationType(
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage // NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage
function checkIsLegacyDisappearingContentMessage(contentMessage: SignalService.Content): boolean { function couldBeLegacyDisappearingMessageContent(contentMessage: SignalService.Content): boolean {
return ( return (
(contentMessage.expirationType === SignalService.Content.ExpirationType.UNKNOWN || (contentMessage.expirationType === SignalService.Content.ExpirationType.UNKNOWN ||
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType')) && (ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() &&
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType'))) &&
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationTimer') !ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationTimer')
); );
} }
@ -378,11 +379,6 @@ function checkDisappearButIsntMessage(
expirationMode: DisappearingMessageConversationType, expirationMode: DisappearingMessageConversationType,
expirationTimer: number expirationTimer: number
): boolean { ): boolean {
window.log.debug(
`WIP: expirationMode ${expirationMode} expirationTimer ${expirationTimer} content ${JSON.stringify(
content
)} convo ${JSON.stringify(convo)}`
);
return ( return (
content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE && content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
expirationMode === 'off' && expirationMode === 'off' &&
@ -393,10 +389,13 @@ function checkDisappearButIsntMessage(
} }
export function checkIsLegacyDisappearingDataMessage( export function checkIsLegacyDisappearingDataMessage(
couldBeLegacyContent: boolean,
dataMessage: SignalService.DataMessage dataMessage: SignalService.DataMessage
): boolean { ): boolean {
return ( return (
ProtobufUtils.hasDefinedProperty(dataMessage, 'expireTimer') && dataMessage.expireTimer > -1 couldBeLegacyContent &&
ProtobufUtils.hasDefinedProperty(dataMessage, 'expireTimer') &&
dataMessage.expireTimer > -1
); );
} }
@ -409,32 +408,47 @@ export async function checkForExpireUpdateInContentMessage(
// We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked // We will only support legacy disappearing messages for a short period before disappearing messages v2 is unlocked
const isDisappearingMessagesV2Released = await ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased(); const isDisappearingMessagesV2Released = await ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased();
const isLegacyContentMessage = checkIsLegacyDisappearingContentMessage(content); const couldBeLegacyContentMessage = couldBeLegacyDisappearingMessageContent(content);
const isLegacyDataMessage = Boolean( const isLegacyDataMessage = checkIsLegacyDisappearingDataMessage(
isLegacyContentMessage && couldBeLegacyContentMessage,
checkIsLegacyDisappearingDataMessage(dataMessage as SignalService.DataMessage) dataMessage as SignalService.DataMessage
); );
const isLegacyConversationSettingMessage = isDisappearingMessagesV2Released const isLegacyConversationSettingMessage = isDisappearingMessagesV2Released
? isLegacyContentMessage && ? (isLegacyDataMessage ||
(isLegacyDataMessage || !content.lastDisappearingMessageChangeTimestamp) && (couldBeLegacyContentMessage && !content.lastDisappearingMessageChangeTimestamp)) &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
: isLegacyContentMessage && : couldBeLegacyContentMessage &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE; dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp
? Number(content.lastDisappearingMessageChangeTimestamp)
: undefined;
if (
convoToUpdate.get('lastDisappearingMessageChangeTimestamp') &&
lastDisappearingMessageChangeTimestamp &&
convoToUpdate.get('lastDisappearingMessageChangeTimestamp') >
lastDisappearingMessageChangeTimestamp
) {
window.log.info(
`WIP: checkForExpireUpdateInContentMessage() This is an outdated disappearing message setting.\ncontent: ${JSON.stringify(
content
)}\nconvoToUpdate: ${JSON.stringify(convoToUpdate)}`
);
return undefined;
}
const expirationTimer = isLegacyDataMessage const expirationTimer = isLegacyDataMessage
? Number(dataMessage.expireTimer) ? Number(dataMessage.expireTimer)
: content.expirationTimer; : content.expirationTimer;
// NOTE we don't use the expirationType directly from the Content Message because we need to resolve it to the correct convo type first in case it is legacy or has errors
const expirationMode = changeToDisappearingMessageConversationType( const expirationMode = changeToDisappearingMessageConversationType(
convoToUpdate, convoToUpdate,
DisappearingMessageMode[content.expirationType], DisappearingMessageMode[content.expirationType],
expirationTimer expirationTimer
); );
const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp
? Number(content.lastDisappearingMessageChangeTimestamp)
: undefined;
const shouldDisappearButIsntMessage = checkDisappearButIsntMessage( const shouldDisappearButIsntMessage = checkDisappearButIsntMessage(
content, content,
convoToUpdate, convoToUpdate,
@ -456,7 +470,7 @@ export async function checkForExpireUpdateInContentMessage(
if ( if (
!isDisappearingMessagesV2Released && !isDisappearingMessagesV2Released &&
!isLegacyConversationSettingMessage && !isLegacyConversationSettingMessage &&
isLegacyContentMessage && couldBeLegacyContentMessage &&
convoToUpdate.get('expirationType') !== 'off' convoToUpdate.get('expirationType') !== 'off'
) { ) {
if ( if (
@ -464,9 +478,9 @@ export async function checkForExpireUpdateInContentMessage(
expirationTimer !== convoToUpdate.get('expireTimer') expirationTimer !== convoToUpdate.get('expireTimer')
) { ) {
window.log.debug( window.log.debug(
'WIP: Received a legacy disappearing message before v2 was released without values set. Using the conversation settings.', `WIP: Received a legacy disappearing message before v2 was released without values set. Using the conversation settings.\ncontent: ${JSON.stringify(
content, content
convoToUpdate )}\nconvoToUpdate: ${JSON.stringify(convoToUpdate)}`
); );
expireUpdate.expirationTimer = convoToUpdate.get('expireTimer'); expireUpdate.expirationTimer = convoToUpdate.get('expireTimer');
@ -485,8 +499,9 @@ export async function checkForExpireUpdateInContentMessage(
(isLegacyDataMessage || isLegacyConversationSettingMessage || shouldDisappearButIsntMessage) (isLegacyDataMessage || isLegacyConversationSettingMessage || shouldDisappearButIsntMessage)
) { ) {
window.log.debug( window.log.debug(
'WIP: Received a legacy disappearing message after v2 was released. Overriding it with the conversation settings', `WIP: Received a legacy disappearing message after v2 was released. Overriding it with the conversation settings\ncontent: ${JSON.stringify(
content content
)}\nconvoToUpdate: ${JSON.stringify(convoToUpdate)}`
); );
expireUpdate.expirationTimer = convoToUpdate.get('expireTimer'); expireUpdate.expirationTimer = convoToUpdate.get('expireTimer');
@ -502,19 +517,19 @@ export async function checkForExpireUpdateInContentMessage(
} }
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
export function updateMessageModelToExpire( export function getMessageReadyToDisappear(
converationModel: ConversationModel, conversationModel: ConversationModel,
messageModel: MessageModel, messageModel: MessageModel,
expireUpdate?: DisappearingMessageUpdate expireUpdate?: DisappearingMessageUpdate
) { ) {
if (!expireUpdate) { if (!expireUpdate) {
window.log.debug(`WIP: callced updateMessageModelToExpire() without expireUpdate`); window.log.debug(`WIP: called getMessageReadyToDisappear() without an expireUpdate`);
return messageModel; return messageModel;
} }
if (converationModel.isPublic()) { if (conversationModel.isPublic()) {
window.log.warn( window.log.warn(
"updateMessageModelToExpire() Disappearing messages aren't supported in communities" "getMessageReadyToDisappear() Disappearing messages aren't supported in communities"
); );
return messageModel; return messageModel;
} }
@ -540,8 +555,8 @@ export function updateMessageModelToExpire(
expireTimer, expireTimer,
lastDisappearingMessageChangeTimestamp: isLegacyConversationSettingMessage lastDisappearingMessageChangeTimestamp: isLegacyConversationSettingMessage
? isDisappearingMessagesV2Released ? isDisappearingMessagesV2Released
? converationModel.get('lastDisappearingMessageChangeTimestamp') ? 0
: Date.now() : GetNetworkTime.getNowWithNetworkOffset()
: Number(lastDisappearingMessageChangeTimestamp), : Number(lastDisappearingMessageChangeTimestamp),
source: messageModel.get('source'), source: messageModel.get('source'),
}; };

Loading…
Cancel
Save