refactor: rename expirationType on convo to expirationMode

this means convo has expirationMode and messages have expirationType
pull/2971/head
William Grant 2 years ago
parent cd2f51684d
commit 250e3d0238

@ -10,13 +10,13 @@ import { Flex } from '../basic/Flex';
import { isLegacyDisappearingModeEnabled } from '../../util/expiringMessages';
export const TimerNotification = (props: PropsForExpirationTimer) => {
const { messageId, pubkey, profileName, expirationType, timespan, type, disabled } = props;
const { messageId, pubkey, profileName, expirationMode, timespan, type, disabled } = props;
const contact = profileName || pubkey;
// TODO legacy messages support will be removed in a future release
const mode = isLegacyDisappearingModeEnabled(expirationType)
const mode = isLegacyDisappearingModeEnabled(expirationMode)
? null
: expirationType === 'deleteAfterRead'
: expirationMode === 'deleteAfterRead'
? window.i18n('timerModeRead')
: window.i18n('timerModeSent');

@ -46,7 +46,7 @@ export const ConversationHeaderTitle = () => {
const isGroup = useSelectedIsGroup();
const members = useSelectedMembers();
const expirationType = useSelectedConversationExpirationType();
const expirationMode = useSelectedConversationExpirationType();
const expireTimer = useSelectedExpireTimer();
const convoName = useConversationUsername(selectedConvoKey);
@ -87,11 +87,11 @@ export const ConversationHeaderTitle = () => {
// NOTE If disappearing messages is defined we must show it first
const disappearingMessageSubtitle = useMemo(() => {
const disappearingMessageSettingText =
expirationType === 'deleteAfterRead'
expirationMode === 'deleteAfterRead'
? window.i18n('disappearingMessagesModeAfterRead')
: expirationType === 'deleteAfterSend'
: expirationMode === 'deleteAfterSend'
? window.i18n('disappearingMessagesModeAfterSend')
: expirationType === 'legacy'
: expirationMode === 'legacy'
? isMe || (isGroup && !isPublic)
? window.i18n('disappearingMessagesModeAfterSend')
: window.i18n('disappearingMessagesModeAfterRead')
@ -106,7 +106,7 @@ export const ConversationHeaderTitle = () => {
abbreviatedExpireTime ? ` - ${abbreviatedExpireTime}` : ''
}`
: null;
}, [expirationType, expireTimer, isGroup, isMe, isPublic]);
}, [expirationMode, expireTimer, isGroup, isMe, isPublic]);
const handleRightPanelToggle = () => {
if (isRightPanelOn) {
@ -190,7 +190,7 @@ export const ConversationHeaderTitle = () => {
subtitleStrings={subtitleStrings}
onClickFunction={handleRightPanelToggle}
showDisappearingMessageIcon={
visibleSubtitle === 'disappearingMessages' && expirationType !== 'off'
visibleSubtitle === 'disappearingMessages' && expirationMode !== 'off'
}
/>
)}

@ -63,7 +63,7 @@ function loadDefaultTimeValue(modeSelected: DisappearingMessageConversationModeT
}
export type PropsForExpirationSettings = {
expirationType: DisappearingMessageConversationModeType | undefined;
expirationMode: DisappearingMessageConversationModeType | undefined;
expireTimer: number | undefined;
isGroup: boolean | undefined;
weAreAdmin: boolean | undefined;
@ -84,13 +84,13 @@ export const OverlayDisappearingMessages = () => {
const hasOnlyOneMode = Boolean(singleMode && singleMode.length > 0);
const isGroup = useSelectedIsGroup();
const expirationType = useSelectedConversationExpirationType();
const expirationMode = useSelectedConversationExpirationType();
const expireTimer = useSelectedExpireTimer();
const weAreAdmin = useSelectedWeAreAdmin();
const [modeSelected, setModeSelected] = useState<
DisappearingMessageConversationModeType | undefined
>(hasOnlyOneMode ? singleMode : expirationType);
>(hasOnlyOneMode ? singleMode : expirationMode);
const [timeSelected, setTimeSelected] = useState(expireTimer || 0);
const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode);
@ -122,12 +122,12 @@ export const OverlayDisappearingMessages = () => {
useEffect(() => {
if (!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()) {
setModeSelected(
expirationType === 'deleteAfterRead' || expirationType === 'deleteAfterSend'
expirationMode === 'deleteAfterRead' || expirationMode === 'deleteAfterSend'
? 'legacy'
: expirationType
: expirationMode
);
}
}, [expirationType]);
}, [expirationMode]);
useEffect(() => {
// NOTE loads a time value from the conversation model or the default

@ -367,7 +367,7 @@ export function deleteAllMessagesByConvoIdWithConfirmation(conversationId: strin
export async function setDisappearingMessagesByConvoId(
conversationId: string,
expirationType: DisappearingMessageConversationModeType,
expirationMode: DisappearingMessageConversationModeType,
seconds?: number
) {
const conversation = getConversationController().get(conversationId);
@ -381,7 +381,7 @@ export async function setDisappearingMessagesByConvoId(
const providedChangeTimestamp = GetNetworkTime.getNowWithNetworkOffset();
if (!expirationType || expirationType === 'off' || !seconds || seconds <= 0) {
if (!expirationMode || expirationMode === 'off' || !seconds || seconds <= 0) {
await conversation.updateExpireTimer({
providedExpirationType: 'off',
providedExpireTimer: 0,
@ -389,7 +389,7 @@ export async function setDisappearingMessagesByConvoId(
});
} else {
await conversation.updateExpireTimer({
providedExpirationType: expirationType,
providedExpirationType: expirationMode,
providedExpireTimer: seconds,
providedChangeTimestamp,
});

@ -327,8 +327,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
toRet.avatarPath = avatarPath;
}
if (this.get('expirationType')) {
toRet.expirationType = this.get('expirationType');
if (this.get('expirationMode')) {
toRet.expirationMode = this.get('expirationMode');
}
if (this.get('lastDisappearingMessageChangeTimestamp')) {
@ -757,7 +757,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expirationType: changeToDisappearingMessageType(
this,
this.get('expireTimer'),
this.get('expirationType')
this.get('expirationMode')
),
expireTimer: this.get('expireTimer'),
serverTimestamp: this.isPublic() ? networkTimestamp : undefined,
@ -824,13 +824,13 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
window.log.warn("updateExpireTimer() Disappearing messages aren't supported in communities");
return;
}
let expirationType = providedExpirationType;
let expirationMode = providedExpirationType;
let expireTimer = providedExpireTimer;
const lastDisappearingMessageChangeTimestamp = providedChangeTimestamp;
const source = providedSource || UserUtils.getOurPubKeyStrFromCache();
if (expirationType === undefined || expireTimer === undefined) {
expirationType = 'off';
if (expirationMode === undefined || expireTimer === undefined) {
expirationMode = 'off';
expireTimer = 0;
}
@ -849,7 +849,7 @@ 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 (
isEqual(expirationType, this.get('expirationType')) &&
isEqual(expirationMode, this.get('expirationMode')) &&
isEqual(expireTimer, this.get('expireTimer'))
) {
window.log.info(
@ -867,7 +867,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const timestamp = (receivedAt || Date.now()) - 1;
this.set({
expirationType,
expirationMode,
expireTimer,
lastDisappearingMessageChangeTimestamp,
});
@ -876,7 +876,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
'WIP: updateExpireTimer() Updating conversation disappearing messages setting',
{
id: this.idForLogging(),
expirationType,
expirationMode,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
@ -884,24 +884,20 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
);
let message: MessageModel | undefined = existingMessage || undefined;
const messageExpirationType = changeToDisappearingMessageType(
this,
expireTimer,
expirationType
);
const expirationType = changeToDisappearingMessageType(this, expireTimer, expirationMode);
// 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
const commonAttributes = {
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: {
expirationType: messageExpirationType,
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
expirationType: messageExpirationType,
expirationType,
expireTimer,
};
@ -944,7 +940,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const expireUpdate = {
identifier: message?.id,
timestamp,
expirationType: messageExpirationType,
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
};
@ -2341,11 +2337,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
private isDisappearingMode(mode: DisappearingMessageConversationModeType) {
const success =
mode === 'deleteAfterRead'
? this.get('expirationType') === 'deleteAfterRead'
? this.get('expirationMode') === 'deleteAfterRead'
: mode === 'deleteAfterSend'
? this.get('expirationType') === 'deleteAfterSend'
? this.get('expirationMode') === 'deleteAfterSend'
: mode === 'off'
? this.get('expirationType') === 'off'
? this.get('expirationMode') === 'off'
: false;
return success;

@ -105,7 +105,7 @@ export interface ConversationAttributes {
blocksSogsMsgReqsTimestamp: number; // if the convo is blinded and the user has denied contact through sogs, this field be set to the user's latest message timestamp
expirationType: DisappearingMessageConversationModeType; // disappearing messages setting for this conversation
expirationMode: DisappearingMessageConversationModeType; // disappearing messages setting for this conversation
lastDisappearingMessageChangeTimestamp: number; // to avoid applying a change of disappear change when our current one was applied more recently
hasOutdatedClient?: string; // to warn the user that the person he is talking to is using an old client which might cause issues
}
@ -125,7 +125,7 @@ export const fillConvoAttributesWithDefaults = (
groupAdmins: [],
lastJoinedTimestamp: 0,
expirationType: 'off',
expirationMode: 'off',
expireTimer: 0,
lastDisappearingMessageChangeTimestamp: 0,

@ -267,13 +267,13 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return '';
}
const expirationType = changeToDisappearingMessageConversationType(
const expirationMode = changeToDisappearingMessageConversationType(
convo,
expireTimerUpdate?.expirationType,
expireTimer
);
if (!expireTimerUpdate || expirationType === 'off' || !expireTimer || expireTimer === 0) {
if (!expireTimerUpdate || expirationMode === 'off' || !expireTimer || expireTimer === 0) {
return window.i18n('disappearingMessagesDisabled');
}
@ -334,7 +334,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}
const { expireTimer, fromSync, source } = timerUpdate;
const expirationType = changeToDisappearingMessageConversationType(
const expirationMode = changeToDisappearingMessageConversationType(
convo,
timerUpdate?.expirationType || 'unknown',
expireTimer || 0
@ -350,7 +350,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
type: fromSync ? 'fromSync' : UserUtils.isUsFromCache(source) ? 'fromMe' : 'fromOther',
receivedAt: this.get('received_at'),
isUnread: this.isUnread(),
expirationType: expirationType || 'off',
expirationMode: expirationMode || 'off',
...this.getPropsForExpiringMessage(),
};
@ -1119,7 +1119,8 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (expirationMode === 'legacy' || expirationMode === 'deleteAfterRead') {
if (this.isIncoming() && !this.isExpiring()) {
await updateMessageExpiryOnSwarm(this, 'markMessageReadNoCommit()', true);
// NOTE We want to trigger disappearing now and then the TTL can update itself while it is running. Otherwise the UI is blocked until the request is completed.
void updateMessageExpiryOnSwarm(this, 'markMessageReadNoCommit()', true);
}
this.set({

@ -74,7 +74,7 @@ const allowedKeysFormatRowOfConversation = [
'markedAsUnread',
'blocksSogsMsgReqsTimestamp',
'priority',
'expirationType',
'expirationMode',
'lastDisappearingMessageChangeTimestamp',
'hasOutdatedClient',
];
@ -199,7 +199,7 @@ const allowedKeysOfConversationAttributes = [
'markedAsUnread',
'blocksSogsMsgReqsTimestamp',
'priority',
'expirationType',
'expirationMode',
'lastDisappearingMessageChangeTimestamp',
'hasOutdatedClient',
];

@ -3,7 +3,7 @@ import * as BetterSqlite3 from '@signalapp/better-sqlite3';
import {
ContactInfoSet,
ContactsConfigWrapperNode,
DisappearingMessageConversationType,
DisappearingMessageConversationModeType,
LegacyGroupInfo,
LegacyGroupMemberInfo,
UserGroupsWrapperNode,
@ -86,7 +86,7 @@ function getContactInfoFromDBValues({
dbProfileUrl,
dbProfileKey,
dbCreatedAtSeconds,
expirationType,
expirationMode,
expireTimer,
}: {
id: string;
@ -99,7 +99,7 @@ function getContactInfoFromDBValues({
dbProfileUrl: string | undefined;
dbProfileKey: string | undefined;
dbCreatedAtSeconds: number;
expirationType: string | undefined;
expirationMode: string | undefined;
expireTimer: number | undefined;
}): ContactInfoSet {
const wrapperContact: ContactInfoSet = {
@ -111,8 +111,8 @@ function getContactInfoFromDBValues({
nickname: dbNickname,
name: dbName,
createdAtSeconds: dbCreatedAtSeconds,
expirationMode: expirationType
? (expirationType as DisappearingMessageConversationType)
expirationMode: expirationMode
? (expirationMode as DisappearingMessageConversationModeType)
: undefined,
expirationTimerSeconds: !!expireTimer && expireTimer > 0 ? expireTimer : 0,
};
@ -155,7 +155,7 @@ function updateContactInContactWrapper(
dbProfileUrl: contact.avatarPointer || undefined,
priority,
dbCreatedAtSeconds: Math.floor((contact.active_at || Date.now()) / 1000),
expirationType: contact.expirationType || 'off',
expirationMode: contact.expirationMode || 'off',
// TODO rename expireTimer to expirationTimer
expireTimer: contact.expireTimer || 0,
});
@ -183,7 +183,7 @@ function updateContactInContactWrapper(
dbProfileUrl: undefined,
priority: CONVERSATION_PRIORITIES.default,
dbCreatedAtSeconds: Math.floor(Date.now() / 1000),
expirationType: 'off',
expirationMode: 'off',
expireTimer: 0,
})
);
@ -202,7 +202,7 @@ function getLegacyGroupInfoFromDBValues({
priority,
members: maybeMembers,
displayNameInProfile,
expirationType,
expirationMode,
expireTimer,
encPubkeyHex,
encSeckeyHex,
@ -212,7 +212,7 @@ function getLegacyGroupInfoFromDBValues({
id: string;
priority: number;
displayNameInProfile: string | undefined;
expirationType: string | undefined;
expirationMode: string | undefined;
expireTimer: number | undefined;
encPubkeyHex: string;
encSeckeyHex: string;
@ -232,8 +232,8 @@ function getLegacyGroupInfoFromDBValues({
const legacyGroup: LegacyGroupInfo = {
pubkeyHex: id,
disappearingTimerSeconds:
expirationType &&
(expirationType as DisappearingMessageConversationType) !== 'off' &&
expirationMode &&
(expirationMode as DisappearingMessageConversationModeType) !== 'off' &&
!!expireTimer &&
expireTimer > 0
? expireTimer
@ -268,7 +268,7 @@ function updateLegacyGroupInWrapper(
const wrapperLegacyGroup = getLegacyGroupInfoFromDBValues({
id: legacyGroup.id,
priority,
expirationType: legacyGroup.expirationType || 'off',
expirationMode: legacyGroup.expirationMode || 'off',
expireTimer: legacyGroup.expireTimer || 0,
groupAdmins: legacyGroup.groupAdmins || [],
members: legacyGroup.members || [],

@ -1670,7 +1670,7 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite
// region v34 Disappearing Messages Database Model Changes
// Conversation changes
db.prepare(
`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationType TEXT DEFAULT "off";`
`ALTER TABLE ${CONVERSATIONS_TABLE} ADD COLUMN expirationMode TEXT DEFAULT "off";`
).run();
db.prepare(
@ -1696,10 +1696,10 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite
const noteToSelfInfo = db
.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType
expirationMode = $expirationMode
WHERE id = $id AND type = 'private' AND expireTimer > 0;`
)
.run({ expirationType: 'deleteAfterSend', id: publicKeyHex });
.run({ expirationMode: 'deleteAfterSend', id: publicKeyHex });
if (noteToSelfInfo.changes) {
const ourConversation = db
@ -1747,16 +1747,16 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite
const privateConversationsInfo = db
.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType
WHERE type = 'private' AND expirationType = 'off' AND expireTimer > 0;`
expirationMode = $expirationMode
WHERE type = 'private' AND expirationMode = 'off' AND expireTimer > 0;`
)
.run({ expirationType: 'deleteAfterRead' });
.run({ expirationMode: 'deleteAfterRead' });
if (privateConversationsInfo.changes) {
// this filter is based on the `isContactToStoreInWrapper` function. Note, it has been expanded to check if disappearing messages is on
const contactsToUpdateInWrapper = db
.prepare(
`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE type = 'private' AND active_at > 0 AND priority <> ${CONVERSATION_PRIORITIES.hidden} AND (didApproveMe OR isApproved) AND id <> '$us' AND id NOT LIKE '15%' AND id NOT LIKE '25%' AND expirationType = 'deleteAfterRead' AND expireTimer > 0;`
`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE type = 'private' AND active_at > 0 AND priority <> ${CONVERSATION_PRIORITIES.hidden} AND (didApproveMe OR isApproved) AND id <> '$us' AND id NOT LIKE '15%' AND id NOT LIKE '25%' AND expirationMode = 'deleteAfterRead' AND expireTimer > 0;`
)
.all({
us: publicKeyHex,
@ -1823,16 +1823,16 @@ function updateToSessionSchemaVersion34(currentVersion: number, db: BetterSqlite
const groupConversationsInfo = db
.prepare(
`UPDATE ${CONVERSATIONS_TABLE} SET
expirationType = $expirationType
WHERE type = 'group' AND id LIKE '05%' AND expirationType = 'off' AND expireTimer > 0;`
expirationMode = $expirationMode
WHERE type = 'group' AND id LIKE '05%' AND expirationMode = 'off' AND expireTimer > 0;`
)
.run({ expirationType: 'deleteAfterSend' });
.run({ expirationMode: 'deleteAfterSend' });
if (groupConversationsInfo.changes) {
// this filter is based on the `isLegacyGroupToStoreInWrapper` function. Note, it has been expanded to check if disappearing messages is on
const legacyGroupsToWriteInWrapper = db
.prepare(
`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE type = 'group' AND active_at > 0 AND id LIKE '05%' AND NOT isKickedFromGroup AND NOT left AND expirationType = 'deleteAfterSend' AND expireTimer > 0;`
`SELECT * FROM ${CONVERSATIONS_TABLE} WHERE type = 'group' AND active_at > 0 AND id LIKE '05%' AND NOT isKickedFromGroup AND NOT left AND expirationMode = 'deleteAfterSend' AND expireTimer > 0;`
)
.all({});

@ -425,7 +425,7 @@ function saveConversation(data: ConversationAttributes): SaveConversationReturn
profileKey,
zombies,
left,
expirationType,
expirationMode,
// TODO rename expireTimer to expirationTimer
expireTimer,
lastDisappearingMessageChangeTimestamp,
@ -478,7 +478,7 @@ function saveConversation(data: ConversationAttributes): SaveConversationReturn
profileKey,
zombies: zombies && zombies.length ? arrayStrToJson(zombies) : '[]',
left: toSqliteBoolean(left),
expirationType,
expirationMode,
expireTimer,
lastDisappearingMessageChangeTimestamp,
hasOutdatedClient,

@ -384,7 +384,7 @@ async function handleContactsUpdate(result: IncomingConfResult): Promise<Incomin
if (
wrapperConvo.expirationTimerSeconds !== contactConvo.get('expireTimer') ||
wrapperConvo.expirationMode !== contactConvo.get('expirationType')
wrapperConvo.expirationMode !== contactConvo.get('expirationMode')
) {
await contactConvo.updateExpireTimer({
providedExpirationType: wrapperConvo.expirationMode,
@ -694,8 +694,8 @@ async function applyConvoVolatileUpdateFromWrapper(
// TODO legacy messages support will be removed in a future release
if (
canBeDeleteAfterRead &&
(foundConvo.get('expirationType') === 'deleteAfterRead' ||
foundConvo.get('expirationType') === 'legacy') &&
(foundConvo.get('expirationMode') === 'deleteAfterRead' ||
foundConvo.get('expirationMode') === 'legacy') &&
foundConvo.get('expireTimer') > 0
) {
const messages2Expire = await Data.getUnreadByConversation(convoId, lastReadMessageTimestamp);

@ -872,14 +872,14 @@ export async function handleDataExtractionNotification(
const envelopeTimestamp = toNumber(timestamp);
const referencedAttachmentTimestamp = toNumber(referencedAttachment);
const expirationMode = convo.get('expirationType');
const expirationMode = convo.get('expirationMode');
const expireTimer = convo.get('expireTimer');
let expirationType;
let expirationStartTimestamp;
if (convo && expirationMode && expireTimer > 0) {
expirationType =
expirationType !== 'off'
expirationMode !== 'off'
? changeToDisappearingMessageType(convo, expireTimer, expirationMode)
: undefined;

@ -75,7 +75,7 @@ export async function initiateClosedGroupUpdate(
const expirationType = changeToDisappearingMessageType(
convo,
convo.get('expireTimer'),
convo.get('expirationType')
convo.get('expirationMode')
);
if (expirationType === 'deleteAfterRead') {
@ -173,7 +173,7 @@ export async function addUpdateMessage(
groupUpdate.kicked = diff.kickedMembers;
}
const expirationMode = convo.get('expirationType');
const expirationMode = convo.get('expirationMode');
const expireTimer = convo.get('expireTimer');
let expirationType;
let expirationStartTimestamp;
@ -316,7 +316,7 @@ async function sendAddedMembers(
}
const encryptionKeyPair = ECKeyPair.fromHexKeyPair(hexEncryptionKeyPair);
const expirationMode = convo.get('expirationType') || 'off';
const expirationMode = convo.get('expirationMode') || 'off';
const existingExpireTimer = convo.get('expireTimer') || 0;
// Send the Added Members message to the group (only members already in the group will get it)
const closedGroupControlMessage = new ClosedGroupAddedMembersMessage({

@ -516,7 +516,7 @@ export async function USER_callRecipient(recipient: string) {
await calledConvo.unhideIfNeeded(false);
weAreCallerOnCurrentCall = true;
const expirationMode = calledConvo.get('expirationType');
const expirationMode = calledConvo.get('expirationMode');
const expireTimer = calledConvo.get('expireTimer') || 0;
let expirationType;
let expirationStartTimestamp;
@ -901,7 +901,7 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
callerConvo.set('active_at', networkTimestamp);
await callerConvo.unhideIfNeeded(false);
const expirationMode = callerConvo.get('expirationType');
const expirationMode = callerConvo.get('expirationMode');
const expireTimer = callerConvo.get('expireTimer') || 0;
let expirationType;
let expirationStartTimestamp;
@ -1258,7 +1258,7 @@ async function addMissedCallMessage(callerPubkey: string, sentAt: number) {
await incomingCallConversation.unhideIfNeeded(false);
}
const expirationMode = incomingCallConversation.get('expirationType');
const expirationMode = incomingCallConversation.get('expirationMode');
const expireTimer = incomingCallConversation.get('expireTimer') || 0;
let expirationType;
let expirationStartTimestamp;

@ -54,7 +54,7 @@ async function insertContactFromDBIntoWrapperAndRefresh(id: string): Promise<voi
const dbApprovedMe = !!foundConvo.get('didApproveMe') || false;
const dbBlocked = !!foundConvo.isBlocked() || false;
const priority = foundConvo.get('priority') || 0;
const expirationType = foundConvo.get('expirationType') || undefined;
const expirationMode = foundConvo.get('expirationMode') || undefined;
const expireTimer = foundConvo.get('expireTimer') || 0;
const wrapperContact = getContactInfoFromDBValues({
@ -68,7 +68,7 @@ async function insertContactFromDBIntoWrapperAndRefresh(id: string): Promise<voi
dbProfileUrl,
priority,
dbCreatedAtSeconds: 0, // just give 0, now() will be used internally by the wrapper if the contact does not exist yet.
expirationType,
expirationMode,
expireTimer,
});
try {

@ -116,7 +116,7 @@ async function insertGroupsFromDBIntoWrapperAndRefresh(convoId: string): Promise
priority: foundConvo.get('priority'),
members: foundConvo.get('members') || [],
groupAdmins: foundConvo.get('groupAdmins') || [],
expirationType: foundConvo.get('expirationType') || 'off',
expirationMode: foundConvo.get('expirationMode') || 'off',
expireTimer: foundConvo.get('expireTimer') || 0,
displayNameInProfile: foundConvo.get('displayNameInProfile'),
encPubkeyHex: encryptionKeyPair?.publicHex || '',

@ -86,7 +86,7 @@ export type PropsForExpiringMessage = {
};
export type PropsForExpirationTimer = {
expirationType: DisappearingMessageConversationModeType;
expirationMode: DisappearingMessageConversationModeType;
timespan: string;
disabled: boolean;
pubkey: string;
@ -247,7 +247,7 @@ export interface ReduxConversationType {
weAreAdmin?: boolean;
unreadCount?: number;
mentionedUs?: boolean;
expirationType?: DisappearingMessageConversationModeType;
expirationMode?: DisappearingMessageConversationModeType;
expireTimer?: number;
lastDisappearingMessageChangeTimestamp?: number;
hasOutdatedClient?: string;

@ -315,7 +315,7 @@ export function useSelectedExpireTimer(): number | undefined {
export function useSelectedConversationExpirationType():
| DisappearingMessageConversationModeType
| undefined {
return useSelector((state: StateType) => getSelectedConversation(state)?.expirationType);
return useSelector((state: StateType) => getSelectedConversation(state)?.expirationMode);
}
export function useSelectedIsLeft() {

@ -3,7 +3,7 @@
// eslint-disable-next-line camelcase
import {
ContactInfoSet,
DisappearingMessageConversationType,
DisappearingMessageConversationModeType,
LegacyGroupInfo,
LegacyGroupMemberInfo,
} from 'libsession_util_nodejs';
@ -125,7 +125,7 @@ export function getContactInfoFromDBValues({
dbProfileUrl,
dbProfileKey,
dbCreatedAtSeconds,
expirationType,
expirationMode,
expireTimer,
}: {
id: string;
@ -138,7 +138,7 @@ export function getContactInfoFromDBValues({
dbProfileUrl: string | undefined;
dbProfileKey: string | undefined;
dbCreatedAtSeconds: number;
expirationType: string | undefined;
expirationMode: string | undefined;
expireTimer: number | undefined;
}): ContactInfoSet {
const wrapperContact: ContactInfoSet = {
@ -150,8 +150,8 @@ export function getContactInfoFromDBValues({
nickname: dbNickname,
name: dbName,
createdAtSeconds: dbCreatedAtSeconds,
expirationMode: expirationType
? (expirationType as DisappearingMessageConversationType)
expirationMode: expirationMode
? (expirationMode as DisappearingMessageConversationModeType)
: undefined,
expirationTimerSeconds: !!expireTimer && expireTimer > 0 ? expireTimer : 0,
};
@ -214,7 +214,7 @@ export function getLegacyGroupInfoFromDBValues({
priority,
members: maybeMembers,
displayNameInProfile,
expirationType,
expirationMode,
expireTimer,
encPubkeyHex,
encSeckeyHex,
@ -224,7 +224,7 @@ export function getLegacyGroupInfoFromDBValues({
id: string;
priority: number;
displayNameInProfile: string | undefined;
expirationType: string | undefined;
expirationMode: string | undefined;
expireTimer: number | undefined;
encPubkeyHex: string;
encSeckeyHex: string;
@ -245,8 +245,8 @@ export function getLegacyGroupInfoFromDBValues({
const legacyGroup: LegacyGroupInfo = {
pubkeyHex: id,
disappearingTimerSeconds:
expirationType &&
(expirationType as DisappearingMessageConversationType) !== 'off' &&
expirationMode &&
(expirationMode as DisappearingMessageConversationModeType) !== 'off' &&
!!expireTimer &&
expireTimer > 0
? expireTimer

@ -301,11 +301,11 @@ export function setExpirationStartTimestamp(
// TODO legacy messages support will be removed in a future release
export function isLegacyDisappearingModeEnabled(
expirationType: DisappearingMessageConversationModeType | DisappearingMessageType | undefined
expirationMode: DisappearingMessageConversationModeType | undefined
): boolean {
return Boolean(
expirationType &&
expirationType !== 'off' &&
expirationMode &&
expirationMode !== 'off' &&
!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()
);
}
@ -317,15 +317,15 @@ export function isLegacyDisappearingModeEnabled(
* NOTE Used for sending or receiving data messages (protobuf)
*
* @param convo Conversation we want to set
* @param expirationType DisappearingMessageConversationType
* @param expirationMode DisappearingMessageConversationModeType
* @returns Disappearing mode we should use
*/
export function changeToDisappearingMessageType(
convo: ConversationModel,
expireTimer: number,
expirationType?: DisappearingMessageConversationModeType
expirationMode?: DisappearingMessageConversationModeType
): DisappearingMessageType {
if (expirationType === 'off' || expirationType === 'legacy') {
if (expirationMode === 'off' || expirationMode === 'legacy') {
// NOTE we would want this to be undefined but because of an issue with the protobuf implement we need to have a value
return 'unknown';
}
@ -335,7 +335,7 @@ export function changeToDisappearingMessageType(
return 'deleteAfterSend';
}
return expirationType === 'deleteAfterSend' ? 'deleteAfterSend' : 'deleteAfterRead';
return expirationMode === 'deleteAfterSend' ? 'deleteAfterSend' : 'deleteAfterRead';
}
return 'unknown';
@ -394,7 +394,7 @@ function checkDisappearButIsntMessage(
content.dataMessage?.flags !== SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE &&
expirationMode === 'off' &&
expirationTimer === 0 &&
convo.get('expirationType') !== 'off' &&
convo.get('expirationMode') !== 'off' &&
convo.get('expireTimer') !== 0
);
}
@ -501,10 +501,10 @@ export async function checkForExpireUpdateInContentMessage(
!isDisappearingMessagesV2Released &&
!isLegacyConversationSettingMessage &&
couldBeLegacyContentMessage &&
convoToUpdate.get('expirationType') !== 'off'
convoToUpdate.get('expirationMode') !== 'off'
) {
if (
expirationMode !== convoToUpdate.get('expirationType') ||
expirationMode !== convoToUpdate.get('expirationMode') ||
expirationTimer !== convoToUpdate.get('expireTimer')
) {
window.log.debug(
@ -517,7 +517,7 @@ export async function checkForExpireUpdateInContentMessage(
expireUpdate.expirationType = changeToDisappearingMessageType(
convoToUpdate,
expireUpdate.expirationTimer,
convoToUpdate.get('expirationType')
convoToUpdate.get('expirationMode')
);
expireUpdate.isLegacyDataMessage = true;
}
@ -538,7 +538,7 @@ export async function checkForExpireUpdateInContentMessage(
expireUpdate.expirationType = changeToDisappearingMessageType(
convoToUpdate,
expireUpdate.expirationTimer,
convoToUpdate.get('expirationType')
convoToUpdate.get('expirationMode')
);
expireUpdate.isLegacyDataMessage = true;
}
@ -645,11 +645,17 @@ export async function updateMessageExpiryOnSwarm(
if (callLocation) {
window.log.debug(`WIP: [updateMessageExpiryOnSwarm] called from: ${callLocation} `);
}
// window.log.debug(`WIP: [updateMessageExpiryOnSwarm]\nmessage: ${JSON.stringify(message)}`);
const messageHash = message.get('messageHash');
const expiresAt = message.get('expires_at');
if (!message.get('expirationType') || !message.get('expireTimer')) {
window.log.debug(
`WIP: [updateMessageExpiryOnSwarm] Message ${message.get(
'messageHash'
)} has no expirationType or expireTimer set. Ignoring`
);
return message;
}
const messageHash = message.get('messageHash');
if (!messageHash) {
window.log.debug(
`WIP: [updateMessageExpiryOnSwarm] Missing messageHash message: ${JSON.stringify(message)}`
@ -657,11 +663,14 @@ export async function updateMessageExpiryOnSwarm(
return message;
}
// window.log.debug(`WIP: [updateMessageExpiryOnSwarm]\nmessage: ${JSON.stringify(message)}`);
const newTTL = await expireMessageOnSnode({
messageHash,
expireTimer: message.get('expireTimer') * 1000,
shorten: true,
});
const expiresAt = message.get('expires_at');
if (newTTL && newTTL !== expiresAt) {
message.set({

Loading…
Cancel
Save