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

Enable capability-based avatar img loading #5178

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Use profile picture capability in avatars

Requests for loading avatar profile pictures now only get sent
if the backend communicates their availability in the capabilities.

https://github.com/owncloud/web/pull/5178
4 changes: 4 additions & 0 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ export default {
},

loadAvatars({ commit, rootGetters }, { resource }) {
if (!rootGetters.capabilities.files_sharing.user.profile_picture) {
return
}

;['sharedWith', 'owner'].forEach(k => {
;(resource[k] || []).forEach((obj, i) => {
if (!has(obj, 'avatar')) {
Expand Down
16 changes: 6 additions & 10 deletions packages/web-runtime/src/components/Avatar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<component :is="type" v-if="enabled" :aria-hidden="true">
<component :is="type" :aria-hidden="true">
<oc-spinner
v-if="loading"
key="avatar-loading"
Expand Down Expand Up @@ -61,18 +61,14 @@ export default {
}
},
computed: {
...mapGetters(['getToken', 'configuration']),
enabled: function() {
return this.configuration.enableAvatars || true
}
...mapGetters(['getToken', 'capabilities', 'configuration'])
},
watch: {
userid: function(userid, old) {
userid: function(userid) {
this.setUser(userid)
}
},
mounted: function() {
// Handled mounted situation. Userid might not be set yet so try placeholder
if (this.userid !== '') {
this.setUser(this.userid)
} else {
Expand All @@ -86,13 +82,13 @@ export default {
setUser(userid) {
this.loading = true
this.avatarSource = ''
if (!this.enabled || userid === '') {
if (!this.capabilities.files_sharing.user.profile_picture || userid === '') {
this.loading = false
return
}
const headers = new Headers()
const instance = this.configuration.server || window.location.origin
const url = instance + 'remote.php/dav/avatars/' + this.userid + '/128.png'
const url = instance + 'remote.php/dav/avatars/' + userid + '/128.png'
headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')
fetch(url, { headers })
Expand All @@ -116,7 +112,7 @@ export default {
.catch(error => {
this.avatarSource = ''
this.loading = false
console.error(`Error loading avatar image for user "${this.userid}": `, error.message)
console.error(`Error loading avatar image for user "${userid}": `, error.message)
})
}
}
Expand Down
Binary file modified tests/vrt/baseline/ocis/topBar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.