Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache hasAvatar to avoid call background flickering #4379

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/CallView/shared/VideoBackground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ import axios from '@nextcloud/axios'
import usernameToColor from '@nextcloud/vue/dist/Functions/usernameToColor'
import { generateUrl } from '@nextcloud/router'
import { ResizeObserver } from 'vue-resize'
import { getBuilder } from '@nextcloud/browser-storage'

const browserStorage = getBuilder('nextcloud').persist().build()

// note: this info is shared with the Avatar component
function getUserHasAvatar(userId) {
const flag = browserStorage.getItem('user-has-avatar.' + userId)
if (typeof flag === 'string') {
return Boolean(flag)
}
return null
}

function setUserHasAvatar(userId, flag) {
browserStorage.setItem('user-has-avatar.' + userId, flag)
}

export default {
name: 'VideoBackground',
Expand Down Expand Up @@ -96,10 +112,20 @@ export default {
return
}

// check if hasAvatar info is already known
const userHasAvatar = getUserHasAvatar(this.user)
if (typeof userHasAvatar === 'boolean') {
this.hasPicture = userHasAvatar
return
}

try {
const response = await axios.get(generateUrl(`avatar/${this.user}/300`))
if (response.headers[`x-nc-iscustomavatar`] === '1') {
this.hasPicture = true
setUserHasAvatar(this.user, true)
} else {
setUserHasAvatar(this.user, false)
}
} catch (exception) {
console.debug(exception)
Expand Down