diff --git a/web/chat/chat.react.js b/web/chat/chat.react.js
--- a/web/chat/chat.react.js
+++ b/web/chat/chat.react.js
@@ -2,12 +2,20 @@
import * as React from 'react';
+import ThreadDraftUpdater from 'lib/components/thread-draft-updater.react';
+import { isLoggedIn } from 'lib/selectors/user-selectors';
+
import { useSelector } from '../redux/redux-utils';
import ChatMessageListContainer from './chat-message-list-container.react';
import ChatTabs from './chat-tabs.react';
import { ThreadListProvider } from './thread-list-provider';
function Chat(): React.Node {
+ const loggedIn = useSelector(isLoggedIn);
+ let threadDraftUpdater = null;
+ if (loggedIn) {
+ threadDraftUpdater = ;
+ }
const activeChatThreadID = useSelector(
state => state.navInfo.activeChatThreadID,
);
@@ -30,6 +38,7 @@
<>
{chatList}
{messageList}
+ {threadDraftUpdater}
>
);
}
diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js
--- a/web/input/input-state-container.react.js
+++ b/web/input/input-state-container.react.js
@@ -37,6 +37,7 @@
} from 'lib/shared/message-utils';
import {
createRealThreadFromPendingThread,
+ draftKeyFromThreadID,
threadIsPending,
} from 'lib/shared/thread-utils';
import type { CalendarQuery } from 'lib/types/entry-types';
@@ -84,6 +85,7 @@
type Props = {
...BaseProps,
+activeChatThreadID: ?string,
+ +drafts: { +[key: string]: string },
+viewerID: ?string,
+messageStoreMessages: { +[id: string]: RawMessageInfo },
+exifRotate: boolean,
@@ -117,12 +119,15 @@
+pendingUploads: {
[threadID: string]: { [localUploadID: string]: PendingMultimediaUpload },
},
- +drafts: { [threadID: string]: string },
+};
+
+type PropsAndState = {
+ ...Props,
+ ...State,
};
class InputStateContainer extends React.PureComponent {
state: State = {
pendingUploads: {},
- drafts: {},
};
replyCallbacks: Array<(message: string) => void> = [];
pendingThreadCreations = new Map>();
@@ -145,23 +150,16 @@
}
static getDerivedStateFromProps(props: Props, state: State) {
- const drafts = InputStateContainer.reassignToRealizedThreads(
- state.drafts,
- props,
- );
const pendingUploads = InputStateContainer.reassignToRealizedThreads(
state.pendingUploads,
props,
);
- if (!drafts && !pendingUploads) {
+ if (!pendingUploads) {
return null;
}
const stateUpdate = {};
- if (drafts) {
- stateUpdate.drafts = drafts;
- }
if (pendingUploads) {
stateUpdate.pendingUploads = pendingUploads;
}
@@ -449,8 +447,9 @@
inputStateSelector = _memoize((threadID: string) =>
createSelector(
- (state: State) => state.pendingUploads[threadID],
- (state: State) => state.drafts[threadID],
+ (propsAndState: PropsAndState) => propsAndState.pendingUploads[threadID],
+ (propsAndState: PropsAndState) =>
+ propsAndState.drafts[draftKeyFromThreadID(threadID)],
(
pendingUploads: ?{ [localUploadID: string]: PendingMultimediaUpload },
draft: ?string,
@@ -1055,14 +1054,13 @@
}
setDraft(threadID: string, draft: string) {
- this.setState(prevState => {
- const newThreadID = this.getRealizedOrPendingThreadID(threadID);
- return {
- drafts: {
- ...prevState.drafts,
- [newThreadID]: draft,
- },
- };
+ const newThreadID = this.getRealizedOrPendingThreadID(threadID);
+ this.props.dispatch({
+ type: 'UPDATE_DRAFT',
+ payload: {
+ key: draftKeyFromThreadID(newThreadID),
+ text: draft,
+ },
});
}
@@ -1212,7 +1210,10 @@
render() {
const { activeChatThreadID } = this.props;
const inputState = activeChatThreadID
- ? this.inputStateSelector(activeChatThreadID)(this.state)
+ ? this.inputStateSelector(activeChatThreadID)({
+ ...this.state,
+ ...this.props,
+ })
: null;
return (
@@ -1233,6 +1234,7 @@
const activeChatThreadID = useSelector(
state => state.navInfo.activeChatThreadID,
);
+ const drafts = useSelector(state => state.draftStore.drafts);
const viewerID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
);
@@ -1273,6 +1275,7 @@