Skip to content

Commit

Permalink
Merge pull request RocketChat#293 from shubhsherl/fix_profile_1
Browse files Browse the repository at this point in the history
Cache user avatar without '_dc' params
  • Loading branch information
ear-dev authored May 29, 2020
2 parents 40e29d8 + 6f4ffd0 commit 628f094
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/ui-utils/client/lib/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ export const updateAvatarOfUsername = function(username) {
$(`.sidebar-item.js-sidebar-type-d .sidebar-item__link[aria-label='${ username }'] .avatar-image`)
.attr('src', url);

// force reload of avatar on sidenav header
$(`.sidebar__header .sidebar__header-thumb .avatar-image[alt='${ username }']`).attr('src', url);

return true;
};
12 changes: 12 additions & 0 deletions public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function hasSameHash(firstUrl, secondUrl) {
}
}

function handleAvatar(request, response) {
const clonedResponse = response.clone();
const url = request.url.split('?')[0];
caches.open(version).then((cache) => cache.put(new Request(url), clonedResponse));
}

const fetchFromNetwork = (event) => {
const requestToFetch = event.request.clone();
return fetch(requestToFetch, { cache: 'reload' }).then((response) => {
Expand All @@ -37,6 +43,12 @@ const fetchFromNetwork = (event) => {
}
})));
}

if (/avatar\/.*\?_dc/.test(event.request.url)) {
// handle the avatar updates
handleAvatar(event.request, response);
}

caches.open(version).then((cache) => cache.put(event.request, clonedResponse));
}
return response;
Expand Down

0 comments on commit 628f094

Please sign in to comment.