mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Various PR feedback
This commit is contained in:
parent
9e45279894
commit
af48b8920e
2 changed files with 66 additions and 57 deletions
|
@ -24,10 +24,12 @@ export const MENTIONS_ONLY = 'mentions_only';
|
||||||
export const MUTE = 'mute';
|
export const MUTE = 'mute';
|
||||||
|
|
||||||
export function getRoomNotifsState(roomId) {
|
export function getRoomNotifsState(roomId) {
|
||||||
|
if (MatrixClientPeg.get().isGuest()) return RoomNotifs.ALL_MESSAGES;
|
||||||
|
|
||||||
// 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) {
|
||||||
return MUTE;
|
return MUTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,58 +52,71 @@ export function getRoomNotifsState(roomId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setRoomNotifsState(roomId, newState) {
|
export function setRoomNotifsState(roomId, newState) {
|
||||||
|
if (newState == 'mute') {
|
||||||
|
return setRoomNotifsStateMuted(roomId);
|
||||||
|
} else {
|
||||||
|
return setRoomNotifsStateUnmuted(roomId, newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRoomNotifsStateMuted(roomId) {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
if (newState == 'mute') {
|
// delete the room rule
|
||||||
// delete the room rule
|
const roomRule = cli.getRoomPushRule('global', roomId);
|
||||||
const roomRule = MatrixClientPeg.get().getRoomPushRule('global', roomId);
|
if (roomRule) {
|
||||||
if (roomRule) {
|
promises.push(cli.deletePushRule('global', 'room', roomRule.rule_id));
|
||||||
promises.push(cli.deletePushRule('global', 'room', roomRule.rule_id));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// add an override rule to squelch everything in this room
|
// add an override rule to squelch everything in this room
|
||||||
promises.push(cli.addPushRule('global', 'override', roomId, {
|
promises.push(cli.addPushRule('global', 'override', roomId, {
|
||||||
conditions: [
|
conditions: [
|
||||||
{
|
{
|
||||||
kind: 'event_match',
|
kind: 'event_match',
|
||||||
key: 'room_id',
|
key: 'room_id',
|
||||||
pattern: roomId,
|
pattern: roomId,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
actions: [
|
||||||
|
'dont_notify',
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
|
||||||
|
return q.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setRoomNotifsStateUnmuted(roomId, newState) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
|
const overrideMuteRule = findOverrideMuteRule(roomId);
|
||||||
|
if (overrideMuteRule) {
|
||||||
|
promises.push(cli.deletePushRule('global', 'override', overrideMuteRule.rule_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newState == 'all_messages') {
|
||||||
|
promises.push(cli.deletePushRule('global', 'room', roomId));
|
||||||
|
} else if (newState == 'mentions_only') {
|
||||||
|
promises.push(cli.addPushRule('global', 'room', roomId, {
|
||||||
actions: [
|
actions: [
|
||||||
'dont_notify',
|
'dont_notify',
|
||||||
]
|
]
|
||||||
}));
|
}));
|
||||||
} else {
|
// https://matrix.org/jira/browse/SPEC-400
|
||||||
const overrideMuteRule = findOverrideMuteRule(roomId);
|
promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true));
|
||||||
if (overrideMuteRule) {
|
} else if ('all_messages_loud') {
|
||||||
promises.push(cli.deletePushRule('global', 'override', overrideMuteRule.rule_id));
|
promises.push(cli.addPushRule('global', 'room', roomId, {
|
||||||
}
|
actions: [
|
||||||
|
'notify',
|
||||||
if (newState == 'all_messages') {
|
{
|
||||||
promises.push(cli.deletePushRule('global', 'room', roomId));
|
set_tweak: 'sound',
|
||||||
} else if (newState == 'mentions_only') {
|
value: 'default',
|
||||||
promises.push(cli.addPushRule('global', 'room', roomId, {
|
}
|
||||||
actions: [
|
]
|
||||||
'dont_notify',
|
}));
|
||||||
]
|
// https://matrix.org/jira/browse/SPEC-400
|
||||||
}));
|
promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true));
|
||||||
// https://matrix.org/jira/browse/SPEC-400
|
|
||||||
promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true));
|
|
||||||
} else if ('all_messages_loud') {
|
|
||||||
promises.push(cli.addPushRule('global', 'room', roomId, {
|
|
||||||
actions: [
|
|
||||||
'notify',
|
|
||||||
{
|
|
||||||
set_tweak: 'sound',
|
|
||||||
value: 'default',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
// https://matrix.org/jira/browse/SPEC-400
|
|
||||||
promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return q.all(promises);
|
return q.all(promises);
|
||||||
|
@ -110,7 +125,7 @@ export function setRoomNotifsState(roomId, newState) {
|
||||||
function findOverrideMuteRule(roomId) {
|
function findOverrideMuteRule(roomId) {
|
||||||
for (const rule of MatrixClientPeg.get().pushRules['global'].override) {
|
for (const rule of MatrixClientPeg.get().pushRules['global'].override) {
|
||||||
if (isRuleForRoom(roomId, rule)) {
|
if (isRuleForRoom(roomId, rule)) {
|
||||||
if (isMuteRule(rule)) {
|
if (isMuteRule(rule) && rule.enabled) {
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,29 +49,23 @@ module.exports = React.createClass({
|
||||||
badgeHover : false,
|
badgeHover : false,
|
||||||
notificationTagMenu: false,
|
notificationTagMenu: false,
|
||||||
roomTagMenu: false,
|
roomTagMenu: false,
|
||||||
notifState: this._getNotifState(),
|
notifState: RoomNotifs.getRoomNotifsState(this.props.room.roomId),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getNotifState: function() {
|
|
||||||
if (MatrixClientPeg.get().isGuest()) return RoomNotifs.ALL_MESSAGES;
|
|
||||||
return RoomNotifs.getRoomNotifsState(this.props.room.roomId);
|
|
||||||
},
|
|
||||||
|
|
||||||
_shouldShowNotifBadge: function() {
|
_shouldShowNotifBadge: function() {
|
||||||
const showBadgeInStates = [RoomNotifs.ALL_MESSAGES, RoomNotifs.ALL_MESSAGES_LOUD];
|
const showBadgeInStates = [RoomNotifs.ALL_MESSAGES, RoomNotifs.ALL_MESSAGES_LOUD];
|
||||||
const currentState = this._getNotifState();
|
return showBadgeInStates.indexOf(this.state.notifState) > -1;
|
||||||
return showBadgeInStates.indexOf(currentState) > -1;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_shouldShowMentionBadge: function() {
|
_shouldShowMentionBadge: function() {
|
||||||
return this._getNotifState() != RoomNotifs.MUTE;
|
return this.state.notifState != RoomNotifs.MUTE;
|
||||||
},
|
},
|
||||||
|
|
||||||
onAccountData: function(accountDataEvent) {
|
onAccountData: function(accountDataEvent) {
|
||||||
if (accountDataEvent.getType() == 'm.push_rules') {
|
if (accountDataEvent.getType() == 'm.push_rules') {
|
||||||
this.setState({
|
this.setState({
|
||||||
notifState: this._getNotifState(),
|
notifState: RoomNotifs.getRoomNotifsState(this.props.room.roomId),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -193,7 +187,7 @@ module.exports = React.createClass({
|
||||||
'mx_RoomTile_selected': this.props.selected,
|
'mx_RoomTile_selected': this.props.selected,
|
||||||
'mx_RoomTile_unread': this.props.unread,
|
'mx_RoomTile_unread': this.props.unread,
|
||||||
'mx_RoomTile_unreadNotify': notificationCount > 0 && this._shouldShowNotifBadge(),
|
'mx_RoomTile_unreadNotify': notificationCount > 0 && this._shouldShowNotifBadge(),
|
||||||
'mx_RoomTile_highlight': this.props.highlight && badges,
|
'mx_RoomTile_highlight': this.props.highlight && this._shouldShowMentionBadge(),
|
||||||
'mx_RoomTile_invited': (me && me.membership == 'invite'),
|
'mx_RoomTile_invited': (me && me.membership == 'invite'),
|
||||||
'mx_RoomTile_notificationTagMenu': this.state.notificationTagMenu,
|
'mx_RoomTile_notificationTagMenu': this.state.notificationTagMenu,
|
||||||
'mx_RoomTile_noBadges': !badges,
|
'mx_RoomTile_noBadges': !badges,
|
||||||
|
|
Loading…
Reference in a new issue