chore: fix compilation issues after conflicts resolution

pull/2784/head
Audric Ackermann 2 years ago
parent 4637f4609a
commit 0fa58a5654

@ -8,7 +8,8 @@ import { OverlayRightPanelSettings } from './overlay/OverlayRightPanelSettings';
const ClosableOverlay = () => {
const rightOverlayMode = useSelector(getRightOverlayMode);
const [showNewDisppearingMessageModes, setShowNewDisppearingMessageModes] = useState(false);
// TODO we can probably use the ReleasedFeatures.isDisappearMessageV2FeatureReleased instead here so we can remove the state.
const [showNewDisappearingMessageModes, setShowNewDisappearingMessageModes] = useState(false);
useEffect(() => {
let isCancelled = false;
@ -17,7 +18,7 @@ const ClosableOverlay = () => {
if (isCancelled) {
return;
}
setShowNewDisppearingMessageModes(result);
setShowNewDisappearingMessageModes(result);
})
.catch(() => {
if (isCancelled) {
@ -33,7 +34,7 @@ const ClosableOverlay = () => {
switch (rightOverlayMode) {
case 'disappearing-messages':
// TODO legacy messages support will be removed in a future release
return <OverlayDisappearingMessages unlockNewModes={showNewDisppearingMessageModes} />;
return <OverlayDisappearingMessages unlockNewModes={showNewDisappearingMessageModes} />;
default:
return <OverlayRightPanelSettings />;
}

@ -1,27 +1,30 @@
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector';
import { setDisappearingMessagesByConvoId } from '../../../../../interactions/conversationInteractions';
import { getConversationController } from '../../../../../session/conversations';
import { closeRightPanel } from '../../../../../state/ducks/conversations';
import { resetRightOverlayMode } from '../../../../../state/ducks/section';
import { Flex } from '../../../../basic/Flex';
import { SessionButton } from '../../../../basic/SessionButton';
import { SpacerLG, SpacerXL } from '../../../../basic/Text';
import {
getSelectedConversationExpirationModes,
getSelectedConversationExpirationModesWithLegacy,
getSelectedConversationExpirationSettings,
getSelectedConversationKey,
} from '../../../../../state/selectors/conversations';
useSelectedConversationKey,
useSelectedExpirationType,
useSelectedExpireTimer,
useSelectedIsGroup,
useSelectedWeAreAdmin,
} from '../../../../../state/selectors/selectedConversation';
import {
DEFAULT_TIMER_OPTION,
DisappearingMessageConversationType,
} from '../../../../../util/expiringMessages';
import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector';
import { Header } from './Header';
import { Flex } from '../../../../basic/Flex';
import { SessionButton } from '../../../../basic/SessionButton';
import { SpacerLG, SpacerXL } from '../../../../basic/Text';
import { DisappearingModes } from './DisappearingModes';
import { Header } from './Header';
import { TimeOptions } from './TimeOptions';
import { getConversationController } from '../../../../../session/conversations';
const StyledScrollContainer = styled.div`
width: 100%;
@ -67,12 +70,9 @@ export type PropsForExpirationSettings = {
weAreAdmin: boolean | undefined;
};
type OverlayDisappearingMessagesProps = { unlockNewModes: boolean };
export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesProps) => {
const { unlockNewModes } = props;
export const OverlayDisappearingMessages = ({ unlockNewModes }: { unlockNewModes: boolean }) => {
const dispatch = useDispatch();
const selectedConversationKey = useSelector(getSelectedConversationKey);
const selectedConversationKey = useSelectedConversationKey();
const disappearingModeOptions = useSelector(
unlockNewModes
? getSelectedConversationExpirationModes
@ -81,21 +81,20 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
// NOTE if there is only 'off' and one disappearing message mode then we trigger single mode
const singleMode =
disappearingModeOptions.off !== undefined && Object.keys(disappearingModeOptions).length === 2
disappearingModeOptions &&
disappearingModeOptions.off !== undefined &&
Object.keys(disappearingModeOptions).length === 2
? Object.keys(disappearingModeOptions)[1]
: undefined;
const hasOnlyOneMode = Boolean(singleMode && singleMode.length > 0);
const convoProps = useSelector(getSelectedConversationExpirationSettings);
if (!convoProps) {
return null;
}
const { isGroup, weAreAdmin } = convoProps;
const isGroup = useSelectedIsGroup();
const expirationType = useSelectedExpirationType();
const expireTimer = useSelectedExpireTimer();
const weAreAdmin = useSelectedWeAreAdmin();
const [modeSelected, setModeSelected] = useState<DisappearingMessageConversationType | undefined>(
convoProps.expirationType
expirationType
);
const [timeSelected, setTimeSelected] = useState<number>(0);
const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode);
@ -127,13 +126,11 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
useEffect(() => {
// NOTE loads a time value from the conversation model or the default
handleSetTime(
modeSelected === convoProps.expirationType &&
convoProps.expireTimer &&
convoProps.expireTimer > -1
? convoProps.expireTimer
modeSelected === expirationType && expireTimer && expireTimer > -1
? expireTimer
: loadDefaultTimeValue(modeSelected)
);
}, [convoProps.expirationType, convoProps.expireTimer, modeSelected]);
}, [expirationType, expireTimer, modeSelected]);
// TODO legacy messages support will be removed in a future
useEffect(() => {
@ -141,7 +138,7 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
const convo = getConversationController().get(selectedConversationKey);
if (convo) {
let defaultExpirationType: DisappearingMessageConversationType = 'deleteAfterRead';
if (convo.isMe() || convo.isMediumGroup()) {
if (convo.isMe() || convo.isClosedGroup()) {
defaultExpirationType = 'deleteAfterSend';
}
convo.set('expirationType', defaultExpirationType);
@ -150,6 +147,13 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
}
}, [unlockNewModes, selectedConversationKey, modeSelected]);
if (!disappearingModeOptions) {
return null;
}
if (!selectedConversationKey) {
return null;
}
return (
<StyledScrollContainer>
<StyledContainer container={true} flexDirection={'column'} alignItems={'center'}>

@ -262,6 +262,7 @@ export function useMentionedUs(conversationId?: string): boolean {
export function useIsTyping(conversationId?: string): boolean {
return useConversationPropsById(conversationId)?.isTyping || false;
}
export function useMessageExpirationPropsById(messageId?: string) {
return useSelector((state: StateType) => {
if (!messageId) {

@ -385,12 +385,14 @@ export async function setDisappearingMessagesByConvoId(
providedExpirationType: 'off',
providedExpireTimer: 0,
providedChangeTimestamp,
fromConfigMessage: false,
});
} else {
await conversation.updateExpireTimer({
providedExpirationType: expirationType,
providedExpireTimer: seconds,
providedChangeTimestamp,
fromConfigMessage: false,
});
}
}

@ -793,6 +793,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
providedChangeTimestamp,
providedSource,
receivedAt, // is set if it comes from outside
fromConfigMessage,
fromSync = false,
shouldCommit = true,
existingMessage,
@ -803,6 +804,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
providedSource?: string;
receivedAt?: number; // is set if it comes from outside
fromSync?: boolean;
fromConfigMessage: boolean;
shouldCommit?: boolean;
existingMessage?: MessageModel;
}): Promise<void> {
@ -861,41 +863,43 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
lastDisappearingMessageChangeTimestamp,
source,
});
const commonAttributes = {
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: {
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
fromSync,
},
// TODO legacy messages support will be removed in a future release
expirationType:
expirationType !== 'off' || isDisappearingMessagesV2Released ? expirationType : undefined,
expireTimer:
expirationType !== 'off' || isDisappearingMessagesV2Released ? expireTimer : undefined,
};
let message: MessageModel | undefined = existingMessage || undefined;
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,
// 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
if (!fromConfigMessage) {
const commonAttributes = {
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: {
expirationType,
expireTimer,
lastDisappearingMessageChangeTimestamp,
source,
sent_at: timestamp,
received_at: timestamp,
});
fromSync,
},
// TODO legacy messages support will be removed in a future release
expirationType:
expirationType !== 'off' || isDisappearingMessagesV2Released ? expirationType : undefined,
expireTimer:
expirationType !== 'off' || isDisappearingMessagesV2Released ? expireTimer : undefined,
};
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,
});
}
}
}
@ -908,8 +912,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.commit();
}
// if change was made remotely, don't send it to the number/group
if (receivedAt) {
// if change was made remotely, don't send it to the contact/group
if (receivedAt || fromSync || fromConfigMessage) {
return;
}
@ -930,7 +934,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}
const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate);
return message.sendSyncMessageOnly(expirationTimerMessage);
return message?.sendSyncMessageOnly(expirationTimerMessage);
}
if (this.isPrivate()) {

@ -93,6 +93,7 @@ import { ReactionList } from '../types/Reaction';
import { roomHasBlindEnabled } from '../types/sqlSharedTypes';
import {
DisappearingMessageConversationSetting,
DisappearingMessageConversationType,
DisappearingMessageUpdate,
ExpirationTimerOptions,
setExpirationStartTimestamp,
@ -1097,7 +1098,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
dataMessage.flags === SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE)
);
const expirationType = content.expirationType
const expirationType: DisappearingMessageConversationType = content.expirationType
? DisappearingMessageConversationSetting[content.expirationType]
: isLegacyDataMessage
? DisappearingMessageConversationSetting[3]

@ -320,6 +320,7 @@ export async function handleNewClosedGroup(
providedChangeTimestamp: GetNetworkTime.getNowWithNetworkOffset(),
providedSource: sender,
receivedAt: Date.now(),
fromConfigMessage: false,
});
if (isKeyPairAlreadyHere) {
@ -381,6 +382,7 @@ export async function handleNewClosedGroup(
providedChangeTimestamp: GetNetworkTime.getNowWithNetworkOffset(),
providedSource: sender,
receivedAt: envelopeTimestamp,
fromConfigMessage: fromLegacyConfig,
});
convo.updateLastMessage();

@ -331,7 +331,14 @@ async function handleContactsUpdate(result: IncomingConfResult): Promise<Incomin
}
if (wrapperConvo.expirationTimerSeconds !== contactConvo.get('expireTimer')) {
await contactConvo.updateExpireTimer(wrapperConvo.expirationTimerSeconds);
await contactConvo.updateExpireTimer({
providedExpireTimer: wrapperConvo.expirationTimerSeconds,
fromSync: true,
providedExpirationType: wrapperConvo.expirationMode,
shouldCommit: false,
providedChangeTimestamp: result.latestEnvelopeTimestamp,
fromConfigMessage: true,
});
changes = true;
}
@ -559,14 +566,15 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
}
if (legacyGroupConvo.get('expireTimer') !== fromWrapper.disappearingTimerSeconds) {
await legacyGroupConvo.updateExpireTimer(
fromWrapper.disappearingTimerSeconds,
undefined,
latestEnvelopeTimestamp,
{
fromSync: true,
}
);
await legacyGroupConvo.updateExpireTimer({
providedExpireTimer: fromWrapper.disappearingTimerSeconds,
shouldCommit: false,
fromSync: true,
providedChangeTimestamp: latestEnvelopeTimestamp,
fromConfigMessage: true,
providedExpirationType:
fromWrapper.disappearingTimerSeconds === 0 ? 'off' : 'deleteAfterSend',
});
changes = true;
}
// start polling for this group if we haven't left it yet. The wrapper does not store this info for legacy group so we check from the DB entry instead

@ -344,7 +344,7 @@ export async function handleMessageJob(
messageModel.isIncoming() &&
Boolean(messageModel.get('expirationStartTimestamp')) === false &&
((messageModel.get('expirationType') === 'legacy' &&
(conversation.isMe() || conversation.isMediumGroup())) ||
(conversation.isMe() || conversation.isClosedGroup())) ||
messageModel.get('expirationType') === 'deleteAfterSend')
) {
messageModel.set({
@ -397,6 +397,7 @@ export async function handleMessageJob(
receivedAt: messageModel.get('received_at'),
shouldCommit: false,
existingMessage: messageModel,
fromConfigMessage: false,
});
} else {
// this does not commit to db nor UI unless we need to approve a convo

@ -269,10 +269,11 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) {
// TODO What are we cleaning?
providedExpirationType: expirationType || 'deleteAfterSend',
providedExpireTimer: expireTimer,
providedChangeTimestamp: getNowWithNetworkOffset(),
providedChangeTimestamp: GetNetworkTime.getNowWithNetworkOffset(),
providedSource: UserUtils.getOurPubKeyStrFromCache(),
receivedAt: Date.now(),
fromSync: true,
fromConfigMessage: false,
});
}

@ -128,7 +128,7 @@ async function handleMessageSentSuccess(
const isLegacyReadMode =
convo && !convo.isMe() && convo.isPrivate() && expirationType === 'legacy';
const isLegacySentMode =
convo && (convo.isMe() || convo.isMediumGroup()) && expirationType === 'legacy';
convo && (convo.isMe() || convo.isClosedGroup()) && expirationType === 'legacy';
fetchedMessage.set({
sent_to: sentTo,

@ -1,15 +1,12 @@
import { useSelector } from 'react-redux';
import { ConversationTypeEnum, isOpenOrClosedGroup } from '../../models/conversationAttributes';
import { PubKey } from '../../session/types';
import { ReduxConversationType } from '../ducks/conversations';
import { StateType } from '../reducer';
import { getCanWrite, getSubscriberCount } from './sogsRoomInfo';
import { PubKey } from '../../session/types';
import {
DisappearingMessageConversationSetting,
DisappearingMessageModesWithState,
} from '../../util/expiringMessages';
import { createSelector } from '@reduxjs/toolkit';
import { PropsForExpirationSettings } from '../../components/conversation/right-panel/overlay/disappearing-messages/OverlayDisappearingMessages';
import { DisappearingMessageConversationSetting } from '../../util/expiringMessages';
/**
* Returns the formatted text for notification setting.
@ -275,21 +272,21 @@ export function useSelectedWeAreAdmin() {
export const getSelectedConversationExpirationModes = createSelector(
getSelectedConversation,
(convo: ReduxConversationType | undefined) => {
if (!convo) {
return null;
}
let modes = DisappearingMessageConversationSetting;
// TODO legacy messages support will be removed in a future release
// TODO remove legacy mode
modes = modes.slice(0, -1);
if (!convo) {
return DisappearingMessageConversationSetting;
}
// Note to Self and Closed Groups only support deleteAfterSend
const isClosedGroup = !convo.isPrivate && !convo.isPublic;
if (convo?.isMe || isClosedGroup) {
modes = [modes[0], modes[2]];
}
const modesWithDisabledState: DisappearingMessageModesWithState = {};
const modesWithDisabledState: Record<string, boolean> = {};
if (modes && modes.length > 1) {
modes.forEach(mode => {
modesWithDisabledState[mode] = isClosedGroup ? !convo.weAreAdmin : false;
@ -304,12 +301,12 @@ export const getSelectedConversationExpirationModes = createSelector(
export const getSelectedConversationExpirationModesWithLegacy = createSelector(
getSelectedConversation,
(convo: ReduxConversationType | undefined) => {
let modes = DisappearingMessageConversationSetting;
// this just won't happen
if (!convo) {
return DisappearingMessageConversationSetting;
return null;
}
let modes = DisappearingMessageConversationSetting;
// Note to Self and Closed Groups only support deleteAfterSend and legacy modes
const isClosedGroup = !convo.isPrivate && !convo.isPublic;
if (convo?.isMe || isClosedGroup) {
@ -319,7 +316,8 @@ export const getSelectedConversationExpirationModesWithLegacy = createSelector(
// Legacy mode is the 2nd option in the UI
modes = [modes[0], modes[modes.length - 1], ...modes.slice(1, modes.length - 1)];
const modesWithDisabledState: DisappearingMessageModesWithState = {};
// TODO it would be nice to type those with something else that string but it causes a lot of issues
const modesWithDisabledState: Record<string, boolean> = {};
// The new modes are disabled by default
if (modes && modes.length > 1) {
modes.forEach(mode => {
@ -332,13 +330,3 @@ export const getSelectedConversationExpirationModesWithLegacy = createSelector(
return modesWithDisabledState;
}
);
export const getSelectedConversationExpirationSettings = createSelector(
getSelectedConversation,
(convo: ReduxConversationType | undefined): PropsForExpirationSettings => ({
expirationType: convo?.expirationType,
expireTimer: convo?.expireTimer,
isGroup: !convo?.isPrivate,
weAreAdmin: convo?.weAreAdmin,
})
);

@ -14,7 +14,6 @@ import {
import {
getSelectedConversation,
getSelectedConversationKey,
getSelectedConversationExpirationSettings,
} from '../selectors/selectedConversation';
import { getStagedAttachmentsForCurrentConversation } from '../selectors/stagedAttachments';
import { getTheme } from '../selectors/theme';
@ -34,7 +33,6 @@ const mapStateToProps = (state: StateType) => {
stagedAttachments: getStagedAttachmentsForCurrentConversation(state),
hasOngoingCallWithFocusedConvo: getHasOngoingCallWithFocusedConvo(state),
isSelectedConvoInitialLoadingInProgress: getIsSelectedConvoInitialLoadingInProgress(state),
selectedConversationExpirationSettings: getSelectedConversationExpirationSettings(state),
};
};

@ -13,18 +13,13 @@ import { MessageModel } from '../models/message';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { ReleasedFeatures } from './releaseFeature';
// TODO Might need to be improved by using an enum
// TODO do we need to add legacy here now that it's explicitly in the protbuf?
// TODO do we need to add legacy here now that it's explicitly in the protobuf?
export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend'];
export type DisappearingMessageType = typeof DisappearingMessageMode[number] | null;
// TODO legacy messages support will be removed in a future release
export const DisappearingMessageConversationSetting = ['off', ...DisappearingMessageMode, 'legacy'];
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 DisappearingMessageModesWithState = Record<
DisappearingMessageConversationType,
boolean
>;
export const DEFAULT_TIMER_OPTION = {
DELETE_AFTER_READ: 43200, // 12 hours

Loading…
Cancel
Save