Implement avatar upload and removal (not persistent access sessions)

This commit is contained in:
Jonas Herzig 2018-09-24 21:05:22 +02:00
parent 2046bdf03a
commit d3cf7f0f22
2 changed files with 20 additions and 4 deletions

View file

@ -223,11 +223,13 @@
View Avatar View Avatar
</li> </li>
<!-- ko if: $data === $root.thisUser() --> <!-- ko if: $data === $root.thisUser() -->
<li data-bind="css: { disabled: !canChangeAvatar() }, visible: true"> <li data-bind="css: { disabled: !canChangeAvatar() }, visible: true,
click: changeAvatar">
Change Avatar Change Avatar
</li> </li>
<!-- /ko --> <!-- /ko -->
<li data-bind="css: { disabled: !canChangeAvatar() }, visible: texture"> <li data-bind="css: { disabled: !canChangeAvatar() }, visible: texture,
click: removeAvatar">
Reset Avatar Reset Avatar
</li> </li>

View file

@ -394,8 +394,7 @@ class GlobalBindings {
// return this.thisUser() === ui // TODO check for perms // return this.thisUser() === ui // TODO check for perms
} }
ui.canChangeAvatar = () => { ui.canChangeAvatar = () => {
return false // TODO implement changing of avatar return this.thisUser() === ui // TODO check for perms
// return this.thisUser() === ui // TODO check for perms
} }
ui.toggleMute = () => { ui.toggleMute = () => {
if (ui.selfMute()) { if (ui.selfMute()) {
@ -414,6 +413,21 @@ class GlobalBindings {
ui.viewAvatar = () => { ui.viewAvatar = () => {
this.avatarView(ui.texture()) this.avatarView(ui.texture())
} }
ui.changeAvatar = () => {
let input = document.createElement('input')
input.type = 'file'
input.addEventListener('change', () => {
let reader = new window.FileReader()
reader.onload = () => {
this.client.setSelfTexture(reader.result)
}
reader.readAsArrayBuffer(input.files[0])
})
input.click()
}
ui.removeAvatar = () => {
user.clearTexture()
}
Object.entries(simpleProperties).forEach(key => { Object.entries(simpleProperties).forEach(key => {
ui[key[1]] = ko.observable(user[key[0]]) ui[key[1]] = ko.observable(user[key[0]])
}) })