mirror of https://github.com/zulip/zulip.git
people: Add `version` parameter for medium sized avatar urls.
We need to append the `version` parameter when constructing the urls for medium-sized images so that the browser updates the image in real time when the user uploads a new avatar. Fixes #25558.
This commit is contained in:
parent
12db83b011
commit
7ac891a6b9
|
@ -736,7 +736,14 @@ export function medium_avatar_url_for_person(person) {
|
|||
return medium_gravatar_url_for_email(person.email);
|
||||
}
|
||||
|
||||
return "/avatar/" + person.user_id + "/medium";
|
||||
// We need to attach a version to the URL as a cache-breaker so that the browser
|
||||
// will update the image in real time when user uploads a new avatar.
|
||||
//
|
||||
// TODO: Newly created users sometimes are first learned about via
|
||||
// the report_late_add code path; these are missing the avatar_version
|
||||
// metadata. Long term, we should clean up that possibility, but
|
||||
// until it is, we fallback to using a version number of 0.
|
||||
return `/avatar/${person.user_id}/medium?version=${person.avatar_version ?? 0}`;
|
||||
}
|
||||
|
||||
export function sender_info_for_recent_topics_row(sender_ids) {
|
||||
|
|
|
@ -746,8 +746,8 @@ test_people("message_methods", () => {
|
|||
people.medium_avatar_url_for_person(maria),
|
||||
"https://secure.gravatar.com/avatar/6dbdd7946b58d8b11351fcb27e5cdd55?d=identicon&s=500",
|
||||
);
|
||||
assert.equal(people.medium_avatar_url_for_person(charles), "/avatar/301/medium");
|
||||
assert.equal(people.medium_avatar_url_for_person(ashton), "/avatar/303/medium");
|
||||
assert.equal(people.medium_avatar_url_for_person(charles), "/avatar/301/medium?version=0");
|
||||
assert.equal(people.medium_avatar_url_for_person(ashton), "/avatar/303/medium?version=0");
|
||||
|
||||
muted_users.add_muted_user(30);
|
||||
assert.deepEqual(people.sender_info_for_recent_topics_row([30]), [
|
||||
|
|
|
@ -206,7 +206,7 @@ test_ui("sender_hover", ({override, mock_template}) => {
|
|||
handler.call($target, e);
|
||||
|
||||
const avatar_img = image_stubber.get(0);
|
||||
assert.equal(avatar_img.src.toString(), "/avatar/42/medium");
|
||||
assert.equal(avatar_img.src.toString(), "/avatar/42/medium?version=5");
|
||||
|
||||
// todo: load image
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue