1- import React from 'react' ;
1+ import React , { PropsWithChildren } from 'react' ;
22import emojiRegex from 'emoji-regex' ;
33import * as linkify from 'linkifyjs' ;
44//@ts -expect-error
@@ -8,7 +8,7 @@ import ReactMarkdown from 'react-markdown/with-html';
88
99import type { UserResponse } from 'stream-chat' ;
1010
11- import type { UnknownType } from '../types/types' ;
11+ import type { DefaultUserType , UnknownType } from '../types/types' ;
1212
1313export const isOnlyEmojis = ( text ?: string ) => {
1414 if ( ! text ) return false ;
@@ -107,7 +107,11 @@ const emojiMarkdownPlugin = () => {
107107 return transform ;
108108} ;
109109
110- const mentionsMarkdownPlugin = ( mentioned_users : UserResponse [ ] ) => ( ) => {
110+ const mentionsMarkdownPlugin = <
111+ Us extends DefaultUserType < Us > = DefaultUserType
112+ > (
113+ mentioned_users : UserResponse < Us > [ ] ,
114+ ) => ( ) => {
111115 const mentioned_usernames = mentioned_users
112116 . map ( ( user ) => user . name || user . id )
113117 . filter ( Boolean )
@@ -138,16 +142,18 @@ const mentionsMarkdownPlugin = (mentioned_users: UserResponse[]) => () => {
138142 return transform ;
139143} ;
140144
141- type MentionProps = { mentioned_user : UserResponse } ;
145+ type MentionProps < Us extends DefaultUserType < Us > = DefaultUserType > = {
146+ mentioned_user : UserResponse < Us > ;
147+ } ;
142148
143- const Mention : React . FC < MentionProps > = ( { children } ) => (
144- < span className = 'str-chat__message-mention' > { children } </ span >
145- ) ;
149+ const Mention = < Us extends DefaultUserType < Us > = DefaultUserType > (
150+ props : PropsWithChildren < Us > ,
151+ ) => < span className = 'str-chat__message-mention' > { props . children } </ span > ;
146152
147- export const renderText = (
153+ export const renderText = < Us extends DefaultUserType < Us > = DefaultUserType > (
148154 text ?: string ,
149- mentioned_users ?: UserResponse [ ] ,
150- MentionComponent : React . ComponentType < MentionProps > = Mention ,
155+ mentioned_users ?: UserResponse < Us > [ ] ,
156+ MentionComponent : React . ComponentType < MentionProps < Us > > = Mention ,
151157) => {
152158 // take the @ mentions and turn them into markdown?
153159 // translate links
0 commit comments