refactor: disappearingmessageconversationtype to disappearingmessageconversationmodetype

pull/2971/head
William Grant 2 years ago
parent c7f8f4f635
commit cd2f51684d

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { DisappearingMessageConversationType } from '../../../../../util/expiringMessages'; import { DisappearingMessageConversationModeType } from '../../../../../util/expiringMessages';
import { PanelButtonGroup, PanelLabel } from '../../../../buttons/PanelButton'; import { PanelButtonGroup, PanelLabel } from '../../../../buttons/PanelButton';
import { PanelRadioButton } from '../../../../buttons/PanelRadioButton'; import { PanelRadioButton } from '../../../../buttons/PanelRadioButton';
function loadDataTestId(mode: DisappearingMessageConversationType) { function loadDataTestId(mode: DisappearingMessageConversationModeType) {
const dataTestId = 'disappear-%-option'; const dataTestId = 'disappear-%-option';
switch (mode) { switch (mode) {
case 'legacy': case 'legacy':
@ -19,9 +19,9 @@ function loadDataTestId(mode: DisappearingMessageConversationType) {
} }
type DisappearingModesProps = { type DisappearingModesProps = {
options: Record<DisappearingMessageConversationType, boolean>; options: Record<DisappearingMessageConversationModeType, boolean>;
selected?: DisappearingMessageConversationType; selected?: DisappearingMessageConversationModeType;
setSelected: (value: DisappearingMessageConversationType) => void; setSelected: (value: DisappearingMessageConversationModeType) => void;
hasOnlyOneMode?: boolean; hasOnlyOneMode?: boolean;
}; };
@ -63,11 +63,11 @@ export const DisappearingModes = (props: DisappearingModesProps) => {
value={mode} value={mode}
isSelected={selected === mode} isSelected={selected === mode}
onSelect={() => { onSelect={() => {
setSelected(mode as DisappearingMessageConversationType); setSelected(mode as DisappearingMessageConversationModeType);
}} }}
disabled={options[mode as DisappearingMessageConversationType]} disabled={options[mode as DisappearingMessageConversationModeType]}
noBackgroundColor={true} noBackgroundColor={true}
dataTestId={loadDataTestId(mode as DisappearingMessageConversationType)} dataTestId={loadDataTestId(mode as DisappearingMessageConversationModeType)}
/> />
); );
})} })}

