@@ -332,12 +332,19 @@ export default function CustomChatScreen() {
332332 if ( event . user_id !== currentUserId ) {
333333 setIsTyping ( event . is_typing ) ;
334334 }
335- } else if ( event . type === 'message_edited' ) {
335+ } else if ( event . type === 'message_edited' || event . type === 'edit_message' ) {
336+ const targetId = String ( event . server_msg_id || event . message_id || event . id ) ;
337+ const updatedText = event . content || event . text ;
336338 setMessages ( prev =>
337339 prev . map ( msg => {
338- const msgId = msg . server_msg_id || ( msg as any ) . message_id || msg . id ;
339- if ( String ( msgId ) === String ( event . message_id ) ) {
340- return { ...msg , text : event . content , content : event . content , edited_at : event . edited_at } ;
340+ const msgId = String ( msg . server_msg_id || ( msg as any ) . message_id || msg . id || msg . client_msg_id ) ;
341+ if ( msgId === targetId || ( msg . server_msg_id && String ( msg . server_msg_id ) === targetId ) ) {
342+ return {
343+ ...msg ,
344+ text : updatedText || msg . text || msg . content ,
345+ content : updatedText || msg . content || msg . text ,
346+ edited_at : event . edited_at || new Date ( ) . toISOString ( )
347+ } ;
341348 }
342349 return msg ;
343350 } )
@@ -426,12 +433,32 @@ export default function CustomChatScreen() {
426433
427434 // If Editing existing message:
428435 if ( editingMessage ) {
429- const msgId = editingMessage . server_msg_id || ( editingMessage as any ) . message_id || editingMessage . id ;
436+ const rawMsgId = editingMessage . server_msg_id || ( editingMessage as any ) . message_id || editingMessage . id ;
437+ const numMsgId = Number ( rawMsgId ) ;
438+
439+ // Optimistically update message in state immediately
440+ setMessages ( prev =>
441+ prev . map ( m => {
442+ const mKey = String ( m . server_msg_id || ( m as any ) . message_id || m . id || m . client_msg_id ) ;
443+ if ( mKey === String ( rawMsgId ) || ( ! isNaN ( numMsgId ) && ( m . server_msg_id === numMsgId || ( m as any ) . message_id === numMsgId ) ) ) {
444+ return {
445+ ...m ,
446+ text : messageText ,
447+ content : messageText ,
448+ edited_at : new Date ( ) . toISOString ( )
449+ } ;
450+ }
451+ return m ;
452+ } )
453+ ) ;
454+
430455 try {
431- await editMessage ( chatId , Number ( msgId ) , messageText ) ;
456+ await editMessage ( chatId , numMsgId , messageText ) ;
432457 setToast ( { visible : true , message : 'Message edited' , isSuccess : true } ) ;
433- } catch ( err ) {
458+ } catch ( err : any ) {
434459 console . error ( 'Failed to edit message:' , err ) ;
460+ const errorMsg = err ?. response ?. data ?. detail || err ?. message || 'Failed to edit message' ;
461+ setToast ( { visible : true , message : errorMsg , isSuccess : false } ) ;
435462 } finally {
436463 setEditingMessage ( null ) ;
437464 setIsSending ( false ) ;
@@ -487,10 +514,43 @@ export default function CustomChatScreen() {
487514
488515 const handleToggleReaction = async ( emoji : string ) => {
489516 if ( ! selectedActionMessage ) return ;
490- const msgId = selectedActionMessage . server_msg_id || ( selectedActionMessage as any ) . message_id || selectedActionMessage . id ;
517+ const rawMsgId = selectedActionMessage . server_msg_id || ( selectedActionMessage as any ) . message_id || selectedActionMessage . id ;
518+ const numMsgId = Number ( rawMsgId ) ;
491519 setActionModalVisible ( false ) ;
520+
521+ if ( isNaN ( numMsgId ) ) return ;
522+
523+ // Optimistically update reactions in local state
524+ setMessages ( prev =>
525+ prev . map ( msg => {
526+ const mKey = String ( msg . server_msg_id || ( msg as any ) . message_id || msg . id || msg . client_msg_id ) ;
527+ if ( mKey === String ( rawMsgId ) || ( ! isNaN ( numMsgId ) && ( msg . server_msg_id === numMsgId || ( msg as any ) . message_id === numMsgId ) ) ) {
528+ const currentReactions = msg . reactions || [ ] ;
529+ const existingIdx = currentReactions . findIndex ( r => r . emoji === emoji ) ;
530+ let newReactions = [ ...currentReactions ] ;
531+
532+ if ( existingIdx !== - 1 ) {
533+ const existing = newReactions [ existingIdx ] ;
534+ if ( existing . reacted_by_me ) {
535+ if ( existing . count <= 1 ) {
536+ newReactions . splice ( existingIdx , 1 ) ;
537+ } else {
538+ newReactions [ existingIdx ] = { ...existing , count : existing . count - 1 , reacted_by_me : false } ;
539+ }
540+ } else {
541+ newReactions [ existingIdx ] = { ...existing , count : existing . count + 1 , reacted_by_me : true } ;
542+ }
543+ } else {
544+ newReactions . push ( { emoji, count : 1 , reacted_by_me : true } ) ;
545+ }
546+ return { ...msg , reactions : newReactions } ;
547+ }
548+ return msg ;
549+ } )
550+ ) ;
551+
492552 try {
493- await addReaction ( chatId , Number ( msgId ) , emoji ) ;
553+ await addReaction ( chatId , numMsgId , emoji ) ;
494554 } catch ( err ) {
495555 console . error ( 'Failed to add reaction:' , err ) ;
496556 }
@@ -550,7 +610,10 @@ export default function CustomChatScreen() {
550610 onLongPress = { ( ) => handleMessageLongPress ( item ) }
551611 onReply = { ( ) => setReplyToMessage ( item ) }
552612 onReactionPress = { ( msgId , emoji ) => {
553- addReaction ( chatId , msgId , emoji ) ;
613+ const numId = Number ( msgId ) ;
614+ if ( ! isNaN ( numId ) ) {
615+ addReaction ( chatId , numId , emoji ) ;
616+ }
554617 } }
555618 />
556619 ) ;
@@ -657,7 +720,7 @@ export default function CustomChatScreen() {
657720 < LiquidGlassView
658721 glassEffectStyle = "clear"
659722 colorScheme = "auto"
660- fallbackBackgroundColor = "rgba(21, 7, 35, 0.4) "
723+ fallbackBackgroundColor = "transparent "
661724 style = { styles . floatingGlassCapsule }
662725 >
663726 { /* Action Banners */ }
@@ -677,7 +740,7 @@ export default function CustomChatScreen() {
677740 ) }
678741
679742 { editingMessage && (
680- < View style = { [ styles . actionBanner , { backgroundColor : 'rgba(167, 139, 250 , 0.25 )' } ] } >
743+ < View style = { [ styles . actionBanner , { backgroundColor : 'rgba(255, 255, 255 , 0.08 )' } ] } >
681744 < View style = { [ styles . bannerBar , { backgroundColor : '#A78BFA' } ] } />
682745 < View style = { styles . bannerContent } >
683746 < Text style = { [ styles . bannerTitle , { color : '#A78BFA' } ] } > Editing message</ Text >
@@ -966,7 +1029,7 @@ const styles = StyleSheet.create({
9661029 actionBanner : {
9671030 flexDirection : 'row' ,
9681031 alignItems : 'center' ,
969- backgroundColor : 'rgba(167, 139, 250 , 0.18 )' ,
1032+ backgroundColor : 'rgba(255, 255, 255 , 0.08 )' ,
9701033 paddingHorizontal : 14 ,
9711034 paddingVertical : 8 ,
9721035 borderBottomWidth : 1 ,
@@ -1004,7 +1067,7 @@ const styles = StyleSheet.create({
10041067 width : 36 ,
10051068 height : 36 ,
10061069 borderRadius : 18 ,
1007- backgroundColor : 'rgba(167, 139, 250, 0.15) ' ,
1070+ backgroundColor : 'transparent ' ,
10081071 justifyContent : 'center' ,
10091072 alignItems : 'center' ,
10101073 marginRight : 8 ,
@@ -1016,7 +1079,7 @@ const styles = StyleSheet.create({
10161079 paddingHorizontal : 14 ,
10171080 paddingVertical : 8 ,
10181081 borderRadius : 20 ,
1019- backgroundColor : 'rgba(255, 255, 255, 0.08) ' ,
1082+ backgroundColor : 'transparent ' ,
10201083 marginRight : 8 ,
10211084 } ,
10221085 sendButton : {
0 commit comments