feat: remove closedgroupv3 uneeded stuff for now
also move the room stuff which can be kept in memory into another redux slicepull/2620/head
parent
2a5dc5f2a5
commit
f5efb52fea
@ -1,29 +0,0 @@
|
||||
import * as CallDucks from './call';
|
||||
import * as conversationDucks from './conversations';
|
||||
import * as defaultRoomDucks from './defaultRooms';
|
||||
import * as DialogsDucks from './modalDialog';
|
||||
import * as OnionDucks from './onion';
|
||||
import * as PrimaryColorDucks from './primaryColor';
|
||||
import * as SearchDucks from './search';
|
||||
import * as SectionDucks from './section';
|
||||
import * as StagedAttachmentDucks from './stagedAttachments';
|
||||
import * as ThemeDucks from './theme';
|
||||
import * as TimerOptionsDucks from './timerOptions';
|
||||
import * as UserDucks from './user';
|
||||
import * as UserConfigDucks from './userConfig';
|
||||
|
||||
export {
|
||||
CallDucks,
|
||||
DialogsDucks,
|
||||
OnionDucks,
|
||||
PrimaryColorDucks,
|
||||
SearchDucks,
|
||||
SectionDucks,
|
||||
StagedAttachmentDucks,
|
||||
ThemeDucks,
|
||||
TimerOptionsDucks,
|
||||
UserConfigDucks,
|
||||
UserDucks,
|
||||
conversationDucks,
|
||||
defaultRoomDucks,
|
||||
};
|
@ -0,0 +1,62 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
type RoomInfo = {
|
||||
canWrite: boolean;
|
||||
subscriberCount: number;
|
||||
};
|
||||
|
||||
export type SogsRoomInfoState = {
|
||||
rooms: Record<string, RoomInfo>;
|
||||
};
|
||||
|
||||
export const initialSogsRoomInfoState: SogsRoomInfoState = {
|
||||
rooms: {},
|
||||
};
|
||||
|
||||
function addEmptyEntryIfNeeded(state: any, convoId: string) {
|
||||
if (!state.rooms[convoId]) {
|
||||
state.rooms[convoId] = { canWrite: true, subscriberCount: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This slice is the one holding the memory-only infos of sogs room. This includes
|
||||
* - writeCapability
|
||||
* - subscriberCount
|
||||
*/
|
||||
const sogsRoomInfosSlice = createSlice({
|
||||
name: 'sogsRoomInfos',
|
||||
initialState: initialSogsRoomInfoState,
|
||||
reducers: {
|
||||
setSubscriberCount(state, action: PayloadAction<{ convoId: string; subscriberCount: number }>) {
|
||||
addEmptyEntryIfNeeded(state, action.payload.convoId);
|
||||
if (isFinite(action.payload.subscriberCount)) {
|
||||
state.rooms[action.payload.convoId].subscriberCount = action.payload.subscriberCount;
|
||||
}
|
||||
return state;
|
||||
},
|
||||
setCanWrite(state, action: PayloadAction<{ convoId: string; canWrite: boolean }>) {
|
||||
addEmptyEntryIfNeeded(state, action.payload.convoId);
|
||||
state.rooms[action.payload.convoId].canWrite = !!action.payload.canWrite;
|
||||
|
||||
return state;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { actions, reducer } = sogsRoomInfosSlice;
|
||||
const { setSubscriberCount, setCanWrite } = actions;
|
||||
|
||||
export const ReduxSogsRoomInfos = {
|
||||
setSubscriberCountOutsideRedux,
|
||||
setCanWriteOutsideRedux,
|
||||
sogsRoomInfoReducer: reducer,
|
||||
};
|
||||
|
||||
function setSubscriberCountOutsideRedux(convoId: string, subscriberCount: number) {
|
||||
window.inboxStore?.dispatch(setSubscriberCount({ convoId, subscriberCount }));
|
||||
}
|
||||
|
||||
function setCanWriteOutsideRedux(convoId: string, canWrite: boolean) {
|
||||
window.inboxStore?.dispatch(setCanWrite({ convoId, canWrite }));
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import { isNil } from 'lodash';
|
||||
import { SogsRoomInfoState } from '../ducks/sogsRoomInfo';
|
||||
import { StateType } from '../reducer';
|
||||
|
||||
const getSogsRoomInfoState = (state: StateType): SogsRoomInfoState => state.sogsRoomInfo;
|
||||
|
||||
export function getCanWrite(state: StateType, selectedConvo?: string): boolean {
|
||||
if (!selectedConvo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const canWrite = getSogsRoomInfoState(state).rooms[selectedConvo]?.canWrite;
|
||||
// if there is no entry in the redux slice, consider it true (as this selector will be hit for non sogs convo too)
|
||||
return isNil(canWrite) ? true : canWrite;
|
||||
}
|
||||
|
||||
export function getSubscriberCount(state: StateType, selectedConvo?: string): number {
|
||||
if (!selectedConvo) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const subscriberCount = getSogsRoomInfoState(state).rooms[selectedConvo]?.subscriberCount;
|
||||
// if there is no entry in the redux slice, consider it 0 (as this selector will be hit for non sogs convo too)
|
||||
return isNil(subscriberCount) ? 0 : subscriberCount;
|
||||
}
|
||||
|
||||
export function getSubscriberCountOutsideRedux(convoId: string) {
|
||||
const state = window.inboxStore?.getState();
|
||||
|
||||
return state ? getSubscriberCount(state, convoId) : 0;
|
||||
}
|
||||
|
||||
export function getCanWriteOutsideRedux(convoId: string) {
|
||||
const state = window.inboxStore?.getState();
|
||||
return state ? getCanWrite(state, convoId) : false;
|
||||
}
|
@ -1,20 +1,17 @@
|
||||
import { StateType } from '../reducer';
|
||||
import { UserConfigState } from '../ducks/userConfig';
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
|
||||
export const getUserConfig = (state: StateType): UserConfigState => state.userConfig;
|
||||
export const getAudioAutoplay = (state: StateType): boolean => state.userConfig.audioAutoplay;
|
||||
|
||||
export const getAudioAutoplay = createSelector(
|
||||
getUserConfig,
|
||||
(state: UserConfigState): boolean => state.audioAutoplay
|
||||
);
|
||||
export const getShowRecoveryPhrasePrompt = (state: StateType): boolean =>
|
||||
state.userConfig?.showRecoveryPhrasePrompt || false;
|
||||
|
||||
export const getShowRecoveryPhrasePrompt = createSelector(
|
||||
getUserConfig,
|
||||
(state: UserConfigState): boolean => state.showRecoveryPhrasePrompt
|
||||
);
|
||||
export const getHideMessageRequestBanner = (state: StateType): boolean => {
|
||||
// I am not too sure why, but it seems that state.userConfig is not set early enough and we try to somehow fetch this too early?
|
||||
return state.userConfig?.hideMessageRequests || false;
|
||||
};
|
||||
|
||||
export const getHideMessageRequestBanner = createSelector(
|
||||
getUserConfig,
|
||||
(state: UserConfigState): boolean => state.hideMessageRequests
|
||||
);
|
||||
export const getHideMessageRequestBannerOutsideRedux = (): boolean => {
|
||||
const state = window.inboxStore?.getState();
|
||||
|
||||
return state ? getHideMessageRequestBanner(state) : true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue