Moved ChannelMember.NotifyLevel into ChannelMember.NotifyProps
Этот коммит содержится в:
@@ -23,7 +23,6 @@ func InitChannel(r *mux.Router) {
|
||||
sr.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST")
|
||||
sr.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST")
|
||||
sr.Handle("/update_desc", ApiUserRequired(updateChannelDesc)).Methods("POST")
|
||||
sr.Handle("/update_notify_level", ApiUserRequired(updateNotifyLevel)).Methods("POST")
|
||||
sr.Handle("/update_notify_props", ApiUserRequired(updateNotifyProps)).Methods("POST")
|
||||
sr.Handle("/{id:[A-Za-z0-9]+}/", ApiUserRequiredActivity(getChannel, false)).Methods("GET")
|
||||
sr.Handle("/{id:[A-Za-z0-9]+}/extra_info", ApiUserRequired(getChannelExtraInfo)).Methods("GET")
|
||||
@@ -76,8 +75,8 @@ func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.C
|
||||
sc := result.Data.(*model.Channel)
|
||||
|
||||
if addMember {
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: c.Session.UserId, Roles: model.CHANNEL_ROLE_ADMIN,
|
||||
NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: c.Session.UserId,
|
||||
Roles: model.CHANNEL_ROLE_ADMIN, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
return nil, cmresult.Err
|
||||
@@ -135,8 +134,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
|
||||
if sc, err := CreateChannel(c, channel, true); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId, Roles: "",
|
||||
NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId, Roles: "", NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
return nil, cmresult.Err
|
||||
@@ -373,8 +371,8 @@ func JoinChannel(c *Context, channelId string, role string) {
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId, Roles: role,
|
||||
NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: c.Session.UserId,
|
||||
Roles: role, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
|
||||
c.Err = cmresult.Err
|
||||
@@ -407,8 +405,8 @@ 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, Roles: channelRole,
|
||||
NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
|
||||
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
@@ -418,8 +416,8 @@ 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, Roles: channelRole,
|
||||
NotifyLevel: model.CHANNEL_NOTIFY_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
|
||||
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||
err = cmResult.Err
|
||||
@@ -700,8 +698,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_DEFAULT, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
cm := &model.ChannelMember{ChannelId: channel.Id, UserId: userId, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||
|
||||
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)
|
||||
@@ -791,45 +788,6 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
// TODO remove me
|
||||
func updateNotifyLevel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
data := model.MapFromJson(r.Body)
|
||||
userId := data["user_id"]
|
||||
if len(userId) != 26 {
|
||||
c.SetInvalidParam("updateNotifyLevel", "user_id")
|
||||
return
|
||||
}
|
||||
|
||||
channelId := data["channel_id"]
|
||||
if len(channelId) != 26 {
|
||||
c.SetInvalidParam("updateNotifyLevel", "channel_id")
|
||||
return
|
||||
}
|
||||
|
||||
notifyLevel := data["notify_level"]
|
||||
if len(notifyLevel) == 0 || !model.IsChannelNotifyLevelValid(notifyLevel) {
|
||||
c.SetInvalidParam("updateNotifyLevel", "notify_level")
|
||||
return
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
|
||||
|
||||
if !c.HasPermissionsToUser(userId, "updateNotifyLevel") {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "updateNotifyLevel") {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().UpdateNotifyLevel(channelId, userId, notifyLevel); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.MapToJson(data)))
|
||||
}
|
||||
|
||||
func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
data := model.MapFromJson(r.Body)
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ func BenchmarkRemoveChannelMember(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUpdateNotifyLevel(b *testing.B) {
|
||||
func BenchmarkUpdateNotifyProps(b *testing.B) {
|
||||
var (
|
||||
NUM_CHANNELS_RANGE = utils.Range{NUM_CHANNELS, NUM_CHANNELS}
|
||||
)
|
||||
@@ -271,9 +271,10 @@ func BenchmarkUpdateNotifyLevel(b *testing.B) {
|
||||
|
||||
for i := range data {
|
||||
newmap := map[string]string{
|
||||
"channel_id": channels[i].Id,
|
||||
"user_id": user.Id,
|
||||
"notify_level": model.CHANNEL_NOTIFY_MENTION,
|
||||
"channel_id": channels[i].Id,
|
||||
"user_id": user.Id,
|
||||
"desktop": model.CHANNEL_NOTIFY_MENTION,
|
||||
"mark_unread": model.CHANNEL_MARK_UNREAD_MENTION,
|
||||
}
|
||||
data[i] = newmap
|
||||
}
|
||||
@@ -282,7 +283,7 @@ func BenchmarkUpdateNotifyLevel(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for j := range channels {
|
||||
Client.Must(Client.UpdateNotifyLevel(data[j]))
|
||||
Client.Must(Client.UpdateNotifyProps(data[j]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,88 +803,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateNotifyLevel(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
store.Must(Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.LoginByEmail(team.Name, user.Email, "pwd")
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
||||
|
||||
data := make(map[string]string)
|
||||
data["channel_id"] = channel1.Id
|
||||
data["user_id"] = user.Id
|
||||
data["notify_level"] = model.CHANNEL_NOTIFY_MENTION
|
||||
|
||||
timeBeforeUpdate := model.GetMillis()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
if _, err := Client.UpdateNotifyLevel(data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rget := Client.Must(Client.GetChannels(""))
|
||||
rdata := rget.Data.(*model.ChannelList)
|
||||
if len(rdata.Members) == 0 || rdata.Members[channel1.Id].NotifyLevel != data["notify_level"] {
|
||||
t.Fatal("NotifyLevel did not update properly")
|
||||
}
|
||||
|
||||
if rdata.Members[channel1.Id].LastUpdateAt <= timeBeforeUpdate {
|
||||
t.Fatal("LastUpdateAt did not update")
|
||||
}
|
||||
|
||||
data["user_id"] = "junk"
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - bad user id")
|
||||
}
|
||||
|
||||
data["user_id"] = "12345678901234567890123456"
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - bad user id")
|
||||
}
|
||||
|
||||
data["user_id"] = user.Id
|
||||
data["channel_id"] = "junk"
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - bad channel id")
|
||||
}
|
||||
|
||||
data["channel_id"] = "12345678901234567890123456"
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - bad channel id")
|
||||
}
|
||||
|
||||
data["channel_id"] = channel1.Id
|
||||
data["notify_level"] = ""
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - empty notify level")
|
||||
}
|
||||
|
||||
data["notify_level"] = "junk"
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - bad notify level")
|
||||
}
|
||||
|
||||
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
|
||||
Client.LoginByEmail(team.Name, user2.Email, "pwd")
|
||||
|
||||
data["channel_id"] = channel1.Id
|
||||
data["user_id"] = user2.Id
|
||||
data["notify_level"] = model.CHANNEL_NOTIFY_MENTION
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
t.Fatal("Should have errored - user not in channel")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateNotifyProps(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
@@ -1002,7 +920,7 @@ func TestUpdateNotifyProps(t *testing.T) {
|
||||
data["user_id"] = user2.Id
|
||||
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
|
||||
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
|
||||
if _, err := Client.UpdateNotifyLevel(data); err == nil {
|
||||
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||
t.Fatal("Should have errored - user not in channel")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ type ChannelMember struct {
|
||||
MsgCount int64 `json:"msg_count"`
|
||||
MentionCount int64 `json:"mention_count"`
|
||||
NotifyProps StringMap `json:"notify_props"`
|
||||
NotifyLevel string `json:"notify_level"`
|
||||
LastUpdateAt int64 `json:"last_update_at"`
|
||||
}
|
||||
|
||||
@@ -67,8 +66,9 @@ func (o *ChannelMember) IsValid() *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if len(o.NotifyLevel) > 20 || !IsChannelNotifyLevelValid(o.NotifyLevel) {
|
||||
return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+o.NotifyLevel)
|
||||
notifyLevel := o.NotifyProps["desktop"]
|
||||
if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
|
||||
return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+notifyLevel)
|
||||
}
|
||||
|
||||
markUnreadLevel := o.NotifyProps["mark_unread"]
|
||||
|
||||
@@ -31,7 +31,6 @@ func TestChannelMemberIsValid(t *testing.T) {
|
||||
}
|
||||
|
||||
o.Roles = "missing"
|
||||
o.NotifyLevel = CHANNEL_NOTIFY_ALL
|
||||
o.NotifyProps = GetDefaultChannelNotifyProps()
|
||||
o.UserId = NewId()
|
||||
if err := o.IsValid(); err == nil {
|
||||
@@ -39,17 +38,17 @@ func TestChannelMemberIsValid(t *testing.T) {
|
||||
}
|
||||
|
||||
o.Roles = CHANNEL_ROLE_ADMIN
|
||||
o.NotifyLevel = "junk"
|
||||
o.NotifyProps["desktop"] = "junk"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.NotifyLevel = "123456789012345678901"
|
||||
o.NotifyProps["desktop"] = "123456789012345678901"
|
||||
if err := o.IsValid(); err == nil {
|
||||
t.Fatal("should be invalid")
|
||||
}
|
||||
|
||||
o.NotifyLevel = CHANNEL_NOTIFY_ALL
|
||||
o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL
|
||||
if err := o.IsValid(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -450,15 +450,6 @@ func (c *Client) UpdateChannelDesc(data map[string]string) (*Result, *AppError)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) UpdateNotifyLevel(data map[string]string) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/channels/update_notify_level", MapToJson(data)); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||
r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) UpdateNotifyProps(data map[string]string) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/channels/update_notify_props", MapToJson(data)); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -78,8 +78,7 @@ func (s SqlChannelStore) UpgradeSchemaIfNeeded() {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
|
||||
// TODO uncomment me
|
||||
// s.RemoveColumnIfExists("ChannelMembers", "NotifyLevel")
|
||||
s.RemoveColumnIfExists("ChannelMembers", "NotifyLevel")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,36 +720,6 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
// TODO remove me
|
||||
func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
updateAt := model.GetMillis()
|
||||
|
||||
_, err := s.GetMaster().Exec(
|
||||
`UPDATE
|
||||
ChannelMembers
|
||||
SET
|
||||
NotifyLevel = :NotifyLevel,
|
||||
LastUpdateAt = :LastUpdateAt
|
||||
WHERE
|
||||
UserId = :UserId
|
||||
AND ChannelId = :ChannelId`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId, "NotifyLevel": notifyLevel, "LastUpdateAt": updateAt})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.UpdateNotifyLevel", "We couldn't update the notify level", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetForExport(teamId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
|
||||
@@ -135,14 +135,12 @@ func TestChannelStoreDelete(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
m2 := model.ChannelMember{}
|
||||
m2.ChannelId = o2.Id
|
||||
m2.UserId = m1.UserId
|
||||
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m2))
|
||||
|
||||
@@ -224,14 +222,12 @@ func TestChannelMemberStore(t *testing.T) {
|
||||
o1 := model.ChannelMember{}
|
||||
o1.ChannelId = c1.Id
|
||||
o1.UserId = u1.Id
|
||||
o1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
o1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&o1))
|
||||
|
||||
o2 := model.ChannelMember{}
|
||||
o2.ChannelId = c1.Id
|
||||
o2.UserId = u2.Id
|
||||
o2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
o2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&o2))
|
||||
|
||||
@@ -295,7 +291,6 @@ func TestChannelStorePermissionsTo(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
@@ -376,21 +371,18 @@ func TestChannelStoreGetChannels(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
m2 := model.ChannelMember{}
|
||||
m2.ChannelId = o1.Id
|
||||
m2.UserId = model.NewId()
|
||||
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m2))
|
||||
|
||||
m3 := model.ChannelMember{}
|
||||
m3.ChannelId = o2.Id
|
||||
m3.UserId = model.NewId()
|
||||
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m3))
|
||||
|
||||
@@ -422,21 +414,18 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
m2 := model.ChannelMember{}
|
||||
m2.ChannelId = o1.Id
|
||||
m2.UserId = model.NewId()
|
||||
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m2))
|
||||
|
||||
m3 := model.ChannelMember{}
|
||||
m3.ChannelId = o2.Id
|
||||
m3.UserId = model.NewId()
|
||||
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m3))
|
||||
|
||||
@@ -493,21 +482,18 @@ func TestChannelStoreGetChannelCounts(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
m2 := model.ChannelMember{}
|
||||
m2.ChannelId = o1.Id
|
||||
m2.UserId = model.NewId()
|
||||
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m2))
|
||||
|
||||
m3 := model.ChannelMember{}
|
||||
m3.ChannelId = o2.Id
|
||||
m3.UserId = model.NewId()
|
||||
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m3))
|
||||
|
||||
@@ -537,7 +523,6 @@ func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
@@ -566,7 +551,6 @@ func TestChannelStoreIncrementMentionCount(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
|
||||
@@ -484,7 +484,6 @@ func TestPostStoreSearch(t *testing.T) {
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = c1.Id
|
||||
m1.UserId = userId
|
||||
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ type ChannelStore interface {
|
||||
CheckPermissionsToByName(teamId string, channelName string, userId string) StoreChannel
|
||||
UpdateLastViewedAt(channelId string, userId string) StoreChannel
|
||||
IncrementMentionCount(channelId string, userId string) StoreChannel
|
||||
UpdateNotifyLevel(channelId string, userId string, notifyLevel string) StoreChannel
|
||||
}
|
||||
|
||||
type PostStore interface {
|
||||
|
||||
@@ -41,7 +41,7 @@ export default class ChannelNotifications extends React.Component {
|
||||
var channelId = button.getAttribute('data-channelid');
|
||||
|
||||
const member = ChannelStore.getMember(channelId);
|
||||
var notifyLevel = member.notify_level;
|
||||
var notifyLevel = member.notify_props.desktop;
|
||||
var markUnreadLevel = member.notify_props.mark_unread;
|
||||
|
||||
this.setState({
|
||||
@@ -62,7 +62,7 @@ export default class ChannelNotifications extends React.Component {
|
||||
}
|
||||
|
||||
const member = ChannelStore.getMember(this.state.channelId);
|
||||
var notifyLevel = member.notify_level;
|
||||
var notifyLevel = member.notify_props.desktop;
|
||||
var markUnreadLevel = member.notify_props.mark_unread;
|
||||
|
||||
var newState = this.state;
|
||||
@@ -81,7 +81,7 @@ export default class ChannelNotifications extends React.Component {
|
||||
var channelId = this.state.channelId;
|
||||
var notifyLevel = this.state.notifyLevel;
|
||||
|
||||
if (ChannelStore.getMember(channelId).notify_level === notifyLevel) {
|
||||
if (ChannelStore.getMember(channelId).notify_props.desktop === notifyLevel) {
|
||||
this.updateSection('');
|
||||
return;
|
||||
}
|
||||
@@ -89,16 +89,12 @@ export default class ChannelNotifications extends React.Component {
|
||||
var data = {};
|
||||
data.channel_id = channelId;
|
||||
data.user_id = UserStore.getCurrentId();
|
||||
data.notify_level = notifyLevel;
|
||||
data.desktop = notifyLevel;
|
||||
|
||||
if (!data.notify_level || data.notify_level.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Client.updateNotifyLevel(data,
|
||||
Client.updateNotifyProps(data,
|
||||
() => {
|
||||
var member = ChannelStore.getMember(channelId);
|
||||
member.notify_level = notifyLevel;
|
||||
member.notify_props.desktop = notifyLevel;
|
||||
ChannelStore.setChannelMember(member);
|
||||
this.updateSection('');
|
||||
},
|
||||
|
||||
@@ -203,7 +203,7 @@ export default class Sidebar extends React.Component {
|
||||
const user = UserStore.getCurrentUser();
|
||||
const member = ChannelStore.getMember(msg.channel_id);
|
||||
|
||||
var notifyLevel = member.notify_level;
|
||||
var notifyLevel = member.notify_props.desktop;
|
||||
if (notifyLevel === 'default') {
|
||||
notifyLevel = user.notify_props.desktop;
|
||||
}
|
||||
|
||||
@@ -568,22 +568,6 @@ export function updateChannelDesc(data, success, error) {
|
||||
track('api', 'api_channels_desc');
|
||||
}
|
||||
|
||||
// TODO remove me
|
||||
export function updateNotifyLevel(data, success, error) {
|
||||
$.ajax({
|
||||
url: '/api/v1/channels/update_notify_level',
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
success,
|
||||
error: function onError(xhr, status, err) {
|
||||
var e = handleError('updateNotifyLevel', xhr, status, err);
|
||||
error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function updateNotifyProps(data, success, error) {
|
||||
$.ajax({
|
||||
url: '/api/v1/channels/update_notify_props',
|
||||
|
||||
Ссылка в новой задаче
Block a user