Skip to content

Commit 63531d9

Browse files
luka-nextcloudbackportbot[bot]
authored andcommitted
refactor: initialize session with store instance
Signed-off-by: Luka Trovic <luka@nextcloud.com> [skip ci]
1 parent 4fb0388 commit 63531d9

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { subscribe } from '@nextcloud/event-bus'
1313
import ClickOutside from 'vue-click-outside'
1414
import './shared-init.js'
1515
import './models/index.js'
16-
import './sessions.js'
16+
import { initSessions } from './sessions.js'
1717

1818
// the server snap.js conflicts with vertical scrolling so we disable it
1919
document.body.setAttribute('data-snap-ignore', 'true')
2020

2121
const store = storeFactory()
2222
sync(store, router)
23+
initSessions(store)
2324

2425
Vue.prototype.t = translate
2526
Vue.prototype.n = translatePlural

src/sessions.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { listen } from '@nextcloud/notify_push'
77
import { sessionApi } from './services/SessionApi.js'
8-
import storeFactory from './store/main.js'
98
import axios from '@nextcloud/axios'
109

1110
const SESSION_INTERVAL = 90 // in seconds
@@ -14,7 +13,7 @@ let hasPush = false
1413

1514
let 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

Comments
 (0)