From 9e45279894c6d7d31d496393835f546a5134e15b Mon Sep 17 00:00:00 2001
From: David Baker <dave@matrix.org>
Date: Thu, 18 Aug 2016 13:44:58 +0100
Subject: [PATCH] Use enumalike thing

---
 src/RoomNotifs.js                      | 13 +++++++++----
 src/components/views/rooms/RoomTile.js | 11 ++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/RoomNotifs.js b/src/RoomNotifs.js
index 704fdd17b8..6f792df26b 100644
--- a/src/RoomNotifs.js
+++ b/src/RoomNotifs.js
@@ -18,12 +18,17 @@ import MatrixClientPeg from './MatrixClientPeg';
 import PushProcessor from 'matrix-js-sdk/lib/pushprocessor';
 import q from 'q';
 
+export const ALL_MESSAGES_LOUD = 'all_messages_loud';
+export const ALL_MESSAGES = 'all_messages';
+export const MENTIONS_ONLY = 'mentions_only';
+export const MUTE = 'mute';
+
 export function getRoomNotifsState(roomId) {
     // look through the override rules for a rule affecting this room:
     // if one exists, it will take precedence.
     const muteRule = findOverrideMuteRule(roomId);
     if (muteRule && muteRule.enabled) {
-        return 'mute';
+        return MUTE;
     }
 
     // for everything else, look at the room rule.
@@ -32,14 +37,14 @@ export function getRoomNotifsState(roomId) {
     // XXX: We have to assume the default is to notify for all messages
     // (in particular this will be 'wrong' for one to one rooms because
     // they will notify loudly for all messages)
-    if (!roomRule || !roomRule.enabled) return 'all_messages';
+    if (!roomRule || !roomRule.enabled) return ALL_MESSAGES;
 
     // a mute at the room level will still allow mentions
     // to notify
-    if (isMuteRule(roomRule)) return 'mentions_only';
+    if (isMuteRule(roomRule)) return MENTIONS_ONLY;
 
     const actionsObject = PushProcessor.actionListToActionsObject(roomRule.actions);
-    if (actionsObject.tweaks.sound) return 'all_messages_loud';
+    if (actionsObject.tweaks.sound) return ALL_MESSAGES_LOUD;
 
     return null;
 }
diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js
index 8a7b83cb44..5b508b6ad0 100644
--- a/src/components/views/rooms/RoomTile.js
+++ b/src/components/views/rooms/RoomTile.js
@@ -54,18 +54,18 @@ module.exports = React.createClass({
     },
 
     _getNotifState: function() {
-        if (MatrixClientPeg.get().isGuest()) return 'all_messages';
+        if (MatrixClientPeg.get().isGuest()) return RoomNotifs.ALL_MESSAGES;
         return RoomNotifs.getRoomNotifsState(this.props.room.roomId);
     },
 
     _shouldShowNotifBadge: function() {
-        const showBadgeInStates = ['all_messages', 'all_messages_loud'];
+        const showBadgeInStates = [RoomNotifs.ALL_MESSAGES, RoomNotifs.ALL_MESSAGES_LOUD];
         const currentState = this._getNotifState();
         return showBadgeInStates.indexOf(currentState) > -1;
     },
 
     _shouldShowMentionBadge: function() {
-        return this._getNotifState() != 'mute';
+        return this._getNotifState() != RoomNotifs.MUTE;
     },
 
     onAccountData: function(accountDataEvent) {
@@ -184,8 +184,9 @@ module.exports = React.createClass({
         var notificationCount = this.props.room.getUnreadNotificationCount();
         // var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
 
-        var badges = notificationCount > 0 && this._shouldShowNotifBadge();
-        badges |= this.props.highlight && this._shouldShowMentionBadge();
+        const notifBadges = notificationCount > 0 && this._shouldShowNotifBadge();
+        const mentionBadges = this.props.highlight && this._shouldShowMentionBadge();
+        const badges = notifBadges || mentionBadges;
 
         var classes = classNames({
             'mx_RoomTile': true,