mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 11:47:23 +03:00
Use enumalike thing
This commit is contained in:
parent
73e486cc58
commit
9e45279894
2 changed files with 15 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue