Merge pull request #55 from Bilb/group-migrate
chore: recreate legacy groups + disable UI actionspull/3281/head
commit
d035c685c1
@ -0,0 +1,46 @@
|
||||
import useInterval from 'react-use/lib/useInterval';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { DURATION } from '../session/constants';
|
||||
import { updateLegacyGroupDeprecationTimestampUpdatedAt } from '../state/ducks/releasedFeatures';
|
||||
import { NetworkTime } from '../util/NetworkTime';
|
||||
import { PubKey } from '../session/types';
|
||||
import { areLegacyGroupsDeprecatedYet } from '../state/selectors/releasedFeatures';
|
||||
import { useSelectedConversationKey } from '../state/selectors/selectedConversation';
|
||||
import type { StateType } from '../state/reducer';
|
||||
import { ConversationTypeEnum } from '../models/types';
|
||||
|
||||
export function useRefreshReleasedFeaturesTimestamp() {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useInterval(() => {
|
||||
const nowFromNetwork = NetworkTime.now();
|
||||
dispatch(updateLegacyGroupDeprecationTimestampUpdatedAt(nowFromNetwork));
|
||||
}, 1 * DURATION.SECONDS);
|
||||
}
|
||||
|
||||
export function getDisableLegacyGroupDeprecatedActions(state: StateType, convoId?: string) {
|
||||
if (!convoId || !PubKey.is05Pubkey(convoId)) {
|
||||
return false;
|
||||
}
|
||||
const selectedConvoIsGroup =
|
||||
state.conversations.conversationLookup[convoId]?.type === ConversationTypeEnum.GROUP;
|
||||
if (!selectedConvoIsGroup) {
|
||||
return false;
|
||||
}
|
||||
const legacyGroupDeprecated = areLegacyGroupsDeprecatedYet();
|
||||
// here we have
|
||||
// - a valid convoId
|
||||
// - that starts with 05
|
||||
// - that is a group (i.e. a legacy group)
|
||||
// - and legacy group deprecation date has been hit
|
||||
return legacyGroupDeprecated;
|
||||
}
|
||||
|
||||
export function useDisableLegacyGroupDeprecatedActions(convoId?: string) {
|
||||
return useSelector((state: StateType) => getDisableLegacyGroupDeprecatedActions(state, convoId));
|
||||
}
|
||||
|
||||
export function useSelectedDisableLegacyGroupDeprecatedActions() {
|
||||
const convoId = useSelectedConversationKey();
|
||||
return useDisableLegacyGroupDeprecatedActions(convoId);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
|
||||
import { DURATION } from '../../session/constants';
|
||||
|
||||
// FIXME update this to the correct timestamp REMOVE AFTER QA
|
||||
export const LEGACY_GROUP_DEPRECATED_TIMESTAMP_MS = Date.now() + DURATION.WEEKS * 52;
|
||||
|
||||
export interface ReleasedFeaturesState {
|
||||
legacyGroupDeprecationTimestampRefreshAtMs: number;
|
||||
}
|
||||
|
||||
export const initialReleasedFeaturesState = {
|
||||
legacyGroupDeprecationTimestampRefreshAtMs: Date.now(),
|
||||
};
|
||||
|
||||
const releasedFeaturesSlice = createSlice({
|
||||
name: 'releasedFeatures',
|
||||
initialState: initialReleasedFeaturesState,
|
||||
reducers: {
|
||||
updateLegacyGroupDeprecationTimestampUpdatedAt: (state, action: PayloadAction<number>) => {
|
||||
state.legacyGroupDeprecationTimestampRefreshAtMs = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { actions, reducer } = releasedFeaturesSlice;
|
||||
export const { updateLegacyGroupDeprecationTimestampUpdatedAt } = actions;
|
||||
export const releasedFeaturesReducer = reducer;
|
@ -0,0 +1,20 @@
|
||||
import { useSelector } from 'react-redux';
|
||||
import { NetworkTime } from '../../util/NetworkTime';
|
||||
import { LEGACY_GROUP_DEPRECATED_TIMESTAMP_MS } from '../ducks/releasedFeatures';
|
||||
|
||||
export const areLegacyGroupsDeprecatedYet = (): boolean => {
|
||||
const theyAreDeprecated = NetworkTime.now() >= LEGACY_GROUP_DEPRECATED_TIMESTAMP_MS;
|
||||
|
||||
return window.sessionFeatureFlags.forceLegacyGroupsDeprecated || theyAreDeprecated;
|
||||
};
|
||||
|
||||
export function areLegacyGroupsDeprecatedYetOutsideRedux() {
|
||||
if (!window.inboxStore) {
|
||||
return false;
|
||||
}
|
||||
return areLegacyGroupsDeprecatedYet();
|
||||
}
|
||||
|
||||
export function useAreLegacyGroupsDeprecatedYet() {
|
||||
return useSelector(areLegacyGroupsDeprecatedYet);
|
||||
}
|
Loading…
Reference in New Issue