mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 20:54:59 +08:00
Use enumalike thing
This commit is contained in:
parent
73e486cc58
commit
9e45279894
@ -18,12 +18,17 @@ import MatrixClientPeg from './MatrixClientPeg';
|
|||||||
import PushProcessor from 'matrix-js-sdk/lib/pushprocessor';
|
import PushProcessor from 'matrix-js-sdk/lib/pushprocessor';
|
||||||
import q from 'q';
|
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) {
|
export function getRoomNotifsState(roomId) {
|
||||||
// look through the override rules for a rule affecting this room:
|
// look through the override rules for a rule affecting this room:
|
||||||
// if one exists, it will take precedence.
|
// if one exists, it will take precedence.
|
||||||
const muteRule = findOverrideMuteRule(roomId);
|
const muteRule = findOverrideMuteRule(roomId);
|
||||||
if (muteRule && muteRule.enabled) {
|
if (muteRule && muteRule.enabled) {
|
||||||
return 'mute';
|
return MUTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for everything else, look at the room rule.
|
// 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
|
// 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
|
// (in particular this will be 'wrong' for one to one rooms because
|
||||||
// they will notify loudly for all messages)
|
// 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
|
// a mute at the room level will still allow mentions
|
||||||
// to notify
|
// to notify
|
||||||
if (isMuteRule(roomRule)) return 'mentions_only';
|
if (isMuteRule(roomRule)) return MENTIONS_ONLY;
|
||||||
|
|
||||||
const actionsObject = PushProcessor.actionListToActionsObject(roomRule.actions);
|
const actionsObject = PushProcessor.actionListToActionsObject(roomRule.actions);
|
||||||
if (actionsObject.tweaks.sound) return 'all_messages_loud';
|
if (actionsObject.tweaks.sound) return ALL_MESSAGES_LOUD;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -54,18 +54,18 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_getNotifState: function() {
|
_getNotifState: function() {
|
||||||
if (MatrixClientPeg.get().isGuest()) return 'all_messages';
|
if (MatrixClientPeg.get().isGuest()) return RoomNotifs.ALL_MESSAGES;
|
||||||
return RoomNotifs.getRoomNotifsState(this.props.room.roomId);
|
return RoomNotifs.getRoomNotifsState(this.props.room.roomId);
|
||||||
},
|
},
|
||||||
|
|
||||||
_shouldShowNotifBadge: function() {
|
_shouldShowNotifBadge: function() {
|
||||||
const showBadgeInStates = ['all_messages', 'all_messages_loud'];
|
const showBadgeInStates = [RoomNotifs.ALL_MESSAGES, RoomNotifs.ALL_MESSAGES_LOUD];
|
||||||
const currentState = this._getNotifState();
|
const currentState = this._getNotifState();
|
||||||
return showBadgeInStates.indexOf(currentState) > -1;
|
return showBadgeInStates.indexOf(currentState) > -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
_shouldShowMentionBadge: function() {
|
_shouldShowMentionBadge: function() {
|
||||||
return this._getNotifState() != 'mute';
|
return this._getNotifState() != RoomNotifs.MUTE;
|
||||||
},
|
},
|
||||||
|
|
||||||
onAccountData: function(accountDataEvent) {
|
onAccountData: function(accountDataEvent) {
|
||||||
@ -184,8 +184,9 @@ module.exports = React.createClass({
|
|||||||
var notificationCount = this.props.room.getUnreadNotificationCount();
|
var notificationCount = this.props.room.getUnreadNotificationCount();
|
||||||
// var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
|
// var highlightCount = this.props.room.getUnreadNotificationCount("highlight");
|
||||||
|
|
||||||
var badges = notificationCount > 0 && this._shouldShowNotifBadge();
|
const notifBadges = notificationCount > 0 && this._shouldShowNotifBadge();
|
||||||
badges |= this.props.highlight && this._shouldShowMentionBadge();
|
const mentionBadges = this.props.highlight && this._shouldShowMentionBadge();
|
||||||
|
const badges = notifBadges || mentionBadges;
|
||||||
|
|
||||||
var classes = classNames({
|
var classes = classNames({
|
||||||
'mx_RoomTile': true,
|
'mx_RoomTile': true,
|
||||||
|
Loading…
Reference in New Issue
Block a user