summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorenahum <nahumhbl@gmail.com>2016-12-19 10:05:46 -0300
committerJoram Wilander <jwawilander@gmail.com>2016-12-19 08:05:46 -0500
commit999d1553e1ce45adf58f6082b160bc1147dc592b (patch)
tree369a9b7f46dd44d136a79a050469429169433cec /store
parent3ce2ce9dc882ed962dc3ce7550bdb07963f376b6 (diff)
downloadchat-999d1553e1ce45adf58f6082b160bc1147dc592b.tar.gz
chat-999d1553e1ce45adf58f6082b160bc1147dc592b.tar.bz2
chat-999d1553e1ce45adf58f6082b160bc1147dc592b.zip
PLT-4167 Team Sidebar (#4569)
* PLT-4167 Team Sidebar * Address feedback from PM * change route from my_members to members * bug fixes * Updating styles for teams sidebar (#4681) * Added PM changes * Fix corner cases * Addressing feedback * use two different endpoints * Bug fixes * Rename model and client functions, using preferences to store last team and channel viewed * Fix mobile notification count and closing the team sidebar * unit test, fixed bad merge and retrieve from cached when available * bug fixes * use id for last channel in preferences, query optimization * Updating multi team css (#4830)
Diffstat (limited to 'store')
-rw-r--r--store/sql_preference_store.go22
-rw-r--r--store/sql_preference_store_test.go35
-rw-r--r--store/sql_team_store.go33
-rw-r--r--store/sql_team_store_test.go47
-rw-r--r--store/store.go2
5 files changed, 139 insertions, 0 deletions
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go
index e20226ce6..5c46d1328 100644
--- a/store/sql_preference_store.go
+++ b/store/sql_preference_store.go
@@ -326,3 +326,25 @@ func (s SqlPreferenceStore) Delete(userId, category, name string) StoreChannel {
return storeChannel
}
+
+func (s SqlPreferenceStore) DeleteCategory(userId string, category string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ if _, err := s.GetMaster().Exec(
+ `DELETE FROM
+ Preferences
+ WHERE
+ UserId = :UserId
+ AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}); err != nil {
+ result.Err = model.NewLocAppError("SqlPreferenceStore.DeleteCategory", "store.sql_preference.delete.app_error", nil, err.Error())
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_preference_store_test.go b/store/sql_preference_store_test.go
index 8c6a2b6af..fc1cf5f5b 100644
--- a/store/sql_preference_store_test.go
+++ b/store/sql_preference_store_test.go
@@ -392,3 +392,38 @@ func TestPreferenceDelete(t *testing.T) {
t.Fatal("should've returned no preferences")
}
}
+
+func TestPreferenceDeleteCategory(t *testing.T) {
+ Setup()
+
+ category := model.NewId()
+ userId := model.NewId()
+
+ preference1 := model.Preference{
+ UserId: userId,
+ Category: category,
+ Name: model.NewId(),
+ Value: "value1a",
+ }
+
+ preference2 := model.Preference{
+ UserId: userId,
+ Category: category,
+ Name: model.NewId(),
+ Value: "value1a",
+ }
+
+ Must(store.Preference().Save(&model.Preferences{preference1, preference2}))
+
+ if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 2 {
+ t.Fatal("should've returned 2 preferences")
+ }
+
+ if result := <-store.Preference().DeleteCategory(userId, category); result.Err != nil {
+ t.Fatal(result.Err)
+ }
+
+ if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 0 {
+ t.Fatal("should've returned no preferences")
+ }
+}
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index 3ec336be5..13b6baa1a 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -583,6 +583,39 @@ func (s SqlTeamStore) GetTeamsForUser(userId string) StoreChannel {
return storeChannel
}
+func (s SqlTeamStore) GetTeamsUnreadForUser(teamId, userId string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ var members []*model.TeamUnread
+ _, err := s.GetReplica().Select(&members,
+ `SELECT
+ Channels.TeamId,
+ SUM(Channels.TotalMsgCount - ChannelMembers.MsgCount) as MsgCount,
+ SUM(ChannelMembers.MentionCount) as MentionCount
+ FROM
+ Channels,
+ ChannelMembers
+ WHERE
+ Channels.Id = ChannelMembers.ChannelId AND
+ ChannelMembers.UserId = :UserId AND Channels.TeamId != :TeamId
+ GROUP BY
+ Channels.TeamId`, map[string]interface{}{"UserId": userId, "TeamId": teamId})
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlTeamStore.GetTeamsUnreadForUser", "store.sql_team.get_unread.app_error", nil, "userId="+userId+" "+err.Error())
+ } else {
+ result.Data = members
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlTeamStore) RemoveMember(teamId string, userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
diff --git a/store/sql_team_store_test.go b/store/sql_team_store_test.go
index 0e472a961..5e6abd102 100644
--- a/store/sql_team_store_test.go
+++ b/store/sql_team_store_test.go
@@ -529,3 +529,50 @@ func TestTeamStoreMemberCount(t *testing.T) {
}
}
}
+
+func TestMyTeamMembersUnread(t *testing.T) {
+ Setup()
+
+ teamId1 := model.NewId()
+ teamId2 := model.NewId()
+
+ uid := model.NewId()
+ m1 := &model.TeamMember{TeamId: teamId1, UserId: uid}
+ m2 := &model.TeamMember{TeamId: teamId2, UserId: uid}
+ Must(store.Team().SaveMember(m1))
+ Must(store.Team().SaveMember(m2))
+
+ c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
+ Must(store.Channel().Save(c1))
+ c2 := &model.Channel{TeamId: m2.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
+ Must(store.Channel().Save(c2))
+
+ cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
+ Must(store.Channel().SaveMember(cm1))
+ cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m2.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
+ Must(store.Channel().SaveMember(cm2))
+
+ if r1 := <-store.Team().GetTeamsUnreadForUser("", uid); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ ms := r1.Data.([]*model.TeamUnread)
+
+ if len(ms) != 2 {
+ t.Fatal("Should be the unreads for all the teams")
+ }
+ }
+
+ if r2 := <-store.Team().GetTeamsUnreadForUser(teamId1, uid); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ ms := r2.Data.([]*model.TeamUnread)
+
+ if len(ms) != 1 {
+ t.Fatal("Should be the unreads for just one team")
+ }
+ }
+
+ if r1 := <-store.Team().RemoveAllMembersByUser(uid); r1.Err != nil {
+ t.Fatal(r1.Err)
+ }
+}
diff --git a/store/store.go b/store/store.go
index b0cc09983..05eb7f4e1 100644
--- a/store/store.go
+++ b/store/store.go
@@ -74,6 +74,7 @@ type TeamStore interface {
GetTotalMemberCount(teamId string) StoreChannel
GetActiveMemberCount(teamId string) StoreChannel
GetTeamsForUser(userId string) StoreChannel
+ GetTeamsUnreadForUser(teamId, userId string) StoreChannel
RemoveMember(teamId string, userId string) StoreChannel
RemoveAllMembersByTeam(teamId string) StoreChannel
RemoveAllMembersByUser(userId string) StoreChannel
@@ -270,6 +271,7 @@ type PreferenceStore interface {
GetCategory(userId string, category string) StoreChannel
GetAll(userId string) StoreChannel
Delete(userId, category, name string) StoreChannel
+ DeleteCategory(userId string, category string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
IsFeatureEnabled(feature, userId string) StoreChannel
}