1- import type {
2- APIMessageInteraction ,
3- APIRole ,
4- APIUser ,
5- Snowflake ,
6- } from "discord-api-types/v10" ;
7- import { MessageType } from "discord-api-types/v10" ;
8- import Moment from "moment" ;
9- import React , { memo , useMemo , useRef } from "react" ;
10- import ChatTag from "../../ChatTag" ;
11- import Content from "../../Content" ;
12- import Tooltip from "../../Tooltip" ;
1+ import React from "react" ;
132import { useConfig } from "../../core/ConfigContext" ;
143import type { ChatMessage } from "../../types" ;
15- import type { GetAvatarOptions } from "../../utils/getAvatar" ;
16- import getAvatar from "../../utils/getAvatar" ;
17- import getDisplayName from "../../utils/getDisplayName" ;
18- import LargeTimestamp from "../LargeTimestamp" ;
19- import MessageAuthor from "../MessageAuthor" ;
20- import * as Styles from "../style/message" ;
21-
22- interface ReplyInfoProps {
23- channelId : Snowflake ;
24- referencedMessage : ChatMessage [ "referenced_message" ] ;
25- mentioned ?: boolean ;
26- interaction : APIMessageInteraction | undefined ;
27- isContextMenuInteraction ?: boolean ;
28- }
29-
30- function getMiniAvatarUrl ( user : APIUser ) {
31- const getAvatarSettings : GetAvatarOptions = {
32- size : 16 ,
33- } ;
34-
35- return getAvatar ( user , getAvatarSettings ) ;
36- }
37-
38- const FLAG_CROSSPOST = 1 << 1 ;
39-
40- const ReplyInfo = memo ( ( props : ReplyInfoProps ) => {
41- const user = props . interaction
42- ? props . interaction . user
43- : props . referencedMessage ?. author ;
44-
45- const { resolveRole, resolveChannel, resolveMember, avatarUrlOverride } =
46- useConfig ( ) ;
47- const miniUserName = useMemo ( ( ) => {
48- if ( ! props . interaction && ! props . referencedMessage ) return null ;
49-
50- if ( user === undefined ) return null ;
51-
52- if ( ! resolveChannel ) return getDisplayName ( user ) ;
53-
54- const channel = resolveChannel ( props . channelId ) ;
55- if (
56- ! channel ||
57- ! ( "guild_id" in channel ) ||
58- ! channel . guild_id ||
59- ! props . referencedMessage
60- )
61- return getDisplayName ( user ) ;
62-
63- const guildMember = resolveMember (
64- props . referencedMessage . author ,
65- channel . guild_id
66- ) ;
67-
68- if ( ! guildMember ) return getDisplayName ( user ) ;
69-
70- return guildMember . nick ?? getDisplayName ( guildMember . user as APIUser ) ;
71- } , [ props . referencedMessage , props . interaction , resolveChannel ] ) ;
72-
73- const miniAvatarUrl = useMemo (
74- ( ) =>
75- user === undefined
76- ? null
77- : avatarUrlOverride ?.( user ) ?? getMiniAvatarUrl ( user ) ,
78- [ props . referencedMessage , props . interaction ]
79- ) ;
80-
81- const miniUserNameColorHex = useMemo ( ( ) => {
82- if ( ! props . referencedMessage ) return undefined ;
83-
84- const channel = resolveChannel ( props . referencedMessage . channel_id ) ;
85- if ( ! channel || ! ( "guild_id" in channel ) || ! channel . guild_id )
86- return undefined ;
87-
88- const guildMember = resolveMember (
89- props . referencedMessage . author ,
90- channel . guild_id
91- ) ;
92-
93- if ( ! guildMember ) return undefined ;
94-
95- const [ role ] = guildMember . roles
96- . map ( ( id ) => resolveRole ( id ) )
97- . filter (
98- ( role ) : role is APIRole =>
99- role !== null && role !== undefined && role . color !== 0
100- )
101- . sort ( ( a , b ) => b . position - a . position ) ;
102-
103- const color = role ?. color ;
104- if ( ! color ) return undefined ;
105-
106- return color > 0 ? `#${ color . toString ( 16 ) . padStart ( 6 , "0" ) } ` : undefined ;
107- } , [ resolveRole ] ) ;
1084
109- const unknownReply = ! props . referencedMessage && ! props . interaction ;
110-
111- return (
112- < Styles . ReplyInfo >
113- < Styles . ReplySpine />
114- { unknownReply ? (
115- < >
116- < Styles . UnknownReplyIcon
117- width = { 12 }
118- height = { 12 }
119- svg = "IconUnknownReply"
120- />
121- < Styles . UnknownReply >
122- Original message was deleted or is unknown.
123- </ Styles . UnknownReply >
124- </ >
125- ) : (
126- < Styles . ReplyUser >
127- { miniAvatarUrl && (
128- < Styles . MiniUserAvatar src = { miniAvatarUrl . stillAvatarUrl } />
129- ) }
130- { props . referencedMessage && (
131- < ChatTag
132- author = { props . referencedMessage . author }
133- crossPost = { Boolean (
134- ( props . referencedMessage . flags ?? 0 ) & FLAG_CROSSPOST
135- ) }
136- referenceGuild = {
137- props . referencedMessage . message_reference ?. guild_id
138- }
139- />
140- ) }
141- < Styles . MiniUserName style = { { color : miniUserNameColorHex } } >
142- { props . mentioned && "@" }
143- { miniUserName }
144- </ Styles . MiniUserName >
145- </ Styles . ReplyUser >
146- ) }
147- { props . referencedMessage ? (
148- < Content message = { props . referencedMessage } isReplyContent = { true } />
149- ) : (
150- props . interaction && (
151- < Styles . SlashCommand >
152- used{ " " }
153- < Styles . SlashCommandText >
154- { ! props . isContextMenuInteraction ? "/" : "" }
155- { props . interaction . name }
156- </ Styles . SlashCommandText >
157- </ Styles . SlashCommand >
158- )
159- ) }
160- </ Styles . ReplyInfo >
161- ) ;
162- } ) ;
163-
164- ReplyInfo . displayName = "ReplyInfo" ;
165-
166- // type Message = Omit<MessageData, "referencedMessage"> & Partial<MessageData>;
5+ import * as Styles from "../style/message" ;
1676
1687interface EditMessageInputProps {
1698 // isFirstMessage?: boolean;
@@ -181,24 +20,28 @@ interface EditMessageInputProps {
18120function EditMessageInput ( props : EditMessageInputProps ) {
18221 const { handleMessageEditSubmit } = useConfig ( ) ;
18322
184- const submitMessageCallback = ( content : string ) => {
23+ function submitMessageCallback ( content : string ) {
18524 if ( ! handleMessageEditSubmit || ! content ) return ;
18625
18726 handleMessageEditSubmit ( {
18827 ...props . message ,
18928 content : content ,
19029 edited_timestamp : new Date ( ) . getMilliseconds ( ) . toString ( ) ,
19130 } ) ;
192- } ;
31+ }
32+
33+ function onKeyDown ( e : React . KeyboardEvent < HTMLInputElement > ) {
34+ const target = e . target as HTMLInputElement ;
35+
36+ if ( e . key === "Enter" ) {
37+ submitMessageCallback ( target . value ) ;
38+ }
39+ }
19340
19441 return (
19542 < Styles . MessageEditor
19643 autoCorrect = { "false" }
197- onKeyDown = { ( e ) => {
198- if ( e . key === "Enter" ) {
199- submitMessageCallback ( e . target . value ) ;
200- }
201- } }
44+ onKeyDown = { onKeyDown }
20245 defaultValue = { props . message . content }
20346 />
20447 ) ;
0 commit comments