FIX: setting custom avatar would not work a lot of the time

Due to internal structure we were often caching "redirect" images.
This commit is contained in:
Sam 2015-01-31 23:42:20 +11:00
parent be16bbdd89
commit 05a56b25a9
3 changed files with 17 additions and 10 deletions

View File

@ -14,9 +14,6 @@ export default Em.Component.extend(UploadMixin, {
uploadDone: function(data) {
var self = this;
// indicates the users is using an uploaded avatar
this.set("custom_avatar_upload_id", data.result.upload_id);
// display a warning whenever the image is not a square
this.set("imageIsNotASquare", data.result.width !== data.result.height);
@ -26,6 +23,11 @@ export default Em.Component.extend(UploadMixin, {
// this will also capture the first frame of animated avatars when they're not allowed
Discourse.Utilities.cropAvatar(data.result.url, data.files[0].type).then(function(avatarTemplate) {
self.set("uploadedAvatarTemplate", avatarTemplate);
// indicates the users is using an uploaded avatar (must happen after cropping, otherwise
// we will attempt to load an invalid avatar and cache a redirect to old one, uploadedAvatarTemplate
// trumps over custom avatar upload id)
self.set("custom_avatar_upload_id", data.result.upload_id);
});
// the upload is now done

View File

@ -351,10 +351,13 @@ Discourse.User = Discourse.Model.extend({
Change avatar selection
*/
pickAvatar: function(uploadId) {
this.set("uploaded_avatar_id", uploadId);
var self = this;
return Discourse.ajax("/users/" + this.get("username_lower") + "/preferences/avatar/pick", {
type: 'PUT',
data: { upload_id: uploadId }
}).then(function(){
self.set('uploaded_avatar_id', uploadId);
});
},

View File

@ -45,15 +45,17 @@ export default RestrictedUserRoute.extend(ShowFooter, {
// sends the information to the server if it has changed
if (avatarSelector.get('selectedUploadId') !== user.get('uploaded_avatar_id')) {
user.pickAvatar(avatarSelector.get('selectedUploadId'));
user.pickAvatar(avatarSelector.get('selectedUploadId'))
.then(function(){
user.setProperties(avatarSelector.getProperties(
'system_avatar_upload_id',
'gravatar_avatar_upload_id',
'custom_avatar_upload_id'
));
});
}
// saves the data back
user.setProperties(avatarSelector.getProperties(
'system_avatar_upload_id',
'gravatar_avatar_upload_id',
'custom_avatar_upload_id'
));
avatarSelector.send('closeModal');
},