Skip to content

Commit d32a221

Browse files
Removing MessagesContext and ThreadContext
1 parent ad3ef0f commit d32a221

File tree

10 files changed

+49
-123
lines changed

10 files changed

+49
-123
lines changed

src/components/Channel/Channel.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ import LoadingIndicatorDefault from '../Indicators/LoadingIndicator';
1313
import KeyboardCompatibleViewDefault from '../KeyboardCompatibleView/KeyboardCompatibleView';
1414
import SuggestionsProvider from '../SuggestionsProvider/SuggestionsProvider';
1515

16-
import {
17-
ChannelContext,
18-
ChatContext,
19-
MessagesContext,
20-
ThreadContext,
21-
TranslationContext,
22-
} from '../../context';
16+
import { ChannelContext, ChatContext, TranslationContext } from '../../context';
2317
import { emojiData as emojiDataDefault } from '../../utils/utils';
2418

2519
/**
@@ -458,48 +452,42 @@ const Channel = (props) => {
458452
};
459453

460454
const channelContext = {
455+
Attachment: props.Attachment,
461456
channel,
457+
clearEditingState,
458+
closeThread,
462459
disabled: channel?.data?.frozen && disableIfFrozenChannel,
460+
editing,
461+
editMessage,
462+
emojiData,
463463
EmptyStateIndicator,
464464
error,
465465
eventHistory,
466+
hasMore,
466467
lastRead,
467468
loading,
468-
markRead: markReadThrottled,
469-
members,
470-
read,
471-
setLastRead,
472-
typing,
473-
watcherCount,
474-
watchers,
475-
};
476-
477-
const messagesContext = {
478-
Attachment: props.Attachment,
479-
clearEditingState,
480-
editing,
481-
editMessage,
482-
emojiData,
483-
hasMore,
484469
loadingMore,
485470
loadMore: loadMoreThrottled,
471+
loadMoreThread,
472+
markRead: markReadThrottled,
473+
members,
486474
Message: props.Message,
487475
messages,
476+
openThread,
477+
read,
488478
removeMessage,
489479
retrySendMessage,
490480
sendMessage,
491481
setEditingState,
492-
updateMessage,
493-
};
494-
495-
const threadContext = {
496-
closeThread,
497-
loadMoreThread,
498-
openThread,
482+
setLastRead,
499483
thread,
500484
threadHasMore,
501485
threadLoadingMore,
502486
threadMessages,
487+
typing,
488+
updateMessage,
489+
watcherCount,
490+
watchers,
503491
};
504492

505493
if (!channel || error) {
@@ -521,11 +509,7 @@ const Channel = (props) => {
521509
return (
522510
<KeyboardCompatibleView enabled={!disableKeyboardCompatibleView}>
523511
<ChannelContext.Provider value={channelContext}>
524-
<MessagesContext.Provider value={messagesContext}>
525-
<ThreadContext.Provider value={threadContext}>
526-
<SuggestionsProvider>{children}</SuggestionsProvider>
527-
</ThreadContext.Provider>
528-
</MessagesContext.Provider>
512+
<SuggestionsProvider>{children}</SuggestionsProvider>
529513
</ChannelContext.Provider>
530514
</KeyboardCompatibleView>
531515
);

src/components/Message/Message.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import PropTypes from 'prop-types';
44

55
import MessageSimple from './MessageSimple/MessageSimple';
66

7-
import {
8-
ChannelContext,
9-
ChatContext,
10-
KeyboardContext,
11-
MessagesContext,
12-
} from '../../context';
7+
import { ChannelContext, ChatContext, KeyboardContext } from '../../context';
138

149
/**
15-
* Since this component doesn't consume `messages` from `MessagesContext`,
10+
* Since this component doesn't consume `messages` from `ChannelContext`,
1611
* we memoized and broke it up to prevent new messages from re-rendering
1712
* each individual Message component.
1813
*/
@@ -211,17 +206,18 @@ DefaultMessageWithContext.displayName = 'messageWithContext';
211206
* @example ../docs/Message.md
212207
*/
213208
const DefaultMessage = (props) => {
214-
const { channel, disabled } = useContext(ChannelContext);
215209
const { client } = useContext(ChatContext);
216210
const { dismissKeyboard } = useContext(KeyboardContext);
217211
const {
212+
channel,
213+
disabled,
218214
editing,
219215
emojiData,
220216
removeMessage,
221217
retrySendMessage,
222218
setEditingState,
223219
updateMessage,
224-
} = useContext(MessagesContext);
220+
} = useContext(ChannelContext);
225221

