diff options
author | Elias Nahum <nahumhbl@gmail.com> | 2016-02-25 04:24:03 -0300 |
---|---|---|
committer | Elias Nahum <nahumhbl@gmail.com> | 2016-02-25 04:24:03 -0300 |
commit | f0084229a5ca6a0c51addb888237f6eb42becbfb (patch) | |
tree | 7f6f2e82b5e87d3d3c9fc6249630891c22799117 /store | |
parent | 6f319fc64c9a947d8f076262aaab51354cb39ecd (diff) | |
download | chat-f0084229a5ca6a0c51addb888237f6eb42becbfb.tar.gz chat-f0084229a5ca6a0c51addb888237f6eb42becbfb.tar.bz2 chat-f0084229a5ca6a0c51addb888237f6eb42becbfb.zip |
Member show on Activate and Hide on deactivate from channel member list and at_mention
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 22 | ||||
-rw-r--r-- | store/sql_channel_store_test.go | 64 | ||||
-rw-r--r-- | store/store.go | 1 |
3 files changed, 87 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 87ee2bb11..35322e061 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -924,3 +924,25 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) S return storeChannel } + +func (s SqlChannelStore) ExtraUpdateByUser(userId string, time int64) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + _, err := s.GetMaster().Exec( + `UPDATE Channels SET ExtraUpdateAt = :Time + WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId);`, + map[string]interface{}{"UserId": userId, "Time": time}) + + if err != nil { + result.Err = model.NewLocAppError("SqlChannelStore.extraUpdated", "store.sql_channel.extra_updated.app_error", nil, "user_id="+userId+", "+err.Error()) + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 816a85aef..2213aa795 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -868,3 +868,67 @@ func TestGetMemberCount(t *testing.T) { t.Fatal("got incorrect member count %v", result.Data) } } + +func TestUpdateExtrasByUser(t *testing.T) { + Setup() + + teamId := model.NewId() + + c1 := model.Channel{ + TeamId: teamId, + DisplayName: "Channel1", + Name: "a" + model.NewId() + "b", + Type: model.CHANNEL_OPEN, + } + Must(store.Channel().Save(&c1)) + + c2 := model.Channel{ + TeamId: teamId, + DisplayName: "Channel2", + Name: "a" + model.NewId() + "b", + Type: model.CHANNEL_OPEN, + } + Must(store.Channel().Save(&c2)) + + t.Logf("c1.Id = %v", c1.Id) + + u1 := model.User{ + TeamId: teamId, + Email: model.NewId(), + DeleteAt: 0, + } + Must(store.User().Save(&u1)) + + m1 := model.ChannelMember{ + ChannelId: c1.Id, + UserId: u1.Id, + NotifyProps: model.GetDefaultChannelNotifyProps(), + } + Must(store.Channel().SaveMember(&m1)) + + u1.DeleteAt = model.GetMillis() + Must(store.User().Update(&u1, true)) + + if result := <-store.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil { + t.Fatal("failed to update extras by user: %v", result.Err) + } + + if result := <-store.Channel().GetExtraMembers(c1.Id, -1); result.Err != nil { + t.Fatal("failed to get extras: %v", result.Err) + } else if len(result.Data.([]model.ExtraMember)) != 0 { + t.Fatal("got incorrect member count %v", len(result.Data.([]model.ExtraMember))) + } + + u1.DeleteAt = 0 + Must(store.User().Update(&u1, true)) + + if result := <-store.Channel().ExtraUpdateByUser(u1.Id, u1.DeleteAt); result.Err != nil { + t.Fatal("failed to update extras by user: %v", result.Err) + } + + if result := <-store.Channel().GetExtraMembers(c1.Id, -1); result.Err != nil { + t.Fatal("failed to get extras: %v", result.Err) + } else if len(result.Data.([]model.ExtraMember)) != 1 { + t.Fatal("got incorrect member count %v", len(result.Data.([]model.ExtraMember))) + } +} diff --git a/store/store.go b/store/store.go index 952b96e87..397601543 100644 --- a/store/store.go +++ b/store/store.go @@ -85,6 +85,7 @@ type ChannelStore interface { UpdateLastViewedAt(channelId string, userId string) StoreChannel IncrementMentionCount(channelId string, userId string) StoreChannel AnalyticsTypeCount(teamId string, channelType string) StoreChannel + ExtraUpdateByUser(userId string, time int64) StoreChannel } type PostStore interface { |