feat: added function for calculating the expire start time

updated copy for setting change messages
pull/2660/head
William Grant 3 years ago
parent 8dc7dac55e
commit 13f091eff3

@ -179,9 +179,11 @@
"unblockToSend": "Unblock this contact to send a message.", "unblockToSend": "Unblock this contact to send a message.",
"unblockGroupToSend": "This group is blocked. Unlock it if you would like to send a message.", "unblockGroupToSend": "This group is blocked. Unlock it if you would like to send a message.",
"timer": "Timer", "timer": "Timer",
"youChangedTheTimer": "You set the disappearing message timer to $time$", "timerModeRead": "read",
"timerModeSent": "sent",
"youChangedTheTimer": "You have changed messages to disappear $time$ after they have been $mode$",
"timerSetOnSync": "Updated disappearing message timer to $time$", "timerSetOnSync": "Updated disappearing message timer to $time$",
"theyChangedTheTimer": "$name$ set the disappearing message timer to $time$", "theyChangedTheTimer": "$name$ has changed messages to disappear $time$ after they have been $mode$",
"timerOption_0_seconds": "Off", "timerOption_0_seconds": "Off",
"timerOption_5_seconds": "5 seconds", "timerOption_5_seconds": "5 seconds",
"timerOption_10_seconds": "10 seconds", "timerOption_10_seconds": "10 seconds",

@ -184,6 +184,7 @@ export function useMessageReactsPropsById(messageId?: string) {
}); });
} }
// TODO remove 10 seconds timer
export function useTimerOptionsByMode(disappearingMessageMode?: string) { export function useTimerOptionsByMode(disappearingMessageMode?: string) {
return useSelector((state: StateType) => { return useSelector((state: StateType) => {
let options = state.timerOptions.timerOptions; let options = state.timerOptions.timerOptions;
@ -192,6 +193,7 @@ export function useTimerOptionsByMode(disappearingMessageMode?: string) {
case 'deleteAfterSend': case 'deleteAfterSend':
return options.filter(option => { return options.filter(option => {
return ( return (
option.value === 10 || // 10 seconds (for testing)
option.value === 43200 || // 12 hours option.value === 43200 || // 12 hours
option.value === 86400 || // 1 day option.value === 86400 || // 1 day
option.value === 604800 || // 1 week option.value === 604800 || // 1 week
@ -201,6 +203,7 @@ export function useTimerOptionsByMode(disappearingMessageMode?: string) {
case 'deleteAfterRead': case 'deleteAfterRead':
return options.filter(option => { return options.filter(option => {
return ( return (
option.value === 10 || // 10 seconds (for testing)
option.value === 300 || // 5 minutes option.value === 300 || // 5 minutes
option.value === 3600 || // 1 hour option.value === 3600 || // 1 hour
option.value === 43200 || // 12 hours option.value === 43200 || // 12 hours

@ -1044,16 +1044,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
expireTimer = 0; expireTimer = 0;
} }
if (this.get('expireTimer') === expireTimer || (!expireTimer && !this.get('expireTimer'))) {
window.log.info(`WIP: This disappearing message setting is invalid`, {
id: this.idForLogging(),
expirationType,
expireTimer,
source,
});
return;
}
const isOutgoing = Boolean(!receivedAt); const isOutgoing = Boolean(!receivedAt);
source = source || UserUtils.getOurPubKeyStrFromCache(); source = source || UserUtils.getOurPubKeyStrFromCache();
@ -1314,6 +1304,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
hasErrors: Boolean(errors && errors.length), hasErrors: Boolean(errors && errors.length),
}); });
} }
const oldUnreadNowReadAttrs = oldUnreadNowRead.map(m => m.attributes); const oldUnreadNowReadAttrs = oldUnreadNowRead.map(m => m.attributes);
if (oldUnreadNowReadAttrs?.length) { if (oldUnreadNowReadAttrs?.length) {
await Data.saveMessages(oldUnreadNowReadAttrs); await Data.saveMessages(oldUnreadNowReadAttrs);

@ -35,8 +35,6 @@ export function createSwarmMessageSentFromUs(args: {
const messageData: MessageAttributesOptionals = { const messageData: MessageAttributesOptionals = {
...getSharedAttributesForSwarmMessage(args), ...getSharedAttributesForSwarmMessage(args),
...getSharedAttributesForOutgoingMessage(), ...getSharedAttributesForOutgoingMessage(),
// TODO need to update this for delete after read
expirationStartTimestamp: Math.min(args.sentAt, Date.now()),
}; };
return new MessageModel(messageData); return new MessageModel(messageData);
@ -80,6 +78,7 @@ function getSharedAttributesForPublicMessage({
isPublic: true, isPublic: true,
conversationId, conversationId,
messageHash: '', // we do not care of a messageHash for an opengroup message. we have serverId for that messageHash: '', // we do not care of a messageHash for an opengroup message. we have serverId for that
// TODO do we need to worry about this?
expirationStartTimestamp: undefined, expirationStartTimestamp: undefined,
}; };
} }

@ -16,7 +16,10 @@ import {
ConversationTypeEnum, ConversationTypeEnum,
} from '../../models/conversationAttributes'; } from '../../models/conversationAttributes';
import { ReactionList } from '../../types/Reaction'; import { ReactionList } from '../../types/Reaction';
import { DisappearingMessageConversationType } from '../../util/expiringMessages'; import {
DisappearingMessageConversationType,
DisappearingMessageType,
} from '../../util/expiringMessages';
export type CallNotificationType = 'missed-call' | 'started-call' | 'answered-a-call'; export type CallNotificationType = 'missed-call' | 'started-call' | 'answered-a-call';
export type PropsForCallNotification = { export type PropsForCallNotification = {
@ -72,8 +75,8 @@ export type FindAndFormatContactType = {
isMe: boolean; isMe: boolean;
}; };
// TODO Should this be updated?
export type PropsForExpirationTimer = { export type PropsForExpirationTimer = {
expirationType: DisappearingMessageConversationType;
timespan: string; timespan: string;
disabled: boolean; disabled: boolean;
pubkey: string; pubkey: string;
@ -194,6 +197,7 @@ export type PropsForMessageWithoutConvoProps = {
messageHash?: string; messageHash?: string;
isDeleted?: boolean; isDeleted?: boolean;
isUnread?: boolean; isUnread?: boolean;
expirationType?: DisappearingMessageType;
expirationLength?: number; expirationLength?: number;
expirationTimestamp?: number | null; expirationTimestamp?: number | null;
isExpired?: boolean; isExpired?: boolean;

@ -1148,6 +1148,7 @@ export const getGenericReadableMessageSelectorProps = createSelector(
'convoId', 'convoId',
'direction', 'direction',
'conversationType', 'conversationType',
'expirationType',
'expirationLength', 'expirationLength',
'expirationTimestamp', 'expirationTimestamp',
'isExpired', 'isExpired',

@ -179,6 +179,8 @@ export type LocalizerKeys =
| 'unblockToSend' | 'unblockToSend'
| 'unblockGroupToSend' | 'unblockGroupToSend'
| 'timer' | 'timer'
| 'timerModeRead'
| 'timerModeSent'
| 'youChangedTheTimer' | 'youChangedTheTimer'
| 'timerSetOnSync' | 'timerSetOnSync'
| 'theyChangedTheTimer' | 'theyChangedTheTimer'

Loading…
Cancel
Save