File tree Expand file tree Collapse file tree 5 files changed +13
-15
lines changed
__tests__/offline-support Expand file tree Collapse file tree 5 files changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ export const OptimisticUpdates = () => {
100100 const channelResponse = createChannel ( ) ;
101101 useMockedApis ( chatClient , [ getOrCreateChannelApi ( channelResponse ) ] ) ;
102102 channel = chatClient . channel ( 'messaging' , channelResponse . id ) ;
103+ console . log ( 'BEFORE HERE' ) ;
103104 await channel . watch ( ) ;
104105
105106 channel . cid = channelResponse . channel . cid ;
@@ -364,14 +365,14 @@ export const OptimisticUpdates = () => {
364365 expect ( pendingTasksRows . length ) . toBe ( 2 ) ;
365366 } ) ;
366367
367- jest . spyOn ( chatClient , 'deleteMessage' ) . mockImplementation ( ) ;
368- jest . spyOn ( channel , 'sendReaction ' ) . mockImplementation ( ) ;
368+ const deleteMessageSpy = jest . spyOn ( chatClient , 'deleteMessage' ) . mockImplementation ( ) ;
369+ const sendReactionSpy = jest . spyOn ( channel , '_sendReaction ' ) . mockImplementation ( ) ;
369370
370371 act ( ( ) => dispatchConnectionChangedEvent ( chatClient , true ) ) ;
371372
372373 await waitFor ( ( ) => {
373- expect ( chatClient . deleteMessage ) . toHaveBeenCalled ( ) ;
374- expect ( channel . sendReaction ) . toHaveBeenCalled ( ) ;
374+ expect ( deleteMessageSpy ) . toHaveBeenCalled ( ) ;
375+ expect ( sendReactionSpy ) . toHaveBeenCalled ( ) ;
375376 } ) ;
376377 } ) ;
377378 } ) ;
Original file line number Diff line number Diff line change @@ -1063,7 +1063,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
10631063 } ;
10641064 let connectionChangedSubscription : ReturnType < ChannelType [ 'on' ] > ;
10651065
1066- if ( enableOfflineSupport ) {
1066+ if ( enableOfflineSupport && client . offlineDb ) {
10671067 connectionChangedSubscription = client . offlineDb . syncManager . onSyncStatusChange (
10681068 ( statusChanged ) => {
10691069 if ( statusChanged ) {
@@ -1512,7 +1512,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15121512 }
15131513
15141514 if ( message . status === MessageStatusTypes . FAILED ) {
1515- await client . offlineDb . syncManager . dropPendingTasks ( { messageId : message . id } ) ;
1515+ await client . offlineDb ? .syncManager . dropPendingTasks ( { messageId : message . id } ) ;
15161516 await removeMessage ( message ) ;
15171517 } else {
15181518 const updatedMessage = {
@@ -1525,7 +1525,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15251525
15261526 threadInstance ?. upsertReplyLocally ( { message : updatedMessage } ) ;
15271527
1528- const data = await client . offlineDb . syncManager . queueTask ( {
1528+ const data = await client . offlineDb ? .syncManager . queueTask ( {
15291529 task : {
15301530 channelId : channel . id ,
15311531 channelType : channel . type ,
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
214214
215215 const initializeDatabase = ( ) => {
216216 // TODO: Rethink this, it looks ugly
217- if ( ! client . offlineDb . initialized ) {
217+ if ( ! client . offlineDb ) {
218218 client . setOfflineDBApi ( new OfflineDB ( { client } ) ) ;
219219 }
220220 // This acts as a lock for some very rare occurrences of concurrency
@@ -224,7 +224,7 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
224224 SqliteClient . initializeDatabase ( )
225225 . then ( async ( ) => {
226226 setInitialisedDatabaseConfig ( { initialised : true , userID } ) ;
227- await client . offlineDb . syncManager . init ( ) ;
227+ await client . offlineDb ? .syncManager . init ( ) ;
228228 } )
229229 . catch ( ( error ) => {
230230 console . log ( 'Error Initializing DB:' , error ) ;
@@ -255,7 +255,7 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
255255 // In case something went wrong, make sure to also unsubscribe the listener
256256 // on unmount if it exists to prevent a memory leak.
257257 // FIXME: Should be wrapped in its own unregistration mechanism
258- client . offlineDb . syncManager ? .connectionChangedListener ?. unsubscribe ( ) ;
258+ client . offlineDb ? .syncManager . connectionChangedListener ?. unsubscribe ( ) ;
259259 } ;
260260 } , [ client ] ) ;
261261
Original file line number Diff line number Diff line change @@ -11,12 +11,8 @@ import * as api from './apis';
1111import { SqliteClient } from './SqliteClient' ;
1212
1313export class OfflineDB extends AbstractOfflineDB {
14- public initialized = false ;
15-
1614 constructor ( { client } : { client : StreamChat } ) {
1715 super ( { client } ) ;
18-
19- this . initialized = true ;
2016 }
2117
2218 upsertCidsForQuery = api . upsertCidsForQuery ;
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ export const addPendingTask = async (task: PendingTask) => {
2222 type,
2323 } ) ;
2424
25- await SqliteClient . executeSql . apply ( null , query ) ;
25+ const r = await SqliteClient . executeSql . apply ( null , query ) ;
26+ console . log ( '[OFFLINE]: QUERY: ' , r ) ;
2627
2728 return async ( ) => {
2829 SqliteClient . logger ?.( 'info' , 'deletePendingTaskAfterAddition' , {
You can’t perform that action at this time.
0 commit comments