Skip to content

Commit c01717b

Browse files
authored
Merge pull request #2771 from GetStream/develop
Next Release
2 parents a932d07 + b26b98c commit c01717b

File tree

20 files changed

+295
-55
lines changed

20 files changed

+295
-55
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,7 @@ const ChannelWithContext = <
852852
setThreadMessages(updatedThreadMessages);
853853
}
854854

855-
if (
856-
channel &&
857-
thread?.id &&
858-
event.message?.id === thread.id &&
859-
!threadInstance &&
860-
!thread.poll_id
861-
) {
855+
if (channel && thread?.id && event.message?.id === thread.id && !threadInstance) {
862856
const updatedThread = channel.state.formatMessage(event.message);
863857
setThread(updatedThread);
864858
}

package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export type LatestMessagePreview<
4040
export type LatestMessagePreviewSelectorReturnType = {
4141
createdBy?: UserResponse | null;
4242
latestVotesByOption?: Record<string, PollVote[]>;
43+
name?: string;
4344
};
4445

4546
const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
4647
nextValue: PollState<StreamChatGenerics>,
4748
): LatestMessagePreviewSelectorReturnType => ({
4849
createdBy: nextValue.created_by,
4950
latestVotesByOption: nextValue.latest_votes_by_option,
51+
name: nextValue.name,
5052
});
5153

