allow hiding of avatar/display name changes

This commit is contained in:
Michael Telatynski 2017-08-04 17:22:01 +01:00
parent 91c96c1c27
commit ffdffb643d
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E
3 changed files with 28 additions and 25 deletions

View file

@ -85,6 +85,10 @@ const SETTINGS_LABELS = [
id: 'hideJoinLeaves', id: 'hideJoinLeaves',
label: 'Hide join/leave messages (invites/kicks/bans unaffected)', label: 'Hide join/leave messages (invites/kicks/bans unaffected)',
}, },
{
id: 'hideAvatarDisplaynameChanges',
label: 'Hide Avatar and Display Name changes',
},
{ {
id: 'useCompactLayout', id: 'useCompactLayout',
label: 'Use compact timeline layout', label: 'Use compact timeline layout',

View file

@ -346,6 +346,7 @@
"Hangup": "Hangup", "Hangup": "Hangup",
"Hide Apps": "Hide Apps", "Hide Apps": "Hide Apps",
"Hide join/leave messages (invites/kicks/bans unaffected)": "Hide join/leave messages (invites/kicks/bans unaffected)", "Hide join/leave messages (invites/kicks/bans unaffected)": "Hide join/leave messages (invites/kicks/bans unaffected)",
"Hide Avatar and Display Name changes": "Hide Avatar and Display Name changes",
"Hide read receipts": "Hide read receipts", "Hide read receipts": "Hide read receipts",
"Hide Text Formatting Toolbar": "Hide Text Formatting Toolbar", "Hide Text Formatting Toolbar": "Hide Text Formatting Toolbar",
"Historical": "Historical", "Historical": "Historical",

View file

@ -14,38 +14,36 @@
limitations under the License. limitations under the License.
*/ */
function _isLeaveOrJoin(ev) { function memberEventDiff(ev) {
const isMemberEvent = ev.getType() === 'm.room.member' && ev.getStateKey() !== undefined; const diff = {
if (!isMemberEvent) { isMembershipEvent: ev.getType() === 'm.room.member' && ev.getStateKey() !== undefined,
return false; // bail early: all the checks below concern member events only };
}
// TODO: These checks are done to make sure we're dealing with membership transitions not avatar changes / dupe joins if (!diff.isMembershipEvent) return diff;
// These checks are also being done in TextForEvent and should really reside in the JS SDK as a helper function
const membership = ev.getContent().membership;
const prevMembership = ev.getPrevContent().membership;
if (membership === prevMembership && membership === 'join') {
// join -> join : This happens when display names change / avatars are set / genuine dupe joins with no changes.
// Find out which we're dealing with.
if (ev.getPrevContent().displayname !== ev.getContent().displayname) {
return false; // display name changed
}
if (ev.getPrevContent().avatar_url !== ev.getContent().avatar_url) {
return false; // avatar url changed
}
// dupe join event, fall through to hide rules
}
const content = ev.getContent();
const prevContent = ev.getPrevContent();
// this only applies to joins/invited joins/leaves not invites/kicks/bans diff.isJoin = content.membership === 'join' && prevContent.membership !== 'ban';
const isJoin = membership === 'join' && prevMembership !== 'ban'; diff.isPart = content.membership === 'leave' && ev.getStateKey() === ev.getSender();
const isLeave = membership === 'leave' && ev.getStateKey() === ev.getSender();
return isJoin || isLeave; const isJoinToJoin = content.membership === prevContent.membership && content.membership === 'join';
diff.isDisplaynameChange = isJoinToJoin && content.displayname !== prevContent.displayname;
diff.isAvatarChange = isJoinToJoin && content.avatar_url !== prevContent.avatar_url;
return diff;
} }
export default function(ev, syncedSettings) { export default function(ev, syncedSettings) {
// Hide redacted events // Hide redacted events
if (syncedSettings['hideRedactions'] && ev.isRedacted()) return true; if (syncedSettings['hideRedactions'] && ev.isRedacted()) return true;
if (syncedSettings['hideJoinLeaves'] && _isLeaveOrJoin(ev)) return true;
const eventDiff = memberEventDiff(ev);
if (eventDiff.isMembershipEvent) {
if (syncedSettings['hideJoinLeaves'] && (eventDiff.isJoin || eventDiff.isPart)) return true;
const isMemberAvatarDisplaynameChange = eventDiff.isAvatarChange || eventDiff.isDisplaynameChange;
if (syncedSettings['hideAvatarDisplaynameChanges'] && isMemberAvatarDisplaynameChange) return true;
}
return false; return false;
} }