File tree Expand file tree Collapse file tree 6 files changed +37
-19
lines changed
Expand file tree Collapse file tree 6 files changed +37
-19
lines changed Original file line number Diff line number Diff line change @@ -1503,7 +1503,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15031503 const removeMessage : MessagesContextValue [ 'removeMessage' ] = useStableCallback (
15041504 async ( message ) => {
15051505 if ( channel ) {
1506- // TODO: See if it's easy to refactor this to be able to accept DB queries
15071506 channel . state . removeMessage ( message ) ;
15081507 copyMessagesStateFromChannel ( channel ) ;
15091508
@@ -1513,13 +1512,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15131512 }
15141513
15151514 if ( client . offlineDb ) {
1516- // FIXME: Batch these maybe ?.
1517- await Promise . all ( [
1518- client . offlineDb . dropPendingTasks ( { messageId : message . id } ) ,
1519- client . offlineDb . hardDeleteMessage ( {
1520- id : message . id ,
1521- } ) ,
1522- ] ) ;
1515+ await client . offlineDb . handleRemoveMessage ( { messageId : message . id } ) ;
15231516 }
15241517 } ,
15251518 ) ;
Original file line number Diff line number Diff line change @@ -163,14 +163,6 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
163163 */
164164 const { connectionRecovering, isOnline } = useIsOnline ( client , closeConnectionOnBackground ) ;
165165
166- // const [initialisedDatabaseConfig, setInitialisedDatabaseConfig] = useState<{
167- // initialised: boolean;
168- // userID?: string;
169- // }>({
170- // initialised: false,
171- // userID: client.userID,
172- // });
173-
174166 const { initialized : offlineDbInitialized , userId : offlineDbUserId } =
175167 useStateStore ( client . offlineDb ?. state , selector ) ?? { } ;
176168
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ export class OfflineDB extends AbstractOfflineDB {
7070
7171 deleteMessagesForChannel = api . deleteMessagesForChannel ;
7272
73+ dropPendingTasks = api . dropPendingTasks ;
74+
7375 hardDeleteMessage = api . deleteMessage ;
7476
7577 softDeleteMessage = api . softDeleteMessage ;
Original file line number Diff line number Diff line change 1+ import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery' ;
2+ import { SqliteClient } from '../SqliteClient' ;
3+
4+ /**
5+ * dropPendingTasks - Drops all pending tasks from the DB given a specific messageId.
6+ * Useful for when we do some message actions on a failed message and then we decide to
7+ * delete it afterwards, removing it from the state.
8+ *
9+ * @param {Object } param
10+ * @param {string } param.messageId The messageId for which we want to remove the pending tasks.
11+ * @param {boolean } param.flush Whether we should immediately execute the query or return it as a prepared one.
12+ *
13+ * @return {() => void } - A function that can be called to remove the task from the database
14+ */
15+ export const dropPendingTasks = async ( {
16+ messageId,
17+ flush = true ,
18+ } : {
19+ messageId : string ;
20+ flush ?: boolean ;
21+ } ) => {
22+ const queries = [ createDeleteQuery ( 'pendingTasks' , { messageId } ) ] ;
23+ SqliteClient . logger ?.( 'info' , 'dropPendingTasks' , {
24+ messageId,
25+ } ) ;
26+
27+ if ( flush ) {
28+ await SqliteClient . executeSqlBatch ( queries ) ;
29+ }
30+
31+ return queries ;
32+ } ;
Original file line number Diff line number Diff line change @@ -30,3 +30,4 @@ export * from './deletePendingTask';
3030export * from './getPendingTasks' ;
3131export * from './softDeleteMessage' ;
3232export * from './channelExists' ;
33+ export * from './dropPendingTasks' ;
Original file line number Diff line number Diff line change 1- import type { MessageLabel , Role } from 'stream-chat' ;
2-
3- import type { PendingTaskTypes } from './types' ;
1+ import type { MessageLabel , PendingTaskTypes , Role } from 'stream-chat' ;
42
53import type { ValueOf } from '../types/types' ;
64
You can’t perform that action at this time.
0 commit comments