226222
return (
227223
<DefaultMessageWithContext

src/components/Message/MessageSimple/MessageContent.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import ReactionPickerWrapper from '../../Reaction/ReactionPickerWrapper';
1717
import {
1818
ChannelContext,
1919
MessageContentContext,
20-
MessagesContext,
21-
ThreadContext,
2220
TranslationContext,
2321
} from '../../../context';
2422
import { themed } from '../../../styles/theme';
@@ -95,7 +93,7 @@ const MetaText = styled.Text`
9593
`;
9694

9795
/**
98-
* Since this component doesn't consume `messages` from `MessagesContext`,
96+
* Since this component doesn't consume `messages` from `ChannelContext`,
9997
* we memoized and broke it up to prevent new messages from re-rendering
10098
* each individual MessageContent component.
10199
*/
@@ -157,7 +155,7 @@ const MessageContentWithContext = React.memo((props) => {
157155
threadList,
158156
} = props;
159157

160-
const { openThread } = useContext(ThreadContext);
158+
const { openThread } = useContext(ChannelContext);
161159
const { t, tDateTimeParser } = useContext(TranslationContext);
162160

163161
const actionSheetRef = useRef(null);
@@ -382,12 +380,12 @@ MessageContentWithContext.displayName = 'message.contentWithContext';
382380
* Child of MessageSimple that displays a message's content.
383381
*/
384382
const MessageContent = (props) => {
385-
const { disabled } = useContext(ChannelContext);
386383
const {
387384
Attachment = DefaultAttachment,
385+
disabled,
388386
Message,
389387
retrySendMessage,
390-
} = useContext(MessagesContext);
388+
} = useContext(ChannelContext);
391389

392390
return (
393391
<MessageContentWithContext

src/components/MessageInput/MessageInput.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import {
2222
ChannelContext,
2323
ChatContext,
2424
KeyboardContext,
25-
MessagesContext,
2625
SuggestionsContext,
27-
ThreadContext,
2826
TranslationContext,
2927
} from '../../context';
3028
import iconClose from '../../images/icons/icon_close.png';
@@ -80,37 +78,34 @@ const InputBoxContainer = styled.View`
8078
* [Channel Context](https://getstream.github.io/stream-chat-react-native/#channelcontext),
8179
* [Chat Context](https://getstream.github.io/stream-chat-react-native/#chatcontext),
8280
* [Keyboard Context](https://getstream.github.io/stream-chat-react-native/#keyboardcontext),
83-
* [Messages Context](https://getstream.github.io/stream-chat-react-native/#messagescontext),
8481
* [Suggestions Context](https://getstream.github.io/stream-chat-react-native/#suggestionscontext),
85-
* [Thread Context](https://getstream.github.io/stream-chat-react-native/#threadcontext), and
8682
* [Translation Context](https://getstream.github.io/stream-chat-react-native/#translationcontext)
8783
*
8884
* @example ../docs/MessageInput.md
8985
*/
9086
const MessageInput = (props) => {
9187
const channelContext = useContext(ChannelContext);
92-
const { channel, disabled = false, members, watchers } = channelContext;
9388

9489
const chatContext = useContext(ChatContext);
9590
const { client } = chatContext;
9691

9792
const keyboardContext = useContext(KeyboardContext);
9893
const { dismissKeyboard } = keyboardContext;
9994

100-
const messagesContext = useContext(MessagesContext);
10195
const {
96+
channel,
10297
clearEditingState,
98+
disabled = false,
10399
editing,
104100
editMessage,
101+
members,
105102
sendMessage: sendMessageContext,
106-
} = messagesContext;
103+
watchers,
104+
} = channelContext;
107105

108106
const suggestionsContext = useContext(SuggestionsContext);
109107
const { setInputBoxContainerRef } = suggestionsContext;
110108

111-
// TODO: not sure if this is actually needed but adding it in from the previously all encompassing usage of withChannelContext
112-
const threadContext = useContext(ThreadContext);
113-
114109
const translationContext = useContext(TranslationContext);
115110
const { t } = translationContext;
116111

@@ -144,9 +139,7 @@ const MessageInput = (props) => {
144139
...channelContext,
145140
...chatContext,
146141
...keyboardContext,
147-
...messagesContext,
148142
...suggestionsContext,
149-
...threadContext,
150143
...translationContext,
151144
};
152145

src/components/MessageInput/SendButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useContext } from 'react';
22
import styled from '@stream-io/styled-components';
33
import PropTypes from 'prop-types';
44

5-
import { MessagesContext } from '../../context';
5+
import { ChannelContext } from '../../context';
66
import iconEdit from '../../images/icons/icon_edit.png';
77
import iconSendNewMessage from '../../images/icons/icon_new_message.png';
88
import { themed } from '../../styles/theme';
@@ -24,7 +24,7 @@ const SendButtonIcon = styled.Image`
2424
* @example ../docs/SendButton.md
2525
*/
2626
const SendButton = ({ disabled = false, sendMessage }) => {
27-
const { editing } = useContext(MessagesContext);
27+
const { editing } = useContext(ChannelContext);
2828
return (
2929
<Container disabled={disabled} onPress={sendMessage} testID='send-button'>
3030
<SendButtonIcon source={editing ? iconEdit : iconSendNewMessage} />

src/components/MessageList/MessageList.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import { getLastReceivedMessage } from './utils/getLastReceivedMessage';
1515

1616
import DefaultMessage from '../Message/Message';
1717

18-
import {
19-
ChannelContext,
20-
ChatContext,
21-
MessagesContext,
22-
ThreadContext,
23-
TranslationContext,
24-
} from '../../context';
18+
import { ChannelContext, ChatContext, TranslationContext } from '../../context';
2519

2620
const ListContainer = styled.FlatList`
2721
flex: 1;
@@ -52,8 +46,6 @@ const ErrorNotification = styled.View`
5246
*
5347
* [ChannelContext](https://getstream.github.io/stream-chat-react-native/#channelcontext)
5448
* [ChatContext](https://getstream.github.io/stream-chat-react-native/#chatcontext)
55-
* [MessagesContext](https://getstream.github.io/stream-chat-react-native/#messagescontext)
56-
* [ThreadContext](https://getstream.github.io/stream-chat-react-native/#threadcontext)
5749
* [TranslationContext](https://getstream.github.io/stream-chat-react-native/#translationcontext)
5850
*
5951
* @example ../docs/MessageList.md
@@ -76,17 +68,18 @@ const MessageList = (props) => {
7668
TypingIndicator = DefaultTypingIndicator,
7769
} = props;
7870

79-
const { channel, disabled, EmptyStateIndicator, markRead } = useContext(
80-
ChannelContext,
81-
);
82-
const { client, isOnline } = useContext(ChatContext);
8371
const {
72+
channel,
8473
clearEditingState,
74+
disabled,
8575
editing,
76+
EmptyStateIndicator,
8677
loadMore: mainLoadMore,
78+
loadMoreThread,
79+
markRead,
8780
Message: MessageFromContext,
88-
} = useContext(MessagesContext);
89-
const { loadMoreThread } = useContext(ThreadContext);
81+
} = useContext(ChannelContext);
82+
const { client, isOnline } = useContext(ChatContext);
9083
const { t } = useContext(TranslationContext);
9184

9285
const Message = MessageFromProps || MessageFromContext;

src/components/MessageList/hooks/useMessageList.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ import { getGroupStyles } from '../utils/getGroupStyles';
44
import { getReadStates } from '../utils/getReadStates';
55
import { insertDates } from '../utils/insertDates';
66

7-
import {
8-
ChannelContext,
9-
MessagesContext,
10-
ThreadContext,
11-
} from '../../../context';
7+
import { ChannelContext } from '../../../context';
128

139
export const useMessageList = ({ noGroupByUser, threadList }) => {
14-
const { read } = useContext(ChannelContext);
15-
const { messages } = useContext(MessagesContext);
16-
const { threadMessages } = useContext(ThreadContext);
10+
const { messages, read, threadMessages } = useContext(ChannelContext);
1711

1812
const messageList = threadList ? threadMessages : messages;
1913
const readList = threadList ? {} : read;

src/components/Thread/Thread.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import DefaultMessage from '../Message/Message';
66
import DefaultMessageInput from '../MessageInput/MessageInput';
77
import DefaultMessageList from '../MessageList/MessageList';
88

9-
import {
10-
ChannelContext,
11-
ChatContext,
12-
MessagesContext,
13-
ThreadContext,
14-
TranslationContext,
15-
} from '../../context';
9+
import { ChannelContext, ChatContext, TranslationContext } from '../../context';
1610
import { themed } from '../../styles/theme';
1711

1812
const NewThread = styled.View`
@@ -44,15 +38,15 @@ const Thread = (props) => {
4438
const translationContext = useContext(TranslationContext);
4539
const { t } = translationContext;
4640
const channelContext = useContext(ChannelContext);
47-
const { channel } = channelContext;
48-
const { Message: MessageFromContext } = useContext(MessagesContext);
4941
const {
42+
channel,
5043
loadMoreThread,
44+
Message: MessageFromContext,
5145
thread,
5246
threadHasMore = true,
5347
threadLoadingMore,
5448
threadMessages,
55-
} = useContext(ThreadContext);
49+
} = channelContext;
5650
const chatContext = useContext(ChatContext);
5751
const {
5852
autoFocus = true,

src/context.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ export const KeyboardContext = React.createContext({
77
dismissKeyboard: Keyboard.dismiss,
88
});
99
export const MessageContentContext = React.createContext({});
10-
export const MessagesContext = React.createContext({});
1110
export const SuggestionsContext = React.createContext({});
12-
export const ThreadContext = React.createContext({});
1311
export const TranslationContext = React.createContext({
1412
t: () => 'Value not found',
1513
});
@@ -30,18 +28,10 @@ export function withMessageContentContext(OriginalComponent) {
3028
return getContextAwareComponent(MessageContentContext, OriginalComponent);
3129
}
3230

33-
export function withMessagesContext(OriginalComponent) {
34-
return getContextAwareComponent(MessagesContext, OriginalComponent);
35-
}
36-
3731
export function withSuggestionsContext(OriginalComponent) {
3832
return getContextAwareComponent(SuggestionsContext, OriginalComponent);
3933
}
4034

41-
export function withThreadContext(OriginalComponent) {
42-
return getContextAwareComponent(ThreadContext, OriginalComponent);
43-
}
44-
4535
export function withTranslationContext(OriginalComponent) {
4636
const ContextAwareComponent = getContextAwareComponent(
4737
TranslationContext,

0 commit comments

Comments
 (0)