Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Speed up room unread checks by not hitting the SettingsStore so often #2339

Merged
merged 2 commits into from
Dec 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/shouldHideEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ function memberEventDiff(ev) {
}

export default function shouldHideEvent(ev) {
// Wrap getValue() for readability
// Wrap getValue() for readability. Calling the SettingsStore can be
// fairly resource heavy, so the checks below should avoid hitting it
// where possible.
const isEnabled = (name) => SettingsStore.getValue(name, ev.getRoomId());

// Hide redacted events
if (isEnabled('hideRedactions') && ev.isRedacted()) return true;
if (ev.isRedacted() && isEnabled('hideRedactions')) return true;

const eventDiff = memberEventDiff(ev);

if (eventDiff.isMemberEvent) {
if (isEnabled('hideJoinLeaves') && (eventDiff.isJoin || eventDiff.isPart)) return true;
if (isEnabled('hideAvatarChanges') && eventDiff.isAvatarChange) return true;
if (isEnabled('hideDisplaynameChanges') && eventDiff.isDisplaynameChange) return true;
if ((eventDiff.isJoin || eventDiff.isPart) && isEnabled('hideJoinLeaves')) return true;
if (eventDiff.isAvatarChange && isEnabled('hideAvatarChanges')) return true;
if (eventDiff.isDisplaynameChange && isEnabled('hideDisplaynameChanges')) return true;
}

return false;
Expand Down