mirror of https://github.com/zulip/zulip.git
Prevent stale avatars from showing in new messages.
When you upload a 2nd avatar to Zulip, the URL doesn't actually change, so even new messages can show the old avatar, if your browser is caching. We work against the cache by having the "stamp" argument, which we vary at reload time and also when we upload the new avatar. The browser still benefits from cached images as new messages come in. (imported from commit 84869c8d7f251c9f2498026a5e9e3b2451784879)
This commit is contained in:
parent
a4f3577832
commit
8339a40acd
|
@ -20,9 +20,11 @@ function is_local_part(value, element) {
|
|||
return this.optional(element) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i.test(value);
|
||||
}
|
||||
|
||||
// Choose avatar stamp fairly randomly, to help get old avatars out of cache.
|
||||
exports.avatar_stamp = Math.floor(Math.random()*100);
|
||||
|
||||
$(function () {
|
||||
|
||||
var avatar_stamp = 1;
|
||||
|
||||
function upload_avatar(file_input) {
|
||||
var form_data = new FormData();
|
||||
|
@ -44,9 +46,9 @@ $(function () {
|
|||
contentType: false,
|
||||
success: function (data) {
|
||||
util.destroy_loading_indicator($("#upload_avatar_spinner"));
|
||||
var url = data.avatar_url + '&stamp=' + avatar_stamp;
|
||||
var url = data.avatar_url + '&stamp=' + exports.avatar_stamp;
|
||||
$("#user-settings-avatar").expectOne().attr("src", url);
|
||||
avatar_stamp += 1;
|
||||
exports.avatar_stamp += 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -274,4 +276,5 @@ $(function () {
|
|||
|
||||
});
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
|
|
@ -25,7 +25,6 @@ exports.home_tab_obscured = function () {
|
|||
// scrollbar when we switch to a new tab (and restore it
|
||||
// when we switch back.)
|
||||
var scroll_positions = {};
|
||||
var gravatar_stamp = 1;
|
||||
|
||||
exports.change_tab_to = function (tabname) {
|
||||
$('#gear-menu a[href="' + tabname + '"]').tab('show');
|
||||
|
@ -690,7 +689,7 @@ function toggle_star(row_id) {
|
|||
|
||||
exports.small_avatar_url = function (message) {
|
||||
// Try to call this function in all places where we need 25px
|
||||
// gravatar images, so that the browser can help
|
||||
// avatar images, so that the browser can help
|
||||
// us avoid unnecessary network trips. (For user-uploaded avatars,
|
||||
// the s=25 parameter is essentially ignored, but it's harmless.)
|
||||
//
|
||||
|
@ -699,7 +698,7 @@ exports.small_avatar_url = function (message) {
|
|||
if (message.avatar_url) {
|
||||
var url = message.avatar_url + "&s=50";
|
||||
if (message.sent_by_me) {
|
||||
url += "&stamp=" + gravatar_stamp;
|
||||
url += "&stamp=" + settings.avatar_stamp;
|
||||
}
|
||||
return url;
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,7 @@ var globals =
|
|||
+ ' compose compose_fade rows hotkeys narrow reload notifications_bar search subs'
|
||||
+ ' composebox_typeahead typeahead_helper notifications hashchange'
|
||||
+ ' invite ui util activity timerender MessageList MessageListView blueslip unread stream_list'
|
||||
+ ' message_edit tab_bar emoji popovers navigate message_tour'
|
||||
+ ' message_edit tab_bar emoji popovers navigate message_tour settings'
|
||||
+ ' avatar feature_flags search_suggestion referral stream_color Dict'
|
||||
+ ' Filter summary admin stream_data muting WinChan muting_ui Socket'
|
||||
|
||||
|
|
Loading…
Reference in New Issue