|
|
|
@ -7,6 +7,8 @@ import { StateType } from '../reducer';
|
|
|
|
|
import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo';
|
|
|
|
|
import { getIsMessageSelectionMode, getSelectedConversation } from './conversations';
|
|
|
|
|
import { DisappearingMessageConversationSetting } from '../../util/expiringMessages';
|
|
|
|
|
import { ReleasedFeatures } from '../../util/releaseFeature';
|
|
|
|
|
import { ReduxConversationType } from '../ducks/conversations';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the formatted text for notification setting.
|
|
|
|
@ -155,59 +157,62 @@ const getSelectedSubscriberCount = (state: StateType): number | undefined => {
|
|
|
|
|
return getSubscriberCount(state, convo.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getSelectedConversationExpirationModes = (state: StateType) => {
|
|
|
|
|
const convo = getSelectedConversation(state);
|
|
|
|
|
// TODO legacy messages support will be removed in a future release
|
|
|
|
|
const getSelectedConversationExpirationModesWithLegacy = (convo: ReduxConversationType) => {
|
|
|
|
|
if (!convo) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let modes = DisappearingMessageConversationSetting;
|
|
|
|
|
// TODO legacy messages support will be removed in a future release
|
|
|
|
|
// TODO remove legacy mode
|
|
|
|
|
modes = modes.slice(0, -1);
|
|
|
|
|
|
|
|
|
|
// Note to Self and Closed Groups only support deleteAfterSend
|
|
|
|
|
// Note to Self and Closed Groups only support deleteAfterSend and legacy modes
|
|
|
|
|
const isClosedGroup = !convo.isPrivate && !convo.isPublic;
|
|
|
|
|
if (convo?.isMe || isClosedGroup) {
|
|
|
|
|
modes = [modes[0], modes[2]];
|
|
|
|
|
modes = [modes[0], ...modes.slice(2)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Legacy mode is the 2nd option in the UI
|
|
|
|
|
modes = [modes[0], modes[modes.length - 1], ...modes.slice(1, modes.length - 1)];
|
|
|
|
|
|
|
|
|
|
// 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 => {
|
|
|
|
|
modesWithDisabledState[mode] = isClosedGroup ? !convo.weAreAdmin : false;
|
|
|
|
|
modesWithDisabledState[mode] = Boolean(
|
|
|
|
|
(mode !== 'legacy' && mode !== 'off') || (isClosedGroup && !convo.weAreAdmin)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return modesWithDisabledState;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO legacy messages support will be removed in a future release
|
|
|
|
|
export const getSelectedConversationExpirationModesWithLegacy = (state: StateType) => {
|
|
|
|
|
export const getSelectedConversationExpirationModes = (state: StateType) => {
|
|
|
|
|
const convo = getSelectedConversation(state);
|
|
|
|
|
if (!convo) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()) {
|
|
|
|
|
return getSelectedConversationExpirationModesWithLegacy(convo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let modes = DisappearingMessageConversationSetting;
|
|
|
|
|
// TODO legacy messages support will be removed in a future release
|
|
|
|
|
// TODO remove legacy mode
|
|
|
|
|
modes = modes.slice(0, -1);
|
|
|
|
|
|
|
|
|
|
// Note to Self and Closed Groups only support deleteAfterSend and legacy modes
|
|
|
|
|
// Note to Self and Closed Groups only support deleteAfterSend
|
|
|
|
|
const isClosedGroup = !convo.isPrivate && !convo.isPublic;
|
|
|
|
|
if (convo?.isMe || isClosedGroup) {
|
|
|
|
|
modes = [modes[0], ...modes.slice(2)];
|
|
|
|
|
modes = [modes[0], modes[2]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Legacy mode is the 2nd option in the UI
|
|
|
|
|
modes = [modes[0], modes[modes.length - 1], ...modes.slice(1, modes.length - 1)];
|
|
|
|
|
|
|
|
|
|
// 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 => {
|
|
|
|
|
modesWithDisabledState[mode] = Boolean(
|
|
|
|
|
(mode !== 'legacy' && mode !== 'off') || (isClosedGroup && !convo.weAreAdmin)
|
|
|
|
|
);
|
|
|
|
|
modesWithDisabledState[mode] = isClosedGroup ? !convo.weAreAdmin : false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|