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) {
const { attachments, body, groupInvitation, preview, quote } = msg;
this.clearTypingTimers();
const expireTimer = this.get('expireTimer');
const expirationType = changeToDisappearingMessageType(
this,
expireTimer,
this.get('expirationType')
);
const networkTimestamp = GetNetworkTime.getNowWithNetworkOffset();
window?.log?.info(
@ -761,8 +754,12 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
preview,
attachments,
sent_at: networkTimestamp,
expirationType,
expireTimer,
expirationType: changeToDisappearingMessageType(
this,
this.get('expireTimer'),
this.get('expirationType')
),
expireTimer: this.get('expireTimer'),
serverTimestamp: this.isPublic() ? networkTimestamp : undefined,
groupInvitation,
});
@ -783,6 +780,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
lastMessageStatus: 'sending',
active_at: networkTimestamp,
});
await this.commit();
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
// Compare mode and timestamp
if (
fromConfigMessage &&
isEqual(expirationType, this.get('expirationType')) &&
isEqual(expireTimer, this.get('expireTimer'))
) {
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;
}
@ -894,41 +895,38 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer,
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
// 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 = {
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: {
expirationType: messageExpirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
// 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
const commonAttributes = {
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: {
expirationType: messageExpirationType,
expireTimer,
};
lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
expirationType: messageExpirationType,
expireTimer,
};
if (!message) {
if (isOutgoing) {
message = await this.addSingleOutgoingMessage({
...commonAttributes,
sent_at: timestamp,
});
} else {
message = await this.addSingleIncomingMessage({
...commonAttributes,
// 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.
unread: READ_MESSAGE_STATE.unread,
source,
sent_at: timestamp,
received_at: timestamp,
});
}
if (!message) {
if (isOutgoing) {
message = await this.addSingleOutgoingMessage({
...commonAttributes,
sent_at: timestamp,
});
} else {
message = await this.addSingleIncomingMessage({
...commonAttributes,
// 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.
unread: READ_MESSAGE_STATE.unread,
source,
sent_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 (fromSync || fromConfigMessage) {
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;
}
@ -966,10 +964,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate);
window.log.debug(
`WIP: updateExpireTimer() isMe() expirationTimerMessage`,
JSON.stringify(expirationTimerMessage)
);
// window.log.debug(
// `WIP: updateExpireTimer() isMe() expirationTimerMessage`,
// JSON.stringify(expirationTimerMessage)
// );
await message?.sendSyncMessageOnly(expirationTimerMessage);
return;
@ -977,10 +975,12 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
if (this.isPrivate()) {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate);
window.log.debug(
`WIP: updateExpireTimer() isPrivate() expirationTimerMessage`,
JSON.stringify(expirationTimerMessage)
);
// window.log.debug(
// `WIP: updateExpireTimer() isPrivate() expirationTimerMessage`,
// JSON.stringify(expirationTimerMessage)
// );
const pubkey = new PubKey(this.get('id'));
await getMessageQueue().sendToPubKey(
pubkey,
@ -997,10 +997,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdateForGroup);
window.log.debug(
`WIP: updateExpireTimer() isClosedGroup() expirationTimerMessage`,
JSON.stringify(expirationTimerMessage)
);
// window.log.debug(
// `WIP: updateExpireTimer() isClosedGroup() expirationTimerMessage`,
// JSON.stringify(expirationTimerMessage)
// );
await getMessageQueue().sendToGroup({
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
await this.unhideIfNeeded(true);
const expirationType = message.get('expirationType');
const expireTimer = message.get('expireTimer');
// an OpenGroupV2 message is just a visible message
const chatMessageParams: VisibleMessageParams = {
@ -1821,9 +1819,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
identifier: id,
timestamp: sentAt,
attachments,
// TODO not supported in open groups
expirationType,
expireTimer,
expirationType: message.get('expirationType'),
expireTimer: message.get('expireTimer'),
preview: preview ? [preview] : [],
quote,
lokiProfile: UserUtils.getOurProfile(),
@ -1897,8 +1894,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
timestamp: sentAt,
name: groupInvitation.name,
url: groupInvitation.url,
expirationType,
expireTimer,
expirationType: chatMessageParams.expirationType,
expireTimer: chatMessageParams.expireTimer,
});
// we need the return await so that errors are caught in the catch {}
await getMessageQueue().sendToPubKey(

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

@ -223,12 +223,12 @@ async function handleUserProfileUpdate(result: IncomingConfResult): Promise<Inco
const ourConvo = getConversationController().get(UserUtils.getOurPubKeyStrFromCache());
if (ourConvo) {
window.log.debug(`WIP: [userProfileWrapper] Checking for disappearing messages changes`);
let changes = false;
const expireTimer = ourConvo.get('expireTimer');
const wrapperNoteToSelfExpirySeconds = await UserConfigWrapperActions.getNoteToSelfExpiry();
// TODO Should use updateExpireTimer instead
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
ourConvo.set('expireTimer', wrapperNoteToSelfExpirySeconds);
@ -591,13 +591,6 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
continue;
}
window.log.debug(
`WIP: handleLegacyGroupUpdate for ${fromWrapper.pubkeyHex}legacyGroupConvo `,
legacyGroupConvo,
'fromWrapper',
fromWrapper
);
const members = fromWrapper.members.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
@ -619,8 +612,6 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
expireTimer: fromWrapper.disappearingTimerSeconds,
};
window.log.debug(`WIP: groupDetails for ${fromWrapper.pubkeyHex} `, groupDetails);
await ClosedGroup.updateOrCreateClosedGroup(groupDetails);
let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false);

@ -474,15 +474,17 @@ export async function innerHandleSwarmContentMessage(
if (isEmpty(content.dataMessage.profileKey)) {
content.dataMessage.profileKey = null;
}
window.log.debug(`WIP: innerHandleSwarmContentMessage: ${JSON.stringify(content)}`);
const expireUpdate = await checkForExpireUpdateInContentMessage(
content,
conversationModelForUIUpdate
);
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
@ -494,7 +496,7 @@ export async function innerHandleSwarmContentMessage(
);
if (expireUpdate.isLegacyConversationSettingMessage) {
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
)}}`
);

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

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

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

@ -218,7 +218,6 @@ export class MessageQueue {
}
const ourPubKey = UserUtils.getOurPubKeyStrFromCache();
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.
if (expirationMode !== 'off') {
window.log.debug(
`WIP: handleMessageSentSuccess ${fetchedMessage.idForLogging()} is deleteAfterRead`,
fetchedMessage
);
fetchedMessage.set({
expirationStartTimestamp: setExpirationStartTimestamp(
expirationMode,

@ -346,7 +346,7 @@ export function changeToDisappearingMessageConversationType(
expirationType?: DisappearingMessageType,
expireTimer?: number
): DisappearingMessageConversationType {
if (expirationType === 'unknown') {
if (!expirationType || expirationType === 'unknown') {
return expireTimer && expireTimer > 0 ? 'legacy' : 'off';
}
@ -359,10 +359,11 @@ export function changeToDisappearingMessageConversationType(
// 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
function checkIsLegacyDisappearingContentMessage(contentMessage: SignalService.Content): boolean {
function couldBeLegacyDisappearingMessageContent(contentMessage: SignalService.Content): boolean {
return (
(contentMessage.expirationType === SignalService.Content.ExpirationType.UNKNOWN ||
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType')) &&
(ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() &&
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationType'))) &&
!ProtobufUtils.hasDefinedProperty(contentMessage, 'expirationTimer')
);
}
@ -378,11 +379,6 @@ function checkDisappearButIsntMessage(
expirationMode: DisappearingMessageConversationType,
expirationTimer: number
): boolean {
window.log.debug(
`WIP: expirationMode ${expirationMode} expirationTimer ${expirationTimer} content ${JSON.stringify(
content
)} convo ${JSON.stringify(convo)}`
);
return (
content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
expirationMode === 'off' &&
@ -393,10 +389,13 @@ function checkDisappearButIsntMessage(
}
export function checkIsLegacyDisappearingDataMessage(
couldBeLegacyContent: boolean,
dataMessage: SignalService.DataMessage
): boolean {
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
const isDisappearingMessagesV2Released = await ReleasedFeatures.checkIsDisappearMessageV2FeatureReleased();
const isLegacyContentMessage = checkIsLegacyDisappearingContentMessage(content);
const isLegacyDataMessage = Boolean(
isLegacyContentMessage &&
checkIsLegacyDisappearingDataMessage(dataMessage as SignalService.DataMessage)
const couldBeLegacyContentMessage = couldBeLegacyDisappearingMessageContent(content);
const isLegacyDataMessage = checkIsLegacyDisappearingDataMessage(
couldBeLegacyContentMessage,
dataMessage as SignalService.DataMessage
);
const isLegacyConversationSettingMessage = isDisappearingMessagesV2Released
? isLegacyContentMessage &&
(isLegacyDataMessage || !content.lastDisappearingMessageChangeTimestamp) &&
? (isLegacyDataMessage ||
(couldBeLegacyContentMessage && !content.lastDisappearingMessageChangeTimestamp)) &&
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE
: isLegacyContentMessage &&
: couldBeLegacyContentMessage &&
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
? Number(dataMessage.expireTimer)
: 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(
convoToUpdate,
DisappearingMessageMode[content.expirationType],
expirationTimer
);
const lastDisappearingMessageChangeTimestamp = content.lastDisappearingMessageChangeTimestamp
? Number(content.lastDisappearingMessageChangeTimestamp)
: undefined;
const shouldDisappearButIsntMessage = checkDisappearButIsntMessage(
content,
convoToUpdate,
@ -456,7 +470,7 @@ export async function checkForExpireUpdateInContentMessage(
if (
!isDisappearingMessagesV2Released &&
!isLegacyConversationSettingMessage &&
isLegacyContentMessage &&
couldBeLegacyContentMessage &&
convoToUpdate.get('expirationType') !== 'off'
) {
if (
@ -464,9 +478,9 @@ export async function checkForExpireUpdateInContentMessage(
expirationTimer !== convoToUpdate.get('expireTimer')
) {
window.log.debug(
'WIP: Received a legacy disappearing message before v2 was released without values set. Using the conversation settings.',
content,
convoToUpdate
`WIP: Received a legacy disappearing message before v2 was released without values set. Using the conversation settings.\ncontent: ${JSON.stringify(
content
)}\nconvoToUpdate: ${JSON.stringify(convoToUpdate)}`
);
expireUpdate.expirationTimer = convoToUpdate.get('expireTimer');
@ -485,8 +499,9 @@ export async function checkForExpireUpdateInContentMessage(
(isLegacyDataMessage || isLegacyConversationSettingMessage || shouldDisappearButIsntMessage)
) {
window.log.debug(
'WIP: Received a legacy disappearing message after v2 was released. Overriding it with the conversation settings',
content
`WIP: Received a legacy disappearing message after v2 was released. Overriding it with the conversation settings\ncontent: ${JSON.stringify(
content
)}\nconvoToUpdate: ${JSON.stringify(convoToUpdate)}`
);
expireUpdate.expirationTimer = convoToUpdate.get('expireTimer');
@ -502,19 +517,19 @@ export async function checkForExpireUpdateInContentMessage(
}
// TODO legacy messages support will be removed in a future release
export function updateMessageModelToExpire(
converationModel: ConversationModel,
export function getMessageReadyToDisappear(
conversationModel: ConversationModel,
messageModel: MessageModel,
expireUpdate?: DisappearingMessageUpdate
) {
if (!expireUpdate) {
window.log.debug(`WIP: callced updateMessageModelToExpire() without expireUpdate`);
window.log.debug(`WIP: called getMessageReadyToDisappear() without an expireUpdate`);
return messageModel;
}
if (converationModel.isPublic()) {
if (conversationModel.isPublic()) {
window.log.warn(
"updateMessageModelToExpire() Disappearing messages aren't supported in communities"
"getMessageReadyToDisappear() Disappearing messages aren't supported in communities"
);
return messageModel;
}
@ -540,8 +555,8 @@ export function updateMessageModelToExpire(
expireTimer,
lastDisappearingMessageChangeTimestamp: isLegacyConversationSettingMessage
? isDisappearingMessagesV2Released
? converationModel.get('lastDisappearingMessageChangeTimestamp')
: Date.now()
? 0
: GetNetworkTime.getNowWithNetworkOffset()
: Number(lastDisappearingMessageChangeTimestamp),
source: messageModel.get('source'),
};

Loading…
Cancel
Save