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',
label: 'Hide join/leave messages (invites/kicks/bans unaffected)',
},
{
id: 'hideAvatarDisplaynameChanges',
label: 'Hide Avatar and Display Name changes',
},
{
id: 'useCompactLayout',
label: 'Use compact timeline layout',

View file

@ -346,6 +346,7 @@
"Hangup": "Hangup",
"Hide Apps": "Hide Apps",
"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 Text Formatting Toolbar": "Hide Text Formatting Toolbar",
"Historical": "Historical",

View file

@ -14,38 +14,36 @@
limitations under the License.
*/
function _isLeaveOrJoin(ev) {
const isMemberEvent = ev.getType() === 'm.room.member' && ev.getStateKey() !== undefined;
if (!isMemberEvent) {
return false; // bail early: all the checks below concern member events only
}
function memberEventDiff(ev) {
const diff = {
isMembershipEvent: ev.getType() === 'm.room.member' && ev.getStateKey() !== undefined,
};
// TODO: These checks are done to make sure we're dealing with membership transitions not avatar changes / dupe joins
// 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
}
if (!diff.isMembershipEvent) return diff;
const content = ev.getContent();
const prevContent = ev.getPrevContent();
// this only applies to joins/invited joins/leaves not invites/kicks/bans
const isJoin = membership === 'join' && prevMembership !== 'ban';
const isLeave = membership === 'leave' && ev.getStateKey() === ev.getSender();
return isJoin || isLeave;
diff.isJoin = content.membership === 'join' && prevContent.membership !== 'ban';
diff.isPart = content.membership === 'leave' && ev.getStateKey() === ev.getSender();
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) {
// Hide redacted events
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;
}