5254
const getMessageSenderName = <
@@ -145,8 +147,8 @@ const getLatestMessageDisplayText = <
145147
{ bold: false, text: t('🏙 Attachment...') },
146148
];
147149
}
148-
if (message.poll && pollState) {
149-
const { createdBy, latestVotesByOption } = pollState;
150+
if (message.poll_id && pollState) {
151+
const { createdBy, latestVotesByOption, name } = pollState;
150152
let latestVotes;
151153
if (latestVotesByOption) {
152154
latestVotes = Object.values(latestVotesByOption)
@@ -161,7 +163,7 @@ const getLatestMessageDisplayText = <
161163
}
162164
const previewMessage = `${
163165
client.userID === previewUser?.id ? 'You' : previewUser?.name
164-
} ${previewAction}: ${message.poll.name}`;
166+
} ${previewAction}: ${name}`;
165167
return [
166168
{ bold: false, text: '📊 ' },
167169
{ bold: false, text: previewMessage },
@@ -311,7 +313,7 @@ export const useLatestMessagePreview = <
311313
const poll = client.polls.fromState(pollId);
312314
const pollState: LatestMessagePreviewSelectorReturnType =
313315
useStateStore(poll?.state, selector) ?? {};
314-
const { createdBy, latestVotesByOption } = pollState;
316+
const { createdBy, latestVotesByOption, name } = pollState;
315317

316318
useEffect(
317319
() =>
@@ -326,7 +328,15 @@ export const useLatestMessagePreview = <
326328
}),
327329
),
328330
// eslint-disable-next-line react-hooks/exhaustive-deps
329-
[channelLastMessageString, forceUpdate, readEvents, readStatus, latestVotesByOption, createdBy],
331+
[
332+
channelLastMessageString,
333+
forceUpdate,
334+
readEvents,
335+
readStatus,
336+
latestVotesByOption,
337+
createdBy,
338+
name,
339+
],
330340
);
331341

332342
return latestMessagePreview;

package/src/components/Chat/hooks/handleEventToSyncDB.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,14 @@ export const handleEventToSyncDB = <
233233
'poll.vote_removed',
234234
].includes(type)
235235
) {
236-
const poll = event.poll;
236+
const { poll, poll_vote, type } = event;
237237
if (poll) {
238238
return updatePollMessage({
239+
eventType: type,
239240
flush,
240241
poll,
242+
poll_vote,
243+
userID: client?.userID || '',
241244
});
242245
}
243246
}

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const MessageContentWithContext = <
149149

150150
const {
151151
theme: {
152-
colors: { blue_alice, grey_gainsboro, grey_whisper, transparent, white },
152+
colors: { blue_alice, grey_whisper, light_gray, transparent, white_snow },
153153
messageSimple: {
154154
content: {
155155
container: {
@@ -214,20 +214,20 @@ const MessageContentWithContext = <
214214

215215
const isMessageReceivedOrErrorType = !isMyMessage || error;
216216

217-
let backgroundColor = senderMessageBackgroundColor || grey_gainsboro;
217+
let backgroundColor = senderMessageBackgroundColor ?? light_gray;
218218
if (onlyEmojis && !message.quoted_message) {
219219
backgroundColor = transparent;
220220
} else if (otherAttachments.length) {
221221
if (otherAttachments[0].type === 'giphy') {
222-
backgroundColor = message.quoted_message ? grey_gainsboro : transparent;
222+
backgroundColor = message.quoted_message ? light_gray : transparent;
223223
} else {
224224
backgroundColor = blue_alice;
225225
}
226226
} else if (isMessageReceivedOrErrorType) {
227-
backgroundColor = receiverMessageBackgroundColor || white;
227+
backgroundColor = receiverMessageBackgroundColor ?? white_snow;
228228
}
229229

230-
const repliesCurveColor = !isMessageReceivedOrErrorType ? backgroundColor : grey_gainsboro;
230+
const repliesCurveColor = !isMessageReceivedOrErrorType ? backgroundColor : light_gray;
231231

232232
const getBorderRadius = () => {
233233
// enum('top', 'middle', 'bottom', 'single')

package/src/components/Message/MessageSimple/MessageReplies.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const styles = StyleSheet.create({
3232
},
3333
messageRepliesCurve: {
3434
borderTopWidth: 0,
35-
borderWidth: 1,
35+
borderWidth: 2,
3636
height: 16,
3737
width: 16,
3838
},
@@ -181,13 +181,15 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
181181
message: prevMessage,
182182
noBorder: prevNoBorder,
183183
onOpenThread: prevOnOpenThread,
184+
repliesCurveColor: prevRepliesCurveColor,
184185
t: prevT,
185186
threadList: prevThreadList,
186187
} = prevProps;
187188
const {
188189
message: nextMessage,
189190
noBorder: nextNoBorder,
190191
onOpenThread: nextOnOpenThread,
192+
repliesCurveColor: nextRepliesCurveColor,
191193
t: nextT,
192194
threadList: nextThreadList,
193195
} = nextProps;
@@ -201,6 +203,9 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
201203
const noBorderEqual = prevNoBorder === nextNoBorder;
202204
if (!noBorderEqual) return false;
203205

206+
const repliesCurveColorEqual = prevRepliesCurveColor === nextRepliesCurveColor;
207+
if (!repliesCurveColorEqual) return false;
208+
204209
const tEqual = prevT === nextT;
205210
if (!tEqual) return false;
206211

package/src/components/MessageOverlay/MessageOverlay.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const MessageOverlayWithContext = <
170170
);
171171

172172
const {
173-
colors: { blue_alice, grey_gainsboro, grey_whisper, transparent },
173+
colors: { blue_alice, grey_gainsboro, grey_whisper, light_gray, transparent, white_snow },
174174
messageSimple: {
175175
content: {
176176
container: { borderRadiusL, borderRadiusS },
@@ -364,8 +364,8 @@ const MessageOverlayWithContext = <
364364
: grey_gainsboro
365365
: blue_alice
366366
: alignment === 'left'
367-
? receiverMessageBackgroundColor
368-
: senderMessageBackgroundColor,
367+
? receiverMessageBackgroundColor ?? white_snow
368+
: senderMessageBackgroundColor ?? light_gray,
369369
borderBottomLeftRadius:
370370
(groupStyle === 'left_bottom' || groupStyle === 'left_single') &&
371371
(!hasThreadReplies || threadList)

package/src/components/Poll/CreatePollContent.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ export const CreatePollContent = () => {
164164
{t<string>('Multiple answers')}
165165
</Text>
166166
<Switch
167-
onValueChange={() => setMultipleAnswersAllowed(!multipleAnswersAllowed)}
167+
onValueChange={() => {
168+
if (multipleAnswersAllowed) {
169+
setMaxVotesPerPersonEnabled(false);
170+
}
171+
setMultipleAnswersAllowed(!multipleAnswersAllowed);
172+
}}
168173
value={multipleAnswersAllowed}
169174
/>
170175
</View>

package/src/components/Reply/Reply.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import dayjs from 'dayjs';
66

77
import merge from 'lodash/merge';
88

9-
import type { Attachment } from 'stream-chat';
9+
import type { Attachment, PollState } from 'stream-chat';
1010

11+
import { useChatContext } from '../../contexts';
1112
import { useMessageContext } from '../../contexts/messageContext/MessageContext';
1213
import {
1314
MessageInputContext,
@@ -22,6 +23,7 @@ import {
2223
TranslationContextValue,
2324
useTranslationContext,
2425
} from '../../contexts/translationContext/TranslationContext';
26+
import { useStateStore } from '../../hooks';
2527
import { DefaultStreamChatGenerics, FileTypes } from '../../types/types';
2628
import { getResizedImageUrl } from '../../utils/getResizedImageUrl';
2729
import { getTrimmedAttachmentTitle } from '../../utils/getTrimmedAttachmentTitle';
@@ -31,6 +33,7 @@ import { FileIcon as FileIconDefault } from '../Attachment/FileIcon';
3133
import { VideoThumbnail } from '../Attachment/VideoThumbnail';
3234
import { MessageAvatar as MessageAvatarDefault } from '../Message/MessageSimple/MessageAvatar';
3335
import { MessageTextContainer } from '../Message/MessageSimple/MessageTextContainer';
36+
import { MessageType } from '../MessageList/hooks/useMessageList';
3437

3538
const styles = StyleSheet.create({
3639
container: {
@@ -72,6 +75,16 @@ const styles = StyleSheet.create({
7275
},
7376
});
7477

78+
export type ReplySelectorReturnType = {
79+
name?: string;
80+
};
81+
82+
const selector = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
83+
nextValue: PollState<StreamChatGenerics>,
84+
): ReplySelectorReturnType => ({
85+
name: nextValue.name,
86+
});
87+
7588
type ReplyPropsWithContext<
7689
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
7790
> = Pick<MessageInputContextValue<StreamChatGenerics>, 'quotedMessage'> &
@@ -134,6 +147,7 @@ const ReplyWithContext = <
134147
>(
135148
props: ReplyPropsWithContext<StreamChatGenerics>,
136149
) => {
150+
const { client } = useChatContext();
137151
const {
138152
attachmentSize = 40,
139153
FileAttachmentIcon,
@@ -167,6 +181,9 @@ const ReplyWithContext = <
167181
},
168182
} = useTheme();
169183

184+
const poll = client.polls.fromState((quotedMessage as MessageType)?.poll_id ?? '');
185+
const { name: pollName }: ReplySelectorReturnType = useStateStore(poll?.state, selector) ?? {};
186+
170187
const messageText = typeof quotedMessage === 'boolean' ? '' : quotedMessage.text || '';
171188

172189
const emojiOnlyText = useMemo(() => {
@@ -262,8 +279,8 @@ const ReplyWithContext = <
262279
text:
263280
quotedMessage.type === 'deleted'
264281
? `_${t('Message deleted')}_`
265-
: quotedMessage.poll
266-
? `📊 ${quotedMessage.poll.name}`
282+
: pollName
283+
? `📊 ${pollName}`
267284
: quotedMessage.text
268285
? quotedMessage.text.length > 170
269286
? `${quotedMessage.text.slice(0, 170)}...`

package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ exports[`Thread should match thread snapshot 1`] = `
416416
"overflow": "hidden",
417417
},
418418
{
419-
"backgroundColor": "#F2F2F2",
419+
"backgroundColor": "#FCFCFC",
420420
"borderBottomLeftRadius": 0,
421421
"borderBottomRightRadius": 16,
422422
"borderColor": "#ECEBEB",
@@ -742,7 +742,7 @@ exports[`Thread should match thread snapshot 1`] = `
742742
"overflow": "hidden",
743743
},
744744
{
745-
"backgroundColor": "#F2F2F2",
745+
"backgroundColor": "#FCFCFC",
746746
"borderBottomLeftRadius": 0,
747747
"borderBottomRightRadius": 16,
748748
"borderColor": "#ECEBEB",
@@ -1068,7 +1068,7 @@ exports[`Thread should match thread snapshot 1`] = `
10681068
"overflow": "hidden",
10691069
},
10701070
{
1071-
"backgroundColor": "#F2F2F2",
1071+
"backgroundColor": "#FCFCFC",
10721072
"borderBottomLeftRadius": 0,
10731073
"borderBottomRightRadius": 16,
10741074
"borderColor": "#ECEBEB",
@@ -1422,7 +1422,7 @@ exports[`Thread should match thread snapshot 1`] = `
14221422
"overflow": "hidden",
14231423
},
14241424
{
1425-
"backgroundColor": "#F2F2F2",
1425+
"backgroundColor": "#FCFCFC",
14261426
"borderBottomLeftRadius": 0,
14271427
"borderBottomRightRadius": 16,
14281428
"borderColor": "#ECEBEB",

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,8 @@ export const defaultTheme: Theme = {
12181218
metaText: {
12191219
fontSize: 12,
12201220
},
1221-
receiverMessageBackgroundColor: Colors.white_smoke,
12221221
replyBorder: {},
12231222
replyContainer: {},
1224-
senderMessageBackgroundColor: Colors.grey_gainsboro,
12251223
textContainer: {
12261224
onlyEmojiMarkdown: { text: { fontSize: 50 } },
12271225
},

package/src/store/QuickSqliteClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { PreparedQueries, Table } from './types';
3030
*
3131
*/
3232
export class QuickSqliteClient {
33-
static dbVersion = 6;
33+
static dbVersion = 7;
3434

3535
static dbName = DB_NAME;
3636
static dbLocation = DB_LOCATION;

package/src/store/apis/getChannelMessages.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
88
import { isBlockedMessage } from '../../utils/utils';
99
import { mapStorableToMessage } from '../mappers/mapStorableToMessage';
1010
import { QuickSqliteClient } from '../QuickSqliteClient';
11-
import type { TableRowJoinedUser } from '../types';
11+
import { createSelectQuery } from '../sqlite-utils/createSelectQuery';
12+
import type { TableRow, TableRowJoinedUser } from '../types';
1213

1314
export const getChannelMessages = <
1415
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -35,6 +36,21 @@ export const getChannelMessages = <
3536
}
3637
messageIdVsReactions[reaction.messageId].push(reaction);
3738
});
39+
const messageIdsVsPolls: Record<string, TableRow<'poll'>> = {};
40+
const pollsById: Record<string, TableRow<'poll'>> = {};
41+
const messagesWithPolls = messageRows.filter((message) => !!message.poll_id);
42+
const polls = QuickSqliteClient.executeSql.apply(
43+
null,
44+
createSelectQuery('poll', ['*'], {
45+
id: messagesWithPolls.map((message) => message.poll_id),
46+
}),
47+
);
48+
polls.forEach((poll) => {
49+
pollsById[poll.id] = poll;
50+
});
51+
messagesWithPolls.forEach((message) => {
52+
messageIdsVsPolls[message.poll_id] = pollsById[message.poll_id];
53+
});
3854

3955
// Populate the messages.
4056
const cidVsMessages: Record<string, MessageResponse<StreamChatGenerics>[]> = {};
@@ -48,6 +64,7 @@ export const getChannelMessages = <
4864
mapStorableToMessage<StreamChatGenerics>({
4965
currentUserId,
5066
messageRow: m,
67+
pollRow: messageIdsVsPolls[m.poll_id],
5168
reactionRows: messageIdVsReactions[m.id],
5269
}),
5370
);

package/src/store/apis/updateMessage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export const updateMessage = ({
3030
return queries;
3131
}
3232

33-
const storableMessage = mapMessageToStorable(message);
33+
const storableMessage = mapMessageToStorable({
34+
...message,
35+
});
3436

3537
queries.push(
3638
createUpdateQuery('messages', storableMessage, {

0 commit comments

Comments
 (0)