@ -15,7 +15,7 @@ import {
} from '../../../../../state/selectors/selectedConversation'; } from '../../../../../state/selectors/selectedConversation';
import { import {
DEFAULT_TIMER_OPTION, DEFAULT_TIMER_OPTION,
DisappearingMessageConversationType, DisappearingMessageConversationModeType,
} from '../../../../../util/expiringMessages'; } from '../../../../../util/expiringMessages';
import { Flex } from '../../../../basic/Flex'; import { Flex } from '../../../../basic/Flex';
import { SessionButton } from '../../../../basic/SessionButton'; import { SessionButton } from '../../../../basic/SessionButton';
@ -52,7 +52,7 @@ const StyledNonAdminDescription = styled.div`
`; `;
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
function loadDefaultTimeValue(modeSelected: DisappearingMessageConversationType | undefined) { function loadDefaultTimeValue(modeSelected: DisappearingMessageConversationModeType | undefined) {
return modeSelected !== 'off' return modeSelected !== 'off'
? modeSelected !== 'legacy' ? modeSelected !== 'legacy'
? modeSelected === 'deleteAfterSend' ? modeSelected === 'deleteAfterSend'
@ -63,7 +63,7 @@ function loadDefaultTimeValue(modeSelected: DisappearingMessageConversationType
} }
export type PropsForExpirationSettings = { export type PropsForExpirationSettings = {
expirationType: DisappearingMessageConversationType | undefined; expirationType: DisappearingMessageConversationModeType | undefined;
expireTimer: number | undefined; expireTimer: number | undefined;
isGroup: boolean | undefined; isGroup: boolean | undefined;
weAreAdmin: boolean | undefined; weAreAdmin: boolean | undefined;
@ -75,11 +75,11 @@ export const OverlayDisappearingMessages = () => {
const disappearingModeOptions = useSelector(getSelectedConversationExpirationModes); const disappearingModeOptions = useSelector(getSelectedConversationExpirationModes);
// NOTE if there is only 'off' and one disappearing message mode then we trigger single mode // NOTE if there is only 'off' and one disappearing message mode then we trigger single mode
const singleMode: DisappearingMessageConversationType | undefined = const singleMode: DisappearingMessageConversationModeType | undefined =
disappearingModeOptions && disappearingModeOptions &&
disappearingModeOptions.off !== undefined && disappearingModeOptions.off !== undefined &&
Object.keys(disappearingModeOptions).length === 2 Object.keys(disappearingModeOptions).length === 2
? (Object.keys(disappearingModeOptions)[1] as DisappearingMessageConversationType) ? (Object.keys(disappearingModeOptions)[1] as DisappearingMessageConversationModeType)
: undefined; : undefined;
const hasOnlyOneMode = Boolean(singleMode && singleMode.length > 0); const hasOnlyOneMode = Boolean(singleMode && singleMode.length > 0);
@ -88,9 +88,9 @@ export const OverlayDisappearingMessages = () => {
const expireTimer = useSelectedExpireTimer(); const expireTimer = useSelectedExpireTimer();
const weAreAdmin = useSelectedWeAreAdmin(); const weAreAdmin = useSelectedWeAreAdmin();
const [modeSelected, setModeSelected] = useState<DisappearingMessageConversationType | undefined>( const [modeSelected, setModeSelected] = useState<
hasOnlyOneMode ? singleMode : expirationType DisappearingMessageConversationModeType | undefined
); >(hasOnlyOneMode ? singleMode : expirationType);
const [timeSelected, setTimeSelected] = useState(expireTimer || 0); const [timeSelected, setTimeSelected] = useState(expireTimer || 0);
const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode); const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode);

@ -44,7 +44,7 @@ import { encryptProfile } from '../util/crypto/profileEncrypter';
import { ReleasedFeatures } from '../util/releaseFeature'; import { ReleasedFeatures } from '../util/releaseFeature';
import { Storage, setLastProfileUpdateTimestamp } from '../util/storage'; import { Storage, setLastProfileUpdateTimestamp } from '../util/storage';
import { UserGroupsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface'; import { UserGroupsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface';
import { DisappearingMessageConversationType } from '../util/expiringMessages'; import { DisappearingMessageConversationModeType } from '../util/expiringMessages';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime'; import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
export async function copyPublicKeyByConvoId(convoId: string) { export async function copyPublicKeyByConvoId(convoId: string) {
@ -367,7 +367,7 @@ export function deleteAllMessagesByConvoIdWithConfirmation(conversationId: strin
export async function setDisappearingMessagesByConvoId( export async function setDisappearingMessagesByConvoId(
conversationId: string, conversationId: string,
expirationType: DisappearingMessageConversationType, expirationType: DisappearingMessageConversationModeType,
seconds?: number seconds?: number
) { ) {
const conversation = getConversationController().get(conversationId); const conversation = getConversationController().get(conversationId);

@ -118,7 +118,7 @@ import {
} from '../state/selectors/sogsRoomInfo'; // decide it it makes sense to move this to a redux slice? } from '../state/selectors/sogsRoomInfo'; // decide it it makes sense to move this to a redux slice?
import { import {
DisappearingMessageConversationType, DisappearingMessageConversationModeType,
changeToDisappearingMessageType, changeToDisappearingMessageType,
} from '../util/expiringMessages'; } from '../util/expiringMessages';
import { markAttributesAsReadIfNeeded } from './messageFactory'; import { markAttributesAsReadIfNeeded } from './messageFactory';
@ -811,7 +811,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
shouldCommit = true, shouldCommit = true,
existingMessage, existingMessage,
}: { }: {
providedExpirationType?: DisappearingMessageConversationType; providedExpirationType?: DisappearingMessageConversationModeType;
providedExpireTimer?: number; providedExpireTimer?: number;
providedChangeTimestamp: number; providedChangeTimestamp: number;
providedSource?: string; providedSource?: string;
@ -2338,7 +2338,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return []; return [];
} }
private isDisappearingMode(mode: DisappearingMessageConversationType) { private isDisappearingMode(mode: DisappearingMessageConversationModeType) {
const success = const success =
mode === 'deleteAfterRead' mode === 'deleteAfterRead'
? this.get('expirationType') === 'deleteAfterRead' ? this.get('expirationType') === 'deleteAfterRead'

@ -1,6 +1,6 @@
import { defaults } from 'lodash'; import { defaults } from 'lodash';
import { LastMessageStatusType } from '../state/ducks/conversations'; import { LastMessageStatusType } from '../state/ducks/conversations';
import { DisappearingMessageConversationType } from '../util/expiringMessages'; import { DisappearingMessageConversationModeType } from '../util/expiringMessages';
/** /**
* Private chats have always the type `Private` * Private chats have always the type `Private`
@ -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 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: DisappearingMessageConversationType; // the type of expiring messages for this conversation expirationType: 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 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 hasOutdatedClient?: string; // to warn the user that the person he is talking to is using an old client which might cause issues
} }

@ -18,7 +18,7 @@ import {
import { getConversationController } from '../../session/conversations'; import { getConversationController } from '../../session/conversations';
import { ReactionList } from '../../types/Reaction'; import { ReactionList } from '../../types/Reaction';
import { import {
DisappearingMessageConversationType, DisappearingMessageConversationModeType,
DisappearingMessageType, DisappearingMessageType,
} from '../../util/expiringMessages'; } from '../../util/expiringMessages';
@ -86,7 +86,7 @@ export type PropsForExpiringMessage = {
}; };
export type PropsForExpirationTimer = { export type PropsForExpirationTimer = {
expirationType: DisappearingMessageConversationType; expirationType: DisappearingMessageConversationModeType;
timespan: string; timespan: string;
disabled: boolean; disabled: boolean;
pubkey: string; pubkey: string;
@ -247,7 +247,7 @@ export interface ReduxConversationType {
weAreAdmin?: boolean; weAreAdmin?: boolean;
unreadCount?: number; unreadCount?: number;
mentionedUs?: boolean; mentionedUs?: boolean;
expirationType?: DisappearingMessageConversationType; expirationType?: DisappearingMessageConversationModeType;
expireTimer?: number; expireTimer?: number;
lastDisappearingMessageChangeTimestamp?: number; lastDisappearingMessageChangeTimestamp?: number;
hasOutdatedClient?: string; hasOutdatedClient?: string;

@ -7,8 +7,8 @@ import { StateType } from '../reducer';
import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo'; import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo';
import { getIsMessageSelectionMode, getSelectedConversation } from './conversations'; import { getIsMessageSelectionMode, getSelectedConversation } from './conversations';
import { import {
DisappearingMessageConversationSetting, DisappearingMessageConversationModes,
DisappearingMessageConversationType, DisappearingMessageConversationModeType,
} from '../../util/expiringMessages'; } from '../../util/expiringMessages';
import { ReleasedFeatures } from '../../util/releaseFeature'; import { ReleasedFeatures } from '../../util/releaseFeature';
import { ReduxConversationType } from '../ducks/conversations'; import { ReduxConversationType } from '../ducks/conversations';
@ -167,7 +167,7 @@ const getSelectedConversationExpirationModesWithLegacy = (convo: ReduxConversati
} }
// NOTE this needs to be as any because the number of modes can change depending on if v2 is released or we are in single mode // NOTE this needs to be as any because the number of modes can change depending on if v2 is released or we are in single mode
let modes: any = DisappearingMessageConversationSetting; let modes: any = DisappearingMessageConversationModes;
// Note to Self and Closed Groups only support deleteAfterSend and legacy modes // Note to Self and Closed Groups only support deleteAfterSend and legacy modes
const isClosedGroup = !convo.isPrivate && !convo.isPublic; const isClosedGroup = !convo.isPrivate && !convo.isPublic;
@ -202,7 +202,7 @@ export const getSelectedConversationExpirationModes = (state: StateType) => {
} }
// NOTE this needs to be as any because the number of modes can change depending on if v2 is released or we are in single mode // NOTE this needs to be as any because the number of modes can change depending on if v2 is released or we are in single mode
let modes: any = DisappearingMessageConversationSetting; let modes: any = DisappearingMessageConversationModes;
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// TODO remove legacy mode // TODO remove legacy mode
modes = modes.slice(0, -1); modes = modes.slice(0, -1);
@ -313,7 +313,7 @@ export function useSelectedExpireTimer(): number | undefined {
} }
export function useSelectedConversationExpirationType(): export function useSelectedConversationExpirationType():
| DisappearingMessageConversationType | DisappearingMessageConversationModeType
| undefined { | undefined {
return useSelector((state: StateType) => getSelectedConversation(state)?.expirationType); return useSelector((state: StateType) => getSelectedConversation(state)?.expirationType);
} }

@ -22,13 +22,13 @@ export type DisappearAfterSendOnly = Exclude<DisappearingMessageType, 'deleteAft
// NOTE these cannot be imported in the nodejs side yet. We need to move the types to the own file with no window imports // NOTE these cannot be imported in the nodejs side yet. We need to move the types to the own file with no window imports
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// TODO NOTE legacy is strictly used in the UI and is not a valid disappearing message mode // TODO NOTE legacy is strictly used in the UI and is not a valid disappearing message mode
export const DisappearingMessageConversationSetting = [ export const DisappearingMessageConversationModes = [
'off', 'off',
DisappearingMessageMode[1], // deleteAfterRead DisappearingMessageMode[1], // deleteAfterRead
DisappearingMessageMode[2], // deleteAfterSend DisappearingMessageMode[2], // deleteAfterSend
'legacy', 'legacy',
] as const; ] as const;
export type DisappearingMessageConversationType = typeof DisappearingMessageConversationSetting[number]; // TODO we should make this type a bit more hardcoded than being just resolved as a string export type DisappearingMessageConversationModeType = typeof DisappearingMessageConversationModes[number]; // TODO we should make this type a bit more hardcoded than being just resolved as a string
export const DEFAULT_TIMER_OPTION = { export const DEFAULT_TIMER_OPTION = {
DELETE_AFTER_READ: 43200, // 12 hours DELETE_AFTER_READ: 43200, // 12 hours
@ -243,7 +243,7 @@ export const ExpirationTimerOptions = {
}; };
export function setExpirationStartTimestamp( export function setExpirationStartTimestamp(
mode: DisappearingMessageConversationType, mode: DisappearingMessageConversationModeType,
timestamp?: number, timestamp?: number,
callLocation?: string // this is for debugging purposes callLocation?: string // this is for debugging purposes
): number | undefined { ): number | undefined {
@ -301,7 +301,7 @@ export function setExpirationStartTimestamp(
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
export function isLegacyDisappearingModeEnabled( export function isLegacyDisappearingModeEnabled(
expirationType: DisappearingMessageConversationType | DisappearingMessageType | undefined expirationType: DisappearingMessageConversationModeType | DisappearingMessageType | undefined
): boolean { ): boolean {
return Boolean( return Boolean(
expirationType && expirationType &&
@ -323,7 +323,7 @@ export function isLegacyDisappearingModeEnabled(
export function changeToDisappearingMessageType( export function changeToDisappearingMessageType(
convo: ConversationModel, convo: ConversationModel,
expireTimer: number, expireTimer: number,
expirationType?: DisappearingMessageConversationType expirationType?: DisappearingMessageConversationModeType
): DisappearingMessageType { ): DisappearingMessageType {
if (expirationType === 'off' || expirationType === 'legacy') { if (expirationType === 'off' || expirationType === 'legacy') {
// NOTE we would want this to be undefined but because of an issue with the protobuf implement we need to have a value // NOTE we would want this to be undefined but because of an issue with the protobuf implement we need to have a value
@ -356,7 +356,7 @@ export function changeToDisappearingMessageConversationType(
convo: ConversationModel, convo: ConversationModel,
expirationType?: DisappearingMessageType, expirationType?: DisappearingMessageType,
expireTimer?: number expireTimer?: number
): DisappearingMessageConversationType { ): DisappearingMessageConversationModeType {
if (!expirationType || expirationType === 'unknown') { if (!expirationType || expirationType === 'unknown') {
return expireTimer && expireTimer > 0 ? 'legacy' : 'off'; return expireTimer && expireTimer > 0 ? 'legacy' : 'off';
} }
@ -387,7 +387,7 @@ function couldBeLegacyDisappearingMessageContent(contentMessage: SignalService.C
function checkDisappearButIsntMessage( function checkDisappearButIsntMessage(
content: SignalService.Content, content: SignalService.Content,
convo: ConversationModel, convo: ConversationModel,
expirationMode: DisappearingMessageConversationType, expirationMode: DisappearingMessageConversationModeType,
expirationTimer: number expirationTimer: number
): boolean { ): boolean {
return ( return (

Loading…
Cancel
Save