Small improvements to code.

This commit is contained in:
Kavin 2022-08-01 17:53:07 +05:30
parent f18388c828
commit ef8dbb9074
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 5 additions and 9 deletions

View file

@ -87,12 +87,7 @@ export default {
}, },
getUnauthenticatedChannels() { getUnauthenticatedChannels() {
const localSubscriptions = this.getLocalSubscriptions(); const localSubscriptions = this.getLocalSubscriptions();
var channels = ""; return localSubscriptions.join(",");
localSubscriptions.forEach((element, index) => {
channels += element;
if (localSubscriptions.size != index) channels += ",";
});
return channels;
}, },
}, },
}; };

View file

@ -208,11 +208,12 @@ const mixin = {
return localSubscriptions.includes(channelId); return localSubscriptions.includes(channelId);
}, },
handleLocalSubscriptions(channelId) { handleLocalSubscriptions(channelId) {
var localSubscriptions = this.getLocalSubscriptions(); var localSubscriptions = this.getLocalSubscriptions() ?? [];
if (localSubscriptions == null || localSubscriptions.size == 0) localSubscriptions = [channelId]; if (localSubscriptions.includes(channelId))
else if (localSubscriptions.includes(channelId))
localSubscriptions.splice(localSubscriptions.indexOf(channelId)); localSubscriptions.splice(localSubscriptions.indexOf(channelId));
else localSubscriptions.push(channelId); else localSubscriptions.push(channelId);
// Sort for better cache hits
localSubscriptions.sort();
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions)); localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
}, },
}, },