Skip to content

Commit

Permalink
update notification and video count badges on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
nkonev committed Dec 15, 2024
1 parent 8da555a commit 682b5ad
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
21 changes: 19 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ import axios from "axios";
import bus, {
CHAT_ADD,
CHAT_DELETED,
CHAT_EDITED, CHAT_REDRAW,
CHAT_EDITED,
CHAT_REDRAW,
LOGGED_OUT,
NOTIFICATION_ADD,
NOTIFICATION_DELETE,
Expand All @@ -182,7 +183,12 @@ import bus, {
VIDEO_CALL_USER_COUNT_CHANGED,
VIDEO_DIAL_STATUS_CHANGED,
VIDEO_RECORDING_CHANGED,
WEBSOCKET_RESTORED, ON_WINDOW_RESIZED, NOTIFICATION_CLEAR_ALL, WEBSOCKET_LOST, WEBSOCKET_CONNECTED,
WEBSOCKET_RESTORED,
ON_WINDOW_RESIZED,
NOTIFICATION_CLEAR_ALL,
WEBSOCKET_LOST,
WEBSOCKET_CONNECTED,
NOTIFICATION_COUNT_CHANGED,
} from "@/bus/bus";
import LoginModal from "@/LoginModal.vue";
import {useChatStore} from "@/store/chatStore";
Expand Down Expand Up @@ -745,6 +751,13 @@ export default {
updateVideoBadge() {
this.showVideoBadge = !!this.chatStore.videoChatUsersCount
},
// needed to update video badge after /api/video/${chatId}/users was called by FOCUS event
onVideoCallChanged() {
this.updateVideoBadge();
},
onNotificationCountChanged() {
this.updateNotificationBadge();
},
},
components: {
ChooseColorModal,
Expand Down Expand Up @@ -810,6 +823,8 @@ export default {
bus.on(WEBSOCKET_RESTORED, this.onWsRestored);
bus.on(VIDEO_CALL_INVITED, this.onVideoCallInvited);
bus.on(VIDEO_RECORDING_CHANGED, this.onVideRecordingChanged);
bus.on(VIDEO_CALL_USER_COUNT_CHANGED, this.onVideoCallChanged);
bus.on(NOTIFICATION_COUNT_CHANGED, this.onNotificationCountChanged);
// To trigger fetching profile that 's going to trigger starting subscriptions
// It's placed after each route in order not to have a race-condition
Expand All @@ -832,6 +847,8 @@ export default {
bus.off(WEBSOCKET_RESTORED, this.onWsRestored);
bus.off(VIDEO_CALL_INVITED, this.onVideoCallInvited);
bus.off(VIDEO_RECORDING_CHANGED, this.onVideRecordingChanged);
bus.off(VIDEO_CALL_USER_COUNT_CHANGED, this.onVideoCallChanged);
bus.off(NOTIFICATION_COUNT_CHANGED, this.onNotificationCountChanged);
this.globalEventsSubscription.graphQlUnsubscribe();
this.selfProfileEventsSubscription.graphQlUnsubscribe();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export default {
})
.then(response => response.data)
.then(data => {
bus.emit(VIDEO_CALL_USER_COUNT_CHANGED, data);
this.chatStore.videoChatUsersCount = data.usersCount;
bus.emit(VIDEO_CALL_USER_COUNT_CHANGED, data);
})
return Promise.resolve();
}).then(() => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/bus/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const CLOSE_SIMPLE_MODAL = "closeSimpleModal";

export const OPEN_SET_PASSWORD_MODAL = "openSetPassword";

export const NOTIFICATION_COUNT_CHANGED = "notificationCountChanged";

export const VIDEO_CALL_USER_COUNT_CHANGED = "videoCallUserCountChanged";
export const VIDEO_CALL_SCREEN_SHARE_CHANGED = "videoCallScreenShareChanged";

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/store/chatStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import axios from "axios";
import {isMobileBrowser, setIcon} from "@/utils";
import {SEARCH_MODE_CHATS, SEARCH_MODE_MESSAGES} from "@/mixins/searchString";
import {setStoredLanguage} from "@/store/localStore";
import bus, {PROFILE_SET} from "@/bus/bus.js";
import bus, {NOTIFICATION_COUNT_CHANGED, PROFILE_SET} from "@/bus/bus.js";

export const callStateReady = "ready"
export const callStateInCall = "inCall"
Expand Down Expand Up @@ -112,6 +112,7 @@ export const useChatStore = defineStore('chat', {
axios.get(`/api/notification/count`).then(( {data} ) => {
console.debug("fetched notifications =", data);
this.setNotificationCount(data.totalCount);
bus.emit(NOTIFICATION_COUNT_CHANGED);
});
},
fetchHasNewMessages() {
Expand Down

0 comments on commit 682b5ad

Please sign in to comment.