move mentions state to the ConversationState

pull/1753/head
audric 4 years ago
parent 23e9a6d31c
commit b7df0788c2

@ -7,7 +7,6 @@ import { UserUtils } from '../../session/utils';
import { createStore } from '../../state/createStore'; import { createStore } from '../../state/createStore';
import { actions as conversationActions } from '../../state/ducks/conversations'; import { actions as conversationActions } from '../../state/ducks/conversations';
import { initialDefaultRoomState } from '../../state/ducks/defaultRooms'; import { initialDefaultRoomState } from '../../state/ducks/defaultRooms';
import { initialMentionsState } from '../../state/ducks/mentionsInput';
import { initialModalState } from '../../state/ducks/modalDialog'; import { initialModalState } from '../../state/ducks/modalDialog';
import { initialOnionPathState } from '../../state/ducks/onion'; import { initialOnionPathState } from '../../state/ducks/onion';
import { initialSearchState } from '../../state/ducks/search'; import { initialSearchState } from '../../state/ducks/search';
@ -112,6 +111,7 @@ export class SessionInboxView extends React.Component<any, State> {
lightBox: undefined, lightBox: undefined,
nextMessageToPlay: undefined, nextMessageToPlay: undefined,
quotedMessage: undefined, quotedMessage: undefined,
mentionMembers: [],
}, },
user: { user: {
ourNumber: UserUtils.getOurPubKeyStrFromCache(), ourNumber: UserUtils.getOurPubKeyStrFromCache(),
@ -120,7 +120,6 @@ export class SessionInboxView extends React.Component<any, State> {
defaultRooms: initialDefaultRoomState, defaultRooms: initialDefaultRoomState,
search: initialSearchState, search: initialSearchState,
theme: initialThemeState, theme: initialThemeState,
mentionsInput: initialMentionsState,
onionPaths: initialOnionPathState, onionPaths: initialOnionPathState,
modals: initialModalState, modals: initialModalState,
userConfig: initialUserConfigState, userConfig: initialUserConfigState,

@ -32,7 +32,6 @@ import { ReduxConversationType } from '../../../state/ducks/conversations';
import { SessionMemberListItem } from '../SessionMemberListItem'; import { SessionMemberListItem } from '../SessionMemberListItem';
import autoBind from 'auto-bind'; import autoBind from 'auto-bind';
import { SessionSettingCategory } from '../settings/SessionSettings'; import { SessionSettingCategory } from '../settings/SessionSettings';
import { getMentionsInput } from '../../../state/selectors/mentionsInput';
import { updateConfirmModal } from '../../../state/ducks/modalDialog'; import { updateConfirmModal } from '../../../state/ducks/modalDialog';
import { import {
SectionType, SectionType,
@ -46,6 +45,7 @@ import {
hasLinkPreviewPopupBeenDisplayed, hasLinkPreviewPopupBeenDisplayed,
} from '../../../data/data'; } from '../../../data/data';
import { import {
getMentionsInput,
getQuotedMessage, getQuotedMessage,
getSelectedConversation, getSelectedConversation,
getSelectedConversationKey, getSelectedConversationKey,

@ -26,16 +26,13 @@ import {
resetSelectedMessageIds, resetSelectedMessageIds,
showLightBox, showLightBox,
SortedMessageModelProps, SortedMessageModelProps,
updateMentionsMembers,
} from '../../../state/ducks/conversations'; } from '../../../state/ducks/conversations';
import { MessageView } from '../../MainViewController'; import { MessageView } from '../../MainViewController';
import { pushUnblockToSend } from '../../../session/utils/Toast';
import { MessageDetail } from '../../conversation/MessageDetail'; import { MessageDetail } from '../../conversation/MessageDetail';
import { getConversationController } from '../../../session/conversations'; import { getConversationController } from '../../../session/conversations';
import { getMessageById, getPubkeysInPublicConversation } from '../../../data/data'; import { getPubkeysInPublicConversation } from '../../../data/data';
import autoBind from 'auto-bind'; import autoBind from 'auto-bind';
import { getDecryptedMediaUrl } from '../../../session/crypto/DecryptedAttachmentsManager';
import { updateMentionsMembers } from '../../../state/ducks/mentionsInput';
import { sendDataExtractionNotification } from '../../../session/messages/outgoing/controlMessage/DataExtractionNotificationMessage';
interface State { interface State {
unreadCount: number; unreadCount: number;
@ -117,8 +114,6 @@ export class SessionConversation extends React.Component<Props, State> {
global.clearInterval(this.publicMembersRefreshTimeout); global.clearInterval(this.publicMembersRefreshTimeout);
this.publicMembersRefreshTimeout = undefined; this.publicMembersRefreshTimeout = undefined;
} }
// shown convo changed. reset the list of members quotable
window?.inboxStore?.dispatch(updateMentionsMembers([]));
// if the newConversation changed, and is public, start our refresh members list // if the newConversation changed, and is public, start our refresh members list
if (newConversation.isPublic) { if (newConversation.isPublic) {
// this is a debounced call. // this is a debounced call.
@ -142,7 +137,6 @@ export class SessionConversation extends React.Component<Props, State> {
} }
if (newConversationKey !== oldConversationKey) { if (newConversationKey !== oldConversationKey) {
void this.loadInitialMessages(); void this.loadInitialMessages();
window.inboxStore?.dispatch(resetSelectedMessageIds());
this.setState({ this.setState({
showOverlay: false, showOverlay: false,
showRecordingView: false, showRecordingView: false,

@ -983,8 +983,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
for (const nowRead of oldUnreadNowRead) { for (const nowRead of oldUnreadNowRead) {
allProps.push(nowRead.getProps()); allProps.push(nowRead.getProps());
} }
window.inboxStore?.dispatch(conversationActions.messagesChanged(allProps));
if (allProps.length) {
window.inboxStore?.dispatch(conversationActions.messagesChanged(allProps));
}
// Some messages we're marking read are local notifications with no sender // Some messages we're marking read are local notifications with no sender
read = _.filter(read, m => Boolean(m.sender)); read = _.filter(read, m => Boolean(m.sender));
const realUnreadCount = await this.getUnreadCount(); const realUnreadCount = await this.getUnreadCount();

@ -243,8 +243,15 @@ export type ConversationsStateType = {
showScrollButton: boolean; showScrollButton: boolean;
animateQuotedMessageId?: string; animateQuotedMessageId?: string;
nextMessageToPlay?: number; nextMessageToPlay?: number;
mentionMembers: MentionsMembersType;
}; };
export type MentionsMembersType = Array<{
id: string;
authorPhoneNumber: string;
authorProfileName: string;
}>;
async function getMessages( async function getMessages(
conversationKey: string, conversationKey: string,
numMessages: number numMessages: number
@ -399,6 +406,7 @@ function getEmptyState(): ConversationsStateType {
selectedMessageIds: [], selectedMessageIds: [],
areMoreMessagesBeingFetched: false, areMoreMessagesBeingFetched: false,
showScrollButton: false, showScrollButton: false,
mentionMembers: [],
}; };
} }
@ -727,6 +735,7 @@ const conversationsSlice = createSlice({
nextMessageToPlay: undefined, nextMessageToPlay: undefined,
showScrollButton: false, showScrollButton: false,
animateQuotedMessageId: undefined, animateQuotedMessageId: undefined,
mentionMembers: [],
}; };
}, },
showLightBox( showLightBox(
@ -758,6 +767,14 @@ const conversationsSlice = createSlice({
state.nextMessageToPlay = action.payload; state.nextMessageToPlay = action.payload;
return state; return state;
}, },
updateMentionsMembers(
state: ConversationsStateType,
action: PayloadAction<MentionsMembersType>
) {
window?.log?.warn('updating mentions input members length', action.payload?.length);
state.mentionMembers = action.payload;
return state;
},
}, },
extraReducers: (builder: any) => { extraReducers: (builder: any) => {
// Add reducers for additional action types here, and handle loading state as needed // Add reducers for additional action types here, and handle loading state as needed
@ -814,4 +831,5 @@ export const {
showScrollToBottomButton, showScrollToBottomButton,
quotedMessageToAnimate, quotedMessageToAnimate,
setNextMessageToPlay, setNextMessageToPlay,
updateMentionsMembers,
} = actions; } = actions;

@ -1,27 +0,0 @@
import { createSlice } from '@reduxjs/toolkit';
export type MentionsInputState = Array<{
id: string;
authorPhoneNumber: string;
authorProfileName: string;
}>;
export const initialMentionsState: MentionsInputState = [];
/**
* This slice is the one holding the default joinable rooms fetched once in a while from the default opengroup v2 server.
*/
const mentionsInputSlice = createSlice({
name: 'mentionsInput',
initialState: initialMentionsState,
reducers: {
updateMentionsMembers(state, action) {
window?.log?.warn('updating mentions input members length', action.payload?.length);
return action.payload as MentionsInputState;
},
},
});
const { actions, reducer } = mentionsInputSlice;
export const { updateMentionsMembers } = actions;
export const defaultMentionsInputReducer = reducer;

@ -19,10 +19,12 @@ const onionSlice = createSlice({
initialState: initialOnionPathState, initialState: initialOnionPathState,
reducers: { reducers: {
updateOnionPaths(state: OnionState, action: PayloadAction<Array<Array<Snode>>>) { updateOnionPaths(state: OnionState, action: PayloadAction<Array<Array<Snode>>>) {
return { ...state, snodePaths: action.payload }; state.snodePaths = action.payload;
return state;
}, },
updateIsOnline(state: OnionState, action: PayloadAction<boolean>) { updateIsOnline(state: OnionState, action: PayloadAction<boolean>) {
return { ...state, isOnline: action.payload }; state.isOnline = action.payload;
return state;
}, },
}, },
}); });

@ -6,10 +6,6 @@ import { reducer as user, UserStateType } from './ducks/user';
import { reducer as theme, ThemeStateType } from './ducks/theme'; import { reducer as theme, ThemeStateType } from './ducks/theme';
import { reducer as section, SectionStateType } from './ducks/section'; import { reducer as section, SectionStateType } from './ducks/section';
import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms'; import { defaultRoomReducer as defaultRooms, DefaultRoomsState } from './ducks/defaultRooms';
import {
defaultMentionsInputReducer as mentionsInput,
MentionsInputState,
} from './ducks/mentionsInput';
import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion'; import { defaultOnionReducer as onionPaths, OnionState } from './ducks/onion';
import { modalReducer as modals, ModalState } from './ducks/modalDialog'; import { modalReducer as modals, ModalState } from './ducks/modalDialog';
@ -23,7 +19,6 @@ export type StateType = {
theme: ThemeStateType; theme: ThemeStateType;
section: SectionStateType; section: SectionStateType;
defaultRooms: DefaultRoomsState; defaultRooms: DefaultRoomsState;
mentionsInput: MentionsInputState;
onionPaths: OnionState; onionPaths: OnionState;
modals: ModalState; modals: ModalState;
userConfig: UserConfigState; userConfig: UserConfigState;
@ -37,7 +32,6 @@ export const reducers = {
theme, theme,
section, section,
defaultRooms, defaultRooms,
mentionsInput,
onionPaths, onionPaths,
modals, modals,
userConfig, userConfig,

@ -4,6 +4,7 @@ import { StateType } from '../reducer';
import { import {
ConversationLookupType, ConversationLookupType,
ConversationsStateType, ConversationsStateType,
MentionsMembersType,
MessagePropsDetails, MessagePropsDetails,
ReduxConversationType, ReduxConversationType,
SortedMessageModelProps, SortedMessageModelProps,
@ -316,3 +317,8 @@ export const getNextMessageToPlayIndex = createSelector(
getConversations, getConversations,
(state: ConversationsStateType): number | undefined => state.nextMessageToPlay || undefined (state: ConversationsStateType): number | undefined => state.nextMessageToPlay || undefined
); );
export const getMentionsInput = createSelector(
getConversations,
(state: ConversationsStateType): MentionsMembersType => state.mentionMembers
);

@ -1,5 +0,0 @@
import { StateType } from '../reducer';
import { MentionsInputState } from '../ducks/mentionsInput';
export const getMentionsInput = (state: StateType): MentionsInputState => state.mentionsInput;

@ -1,6 +1,6 @@
import { ConversationModel } from '../models/conversation'; import { ConversationModel } from '../models/conversation';
import { getConversationController } from '../session/conversations'; import { getConversationController } from '../session/conversations';
import { MentionsInputState } from '../state/ducks/mentionsInput'; import { MentionsMembersType } from '../state/ducks/conversations';
// tslint:disable: no-unnecessary-class // tslint:disable: no-unnecessary-class
export class FindMember { export class FindMember {
@ -31,7 +31,7 @@ export class FindMember {
if (thisConvo.isPublic()) { if (thisConvo.isPublic()) {
const publicMembers = (await window.inboxStore?.getState() const publicMembers = (await window.inboxStore?.getState()
.mentionsInput) as MentionsInputState; .mentionsInput) as MentionsMembersType;
const memberConversations = publicMembers const memberConversations = publicMembers
.map(publicMember => getConversationController().get(publicMember.authorPhoneNumber)) .map(publicMember => getConversationController().get(publicMember.authorPhoneNumber))
.filter((c: any) => !!c); .filter((c: any) => !!c);

Loading…
Cancel
Save