mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Added 'default' option to channel notification settings that just uses the user's notification level
This commit is contained in:
@@ -76,7 +76,7 @@ func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.C
|
||||
|
||||
if addMember {
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: c.Session.UserId,
|
||||
Roles: model.CHANNEL_ROLE_ADMIN, NotifyLevel: model.CHANNEL_NOTIFY_ALL}
|
||||
Roles: model.CHANNEL_ROLE_ADMIN, NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
return nil, cmresult.Err
|
||||
@@ -135,7 +135,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
|
||||
return nil, err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId,
|
||||
Roles: "", NotifyLevel: model.CHANNEL_NOTIFY_ALL}
|
||||
Roles: "", NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
return nil, cmresult.Err
|
||||
@@ -372,7 +372,7 @@ func JoinChannel(c *Context, channelId string, role string) {
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: role}
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, Roles: role}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
c.Err = cmresult.Err
|
||||
@@ -405,7 +405,7 @@ func JoinDefaultChannels(user *model.User, channelRole string) *model.AppError {
|
||||
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "town-square"); result.Err != nil {
|
||||
err = result.Err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole}
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, Roles: channelRole}
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
}
|
||||
@@ -414,7 +414,7 @@ func JoinDefaultChannels(user *model.User, channelRole string) *model.AppError {
|
||||
if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil {
|
||||
err = result.Err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_ALL, Roles: channelRole}
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, Roles: channelRole}
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
}
|
||||
@@ -694,7 +694,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
oUser := oresult.Data.(*model.User)
|
||||
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: userId, NotifyLevel: model.CHANNEL_NOTIFY_ALL}
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: userId, NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", userId, id, cmresult.Err)
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
const (
|
||||
CHANNEL_ROLE_ADMIN = "admin"
|
||||
CHANNEL_NOTIFY_DEFAULT = "default"
|
||||
CHANNEL_NOTIFY_ALL = "all"
|
||||
CHANNEL_NOTIFY_MENTION = "mention"
|
||||
CHANNEL_NOTIFY_NONE = "none"
|
||||
CHANNEL_NOTIFY_QUIET = "quiet"
|
||||
CHANNEL_NOTIFY_QUIET = "quiet" // TODO deprecate me
|
||||
)
|
||||
|
||||
type ChannelMember struct {
|
||||
@@ -76,5 +77,9 @@ func (o *ChannelMember) PreSave() {
|
||||
}
|
||||
|
||||
func IsChannelNotifyLevelValid(notifyLevel string) bool {
|
||||
return notifyLevel == CHANNEL_NOTIFY_ALL || notifyLevel == CHANNEL_NOTIFY_MENTION || notifyLevel == CHANNEL_NOTIFY_NONE || notifyLevel == CHANNEL_NOTIFY_QUIET
|
||||
return notifyLevel == CHANNEL_NOTIFY_DEFAULT ||
|
||||
notifyLevel == CHANNEL_NOTIFY_ALL ||
|
||||
notifyLevel == CHANNEL_NOTIFY_MENTION ||
|
||||
notifyLevel == CHANNEL_NOTIFY_NONE ||
|
||||
notifyLevel == CHANNEL_NOTIFY_QUIET
|
||||
}
|
||||
|
||||
@@ -104,14 +104,28 @@ export default class ChannelNotifications extends React.Component {
|
||||
createDesktopSection(serverError) {
|
||||
var handleUpdateSection;
|
||||
|
||||
const user = UserStore.getCurrentUser();
|
||||
const globalNotifyLevel = user.notify_props.desktop;
|
||||
|
||||
let globalNotifyLevelName;
|
||||
if (globalNotifyLevel === 'all') {
|
||||
globalNotifyLevelName = 'For all activity';
|
||||
} else if (globalNotifyLevel === 'mention') {
|
||||
globalNotifyLevelName = 'Only for mentions';
|
||||
} else {
|
||||
globalNotifyLevelName = 'Never';
|
||||
}
|
||||
|
||||
if (this.state.activeSection === 'desktop') {
|
||||
var notifyActive = [false, false, false];
|
||||
if (this.state.notifyLevel === 'mention') {
|
||||
notifyActive[1] = true;
|
||||
} else if (this.state.notifyLevel === 'all') {
|
||||
var notifyActive = [false, false, false, false];
|
||||
if (this.state.notifyLevel === 'default') {
|
||||
notifyActive[0] = true;
|
||||
} else {
|
||||
} else if (this.state.notifyLevel === 'all') {
|
||||
notifyActive[1] = true;
|
||||
} else if (this.state.notifyLevel === 'mention') {
|
||||
notifyActive[2] = true;
|
||||
} else {
|
||||
notifyActive[3] = true;
|
||||
}
|
||||
|
||||
var inputs = [];
|
||||
@@ -123,9 +137,9 @@ export default class ChannelNotifications extends React.Component {
|
||||
<input
|
||||
type='radio'
|
||||
checked={notifyActive[0]}
|
||||
onChange={this.handleRadioClick.bind(this, 'all')}
|
||||
onChange={this.handleRadioClick.bind(this, 'default')}
|
||||
>
|
||||
For all activity
|
||||
{`Global default (${globalNotifyLevelName})`}
|
||||
</input>
|
||||
</label>
|
||||
<br/>
|
||||
@@ -135,9 +149,9 @@ export default class ChannelNotifications extends React.Component {
|
||||
<input
|
||||
type='radio'
|
||||
checked={notifyActive[1]}
|
||||
onChange={this.handleRadioClick.bind(this, 'mention')}
|
||||
onChange={this.handleRadioClick.bind(this, 'all')}
|
||||
>
|
||||
Only for mentions
|
||||
{'For all activity'}
|
||||
</input>
|
||||
</label>
|
||||
<br/>
|
||||
@@ -147,9 +161,21 @@ export default class ChannelNotifications extends React.Component {
|
||||
<input
|
||||
type='radio'
|
||||
checked={notifyActive[2]}
|
||||
onChange={this.handleRadioClick.bind(this, 'mention')}
|
||||
>
|
||||
{'Only for mentions'}
|
||||
</input>
|
||||
</label>
|
||||
<br/>
|
||||
</div>
|
||||
<div className='radio'>
|
||||
<label>
|
||||
<input
|
||||
type='radio'
|
||||
checked={notifyActive[3]}
|
||||
onChange={this.handleRadioClick.bind(this, 'none')}
|
||||
>
|
||||
Never
|
||||
{'Never'}
|
||||
</input>
|
||||
</label>
|
||||
</div>
|
||||
@@ -162,25 +188,14 @@ export default class ChannelNotifications extends React.Component {
|
||||
e.preventDefault();
|
||||
}.bind(this);
|
||||
|
||||
let curChannel = ChannelStore.get(this.state.channelId);
|
||||
let extraInfo = (
|
||||
const extraInfo = (
|
||||
<span>
|
||||
These settings will override the global notification settings.
|
||||
{'Selecting an option other than "Default" will override the global notification settings.'}
|
||||
<br/>
|
||||
Desktop notifications are available on Firefox, Safari, and Chrome.
|
||||
{'Desktop notifications are available on Firefox, Safari, and Chrome.'}
|
||||
</span>
|
||||
);
|
||||
|
||||
if (curChannel && curChannel.display_name) {
|
||||
extraInfo = (
|
||||
<span>
|
||||
These settings will override the global notification settings for the <b>{curChannel.display_name}</b> channel.
|
||||
<br/>
|
||||
Desktop notifications are available on Firefox, Safari, and Chrome.
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingItemMax
|
||||
title='Send desktop notifications'
|
||||
@@ -194,7 +209,9 @@ export default class ChannelNotifications extends React.Component {
|
||||
}
|
||||
|
||||
var describe;
|
||||
if (this.state.notifyLevel === 'mention') {
|
||||
if (this.state.notifyLevel === 'default') {
|
||||
describe = `Global default (${globalNotifyLevelName})`;
|
||||
} else if (this.state.notifyLevel === 'mention') {
|
||||
describe = 'Only for mentions';
|
||||
} else if (this.state.notifyLevel === 'all') {
|
||||
describe = 'For all activity';
|
||||
|
||||
@@ -200,13 +200,17 @@ export default class Sidebar extends React.Component {
|
||||
}
|
||||
var channel = ChannelStore.get(msg.channel_id);
|
||||
|
||||
var user = UserStore.getCurrentUser();
|
||||
if (user.notify_props && ((user.notify_props.desktop === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== 'D') || user.notify_props.desktop === 'none')) {
|
||||
return;
|
||||
const user = UserStore.getCurrentUser();
|
||||
const member = ChannelStore.getMember(msg.channel_id);
|
||||
|
||||
var notifyLevel = member.notify_level;
|
||||
if (notifyLevel === 'default') {
|
||||
notifyLevel = user.notify_props.desktop;
|
||||
}
|
||||
|
||||
var member = ChannelStore.getMember(msg.channel_id);
|
||||
if ((member.notify_level === 'mention' && mentions.indexOf(user.id) === -1) || member.notify_level === 'none' || member.notify_level === 'quiet') {
|
||||
if (notifyLevel === 'none') {
|
||||
return;
|
||||
} else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== 'D') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ function getNotificationsStateFromStores() {
|
||||
if (user.notify_props && user.notify_props.desktop_sound) {
|
||||
sound = user.notify_props.desktop_sound;
|
||||
}
|
||||
var desktop = 'all';
|
||||
var desktop = 'default';
|
||||
if (user.notify_props && user.notify_props.desktop) {
|
||||
desktop = user.notify_props.desktop;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user