55
66import { listen } from '@nextcloud/notify_push'
77import { sessionApi } from './services/SessionApi.js'
8- import storeFactory from './store/main.js'
98import axios from '@nextcloud/axios'
109
1110const SESSION_INTERVAL = 90 // in seconds
@@ -14,7 +13,7 @@ let hasPush = false
1413
1514let syncRunning = false
1615
17- const store = storeFactory ( )
16+ let store = null
1817
1918/**
2019 * used to verify, whether an event is originated by ourselves
@@ -30,28 +29,35 @@ function isOurSessionToken(token) {
3029 }
3130}
3231
33- hasPush = listen ( 'deck_board_update' , ( name , body ) => {
34- // ignore update events which we have triggered ourselves
35- if ( isOurSessionToken ( body . _causingSessionToken ) ) return
32+ /**
33+ *
34+ * @param storeInstance
35+ */
36+ export function initSessions ( storeInstance ) {
37+ store = storeInstance
38+ hasPush = listen ( 'deck_board_update' , ( name , body ) => {
39+ // ignore update events which we have triggered ourselves
40+ if ( isOurSessionToken ( body . _causingSessionToken ) ) return
3641
37- // only handle update events for the currently open board
38- const currentBoardId = store . state . currentBoard ?. id
39- if ( body . id !== currentBoardId ) return
42+ // only handle update events for the currently open board
43+ const currentBoardId = store . state . currentBoard ?. id
44+ if ( body . id !== currentBoardId ) return
4045
41- store . dispatch ( 'refreshBoard' , currentBoardId )
42- } )
46+ store . dispatch ( 'refreshBoard' , currentBoardId )
47+ } )
4348
44- listen ( 'deck_card_update' , ( name , body ) => {
49+ listen ( 'deck_card_update' , ( name , body ) => {
4550
46- // ignore update events which we have triggered ourselves
47- if ( isOurSessionToken ( body . _causingSessionToken ) ) return
51+ // ignore update events which we have triggered ourselves
52+ if ( isOurSessionToken ( body . _causingSessionToken ) ) return
4853
49- // only handle update events for the currently open board
50- const currentBoardId = store . state . currentBoard ?. id
51- if ( body . boardId !== currentBoardId ) return
54+ // only handle update events for the currently open board
55+ const currentBoardId = store . state . currentBoard ?. id
56+ if ( body . boardId !== currentBoardId ) return
5257
53- store . dispatch ( 'loadStacks' , currentBoardId )
54- } )
58+ store . dispatch ( 'loadStacks' , currentBoardId )
59+ } )
60+ }
5561
5662/**
5763 * is the notify_push app active and can
0 commit comments