Skip to content

Commit

Permalink
Merge pull request #12879 from nextcloud/fix/12864/fix-remote-capabil…
Browse files Browse the repository at this point in the history
…ities

fix(federation): disable chat and call if talk hash is dirty
  • Loading branch information
Antreesy committed Aug 2, 2024
2 parents 10a0f84 + aa637f3 commit f00266d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export default {
},
isNextcloudTalkHashDirty() {
return this.talkHashStore.isNextcloudTalkHashDirty
|| this.talkHashStore.isNextcloudTalkProxyHashDirty[this.token]
},
container() {
return this.$store.getters.getMainContainerSelector()
Expand Down
7 changes: 6 additions & 1 deletion src/services/CapabilitiesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { t } from '@nextcloud/l10n'

import { getRemoteCapabilities } from './federationService.ts'
import BrowserStorage from '../services/BrowserStorage.js'
import { useTalkHashStore } from '../stores/talkHash.js'
import type { Capabilities, JoinRoomFullResponse } from '../types'

type Config = Capabilities['spreed']['config']
Expand Down Expand Up @@ -40,7 +41,7 @@ export function hasTalkFeature(token: string = 'local', feature: string): boolea
* @param key2 second-level key (e.g. 'allowed')
*/
export function getTalkConfig(token: string = 'local', key1: keyof Config, key2: keyof Config[keyof Config]) {
if (localCapabilities?.spreed?.['config-local']?.[key1]?.[key2]) {
if (localCapabilities?.spreed?.['config-local']?.[key1]?.includes(key2)) {
return localCapabilities?.spreed?.config?.[key1]?.[key2]
} else if (token === 'local' || !remoteCapabilities[token]) {
return localCapabilities?.spreed?.config?.[key1]?.[key2]
Expand All @@ -62,6 +63,10 @@ export async function setRemoteCapabilities(joinRoomResponse: JoinRoomFullRespon
return
}

// Mark the hash as dirty to prevent any activity in the conversation
const talkHashStore = useTalkHashStore()
talkHashStore.setTalkProxyHashDirty(token)

const response = await getRemoteCapabilities(token)
if (Array.isArray(response.data.ocs.data)) {
// unknown[] received from server, nothing to update with
Expand Down
19 changes: 16 additions & 3 deletions src/stores/talkHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { defineStore } from 'pinia'
import Vue from 'vue'

import { showError, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
Expand All @@ -12,9 +13,10 @@ import { talkBroadcastChannel } from '../services/talkBroadcastChannel.js'

/**
* @typedef {object} State
* @property {string} initialNextcloudTalkHash - The absence status per conversation.
* @property {boolean} isNextcloudTalkHashDirty - The parent message id to reply per conversation.
* @property {object|null} maintenanceWarningToast -The input value per conversation.
* @property {string} initialNextcloudTalkHash - the 'default' Talk hash to compare with.
* @property {boolean} isNextcloudTalkHashDirty - whether Talk hash was updated and requires a reload.
* @property {object} isNextcloudTalkProxyHashDirty - whether Talk hash in federated conversation was updated.
* @property {object|null} maintenanceWarningToast - a toast object.
*/

/**
Expand All @@ -27,6 +29,7 @@ export const useTalkHashStore = defineStore('talkHash', {
state: () => ({
initialNextcloudTalkHash: '',
isNextcloudTalkHashDirty: false,
isNextcloudTalkProxyHashDirty: {},
maintenanceWarningToast: null,
}),

Expand All @@ -46,6 +49,16 @@ export const useTalkHashStore = defineStore('talkHash', {
}
},

/**
* Mark the current Talk Federation hash as dirty
*
* @param {string} token federated conversation token
*/
setTalkProxyHashDirty(token) {
console.debug('X-Nextcloud-Talk-Proxy-Hash marked dirty: ', token)
Vue.set(this.isNextcloudTalkProxyHashDirty, token, true)
},

/**
* Updates a Talk hash from a response
*
Expand Down

0 comments on commit f00266d

Please sign in to comment.