@@ -1498,27 +1498,29 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
14981498 /**
14991499 * Removes the message from local state
15001500 */
1501- const removeMessage : MessagesContextValue [ 'removeMessage' ] = useStableCallback ( async ( message ) => {
1502- if ( channel ) {
1503- // TODO: See if it's easy to refactor this to be able to accept DB queries
1504- channel . state . removeMessage ( message ) ;
1505- copyMessagesStateFromChannel ( channel ) ;
1501+ const removeMessage : MessagesContextValue [ 'removeMessage' ] = useStableCallback (
1502+ async ( message ) => {
1503+ if ( channel ) {
1504+ // TODO: See if it's easy to refactor this to be able to accept DB queries
1505+ channel . state . removeMessage ( message ) ;
1506+ copyMessagesStateFromChannel ( channel ) ;
15061507
15071508 if ( thread ) {
15081509 setThreadMessages ( channel . state . threads [ thread . id ] || [ ] ) ;
15091510 }
15101511 }
15111512
1512- if ( client . offlineDb ) {
1513- // FIXME: Batch these maybe ?.
1514- await Promise . all ( [
1515- client . offlineDb . dropPendingTasks ( { messageId : message . id } ) ,
1516- client . offlineDb . hardDeleteMessage ( {
1517- id : message . id ,
1518- } ) ,
1519- ] ) ;
1520- }
1521- } ) ;
1513+ if ( client . offlineDb ) {
1514+ // FIXME: Batch these maybe ?.
1515+ await Promise . all ( [
1516+ client . offlineDb . dropPendingTasks ( { messageId : message . id } ) ,
1517+ client . offlineDb . hardDeleteMessage ( {
1518+ id : message . id ,
1519+ } ) ,
1520+ ] ) ;
1521+ }
1522+ } ,
1523+ ) ;
15221524
15231525 const sendReaction = useStableCallback ( async ( type : string , messageId : string ) => {
15241526 if ( ! channel ?. id || ! client . user ) {
@@ -1552,34 +1554,33 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15521554 }
15531555 } ) ;
15541556
1555- const deleteMessage : MessagesContextValue [ 'deleteMessage' ] = useStableCallback ( async (
1556- message ,
1557- hardDelete = false ,
1558- ) => {
1559- if ( ! channel . id ) {
1560- throw new Error ( 'Channel has not been initialized yet' ) ;
1561- }
1557+ const deleteMessage : MessagesContextValue [ 'deleteMessage' ] = useStableCallback (
1558+ async ( message , hardDelete = false ) => {
1559+ if ( ! channel . id ) {
1560+ throw new Error ( 'Channel has not been initialized yet' ) ;
1561+ }
15621562
1563- if ( message . status === MessageStatusTypes . FAILED ) {
1564- await removeMessage ( message ) ;
1565- return ;
1566- }
1567- const updatedMessage = {
1568- ...message ,
1569- cid : channel . cid ,
1570- deleted_at : new Date ( ) . toISOString ( ) ,
1571- type : 'deleted' as MessageLabel ,
1572- } ;
1573- updateMessage ( updatedMessage ) ;
1563+ if ( message . status === MessageStatusTypes . FAILED ) {
1564+ await removeMessage ( message ) ;
1565+ return ;
1566+ }
1567+ const updatedMessage = {
1568+ ...message ,
1569+ cid : channel . cid ,
1570+ deleted_at : new Date ( ) . toISOString ( ) ,
1571+ type : 'deleted' as MessageLabel ,
1572+ } ;
1573+ updateMessage ( updatedMessage ) ;
15741574
1575- threadInstance ?. upsertReplyLocally ( { message : updatedMessage } ) ;
1575+ threadInstance ?. upsertReplyLocally ( { message : updatedMessage } ) ;
15761576
1577- const data = await client . deleteMessage ( message . id , hardDelete ) ;
1577+ const data = await client . deleteMessage ( message . id , hardDelete ) ;
15781578
1579- if ( data ?. message ) {
1580- updateMessage ( { ...data . message } ) ;
1581- }
1582- } ) ;
1579+ if ( data ?. message ) {
1580+ updateMessage ( { ...data . message } ) ;
1581+ }
1582+ } ,
1583+ ) ;
15831584
15841585 const deleteReaction : MessagesContextValue [ 'deleteReaction' ] = useStableCallback (
15851586 async ( type : string , messageId : string ) => {
@@ -1589,14 +1590,20 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15891590
15901591 const payload : Parameters < ChannelClass [ 'deleteReaction' ] > = [ messageId , type ] ;
15911592
1592- if ( enableOfflineSupport ) {
1593- channel . state . removeReaction ( { created_at : '' , message_id : messageId , type, updated_at : '' } ) ;
1593+ if ( enableOfflineSupport ) {
1594+ channel . state . removeReaction ( {
1595+ created_at : '' ,
1596+ message_id : messageId ,
1597+ type,
1598+ updated_at : '' ,
1599+ } ) ;
15941600
1595- copyMessagesStateFromChannel ( channel ) ;
1596- }
1601+ copyMessagesStateFromChannel ( channel ) ;
1602+ }
15971603
1598- await channel . deleteReaction ( ...payload ) ;
1599- } ) ;
1604+ await channel . deleteReaction ( ...payload ) ;
1605+ } ,
1606+ ) ;
16001607
16011608 /**
16021609 * THREAD METHODS
0 commit comments