Skip to content

Commit

Permalink
When app resume in foreground, get notification and chat counts
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscant committed Jun 28, 2023
1 parent 4b6199c commit 3e04382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 0 additions & 3 deletions components/LayoutCommon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,11 @@ export default {
},
monitorTabVisibility() {
if (process.client) {
// console.log('---monitorTabVisibility')
document.addEventListener('visibilitychange', () => {
console.log('---visibilitychange')
const miscStore = useMiscStore()
miscStore.visible = !document.hidden
if (this.me && !document.hidden) {
// console.log('---visibilitychange CHANGED')
// We have become visible. Refetch our notification count and chat count, which are the two key things which
// produce red badges people should click on.
const notificationStore = useNotificationStore()
Expand Down
23 changes: 23 additions & 0 deletions stores/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { FirebaseMessaging } from '@capacitor-firebase/messaging';
import { ZoomPlugin } from 'capacitor-zoom-android';
import { App } from '@capacitor/app';
import { useRouter } from '#imports'
import { useChatStore } from '~/stores/chat'
import { useNotificationStore } from '~/stores/notification'

export const useMobileStore = defineStore({ // Do not persist
id: 'mobile',
Expand Down Expand Up @@ -67,6 +69,7 @@ export const useMobileStore = defineStore({ // Do not persist
await this.initDeepLinks()
await this.initPushNotifications()
await this.checkForAppUpdate()
await this.initWakeUpActions()
//await this.initFirebaseMessaging()
/*if (!this.isiOS) {
try {
Expand Down Expand Up @@ -215,6 +218,26 @@ export const useMobileStore = defineStore({ // Do not persist
return urlParams
},

//////////////
// https://capacitorjs.com/docs/apis/app#addlistenerresume
async initWakeUpActions() {
if (process.client) {
App.addListener('resume', async event => {
// We have become visible. Refetch our notification count and chat count, which are the two key things which
// produce red badges people should click on.
try {
const notificationStore = useNotificationStore()
notificationStore.fetchCount()

const chatStore = useChatStore()

// Don't log as we might have been logged out since we were last active.
chatStore.fetchChats(null, false)
} catch (e){}
})
}
},

//////////////
// Needs: https://www.ilovefreegle.org/.well-known/assetlinks.json
async initDeepLinks() {
Expand Down

0 comments on commit 3e04382

Please sign in to comment.