Skip to content

Commit 50f9fdf

Browse files
committed
include support for name mentions
1 parent 0b2c75d commit 50f9fdf

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/components/Channel/Channel.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ const ChannelInner = <
495495
text,
496496
} = message;
497497

498+
// channel.sendMessage expects an array of user id strings
498499
const mentions = isUserResponseArray(mentioned_users)
499500
? mentioned_users.map(({ id }) => id)
500501
: mentioned_users;
@@ -549,23 +550,18 @@ const ChannelInner = <
549550
text: string,
550551
attachments: MessageAttachments<At>,
551552
parent: MessageResponse<At, Ch, Co, Me, Re, Us> | undefined,
552-
mentioned_users: string[],
553+
mentioned_users: UserResponse<Us>[],
553554
) => {
554555
// create a preview of the message
555556
const clientSideID = `${client.userID}-${uuidv4()}`;
556557

557-
// channel.state.addMessageSorted expects an array of user responses
558-
const mappedMentions = mentioned_users.map((mention) => ({
559-
id: mention,
560-
}));
561-
562558
return ({
563559
__html: text,
564560
attachments,
565561
created_at: new Date(),
566562
html: text,
567563
id: clientSideID,
568-
mentioned_users: mappedMentions,
564+
mentioned_users,
569565
reactions: [],
570566
status: 'sending',
571567
text,

src/components/MessageInput/MessageInput.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import React from 'react';
22

33
import { MessageInputLarge } from './MessageInputLarge';
44

5-
import type { Attachment, Channel, SendFileAPIResponse } from 'stream-chat';
5+
import type {
6+
Attachment,
7+
Channel,
8+
SendFileAPIResponse,
9+
UserResponse,
10+
} from 'stream-chat';
611

712
import type { FileUpload, ImageUpload } from './hooks/messageInput';
813
import type { SendButtonProps } from './icons';
@@ -101,7 +106,7 @@ export type MessageInputProps<
101106
overrideSubmitHandler?: (
102107
message: {
103108
attachments: Attachment<At>[];
104-
mentioned_users: string[];
109+
mentioned_users: UserResponse<Us>[];
105110
text: string;
106111
parent?: StreamMessage<At, Ch, Co, Ev, Me, Re, Us>;
107112
},

src/components/MessageInput/__tests__/MessageInput.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ const ActiveChannelSetter = ({ activeChannel }) => {
700700
expect.objectContaining(image),
701701
expect.objectContaining(file),
702702
]),
703-
mentioned_users: [userId],
703+
mentioned_users: [{ id: userId, name: username }],
704704
text: message.text,
705705
}),
706706
);

src/components/MessageInput/hooks/messageInput.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,10 @@ export const useMessageInput = <
679679
// and allows users to easily undo any accidental deletion
680680
const actualMentionedUsers = Array.from(
681681
new Set(
682-
mentioned_users
683-
.filter(
684-
({ id, name }) =>
685-
text.includes(`@${id}`) || text.includes(`@${name}`),
686-
)
687-
.map(({ id }) => id),
682+
mentioned_users.filter(
683+
({ id, name }) =>
684+
text.includes(`@${id}`) || text.includes(`@${name}`),
685+
),
688686
),
689687
);
690688

src/context/ChannelContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export type MessageToSend<
8080
> = {
8181
attachments?: MessageAttachments<At>;
8282
id?: string;
83-
mentioned_users?: string[];
83+
mentioned_users?: UserResponse<Us>[];
8484
parent?: MessageResponse<At, Ch, Co, Me, Re, Us>;
8585
parent_id?: string;
8686
status?: string;

0 commit comments

Comments
 (0)