summaryrefslogtreecommitdiffstats
path: root/app/team.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-13 09:46:28 -0400
committerChristopher Speller <crspeller@gmail.com>2017-03-13 09:46:28 -0400
commita284cd8c1817bb5419cb9eae118c85cd7e99c039 (patch)
tree71fd6ace54692477acea746f47b3266514ae9292 /app/team.go
parent5ec49c0db03d4ec6fd36619055f99c9a3bb34148 (diff)
downloadchat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.gz
chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.bz2
chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.zip
Implement some team endpoints for APIv4 (#5745)
* Implement PUT /teams/{team_id} endpoint for APIv4 * Implement GET /users/{user_id}/teams/{team_id}/unread endpoint for APIv4 * Implement POST /teams/{team_id}/members/ids endpoint for APIv4 * Remove debug statement
Diffstat (limited to 'app/team.go')
-rw-r--r--app/team.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/app/team.go b/app/team.go
index 60a2f4220..6bc4d258e 100644
--- a/app/team.go
+++ b/app/team.go
@@ -391,6 +391,30 @@ func GetTeamMembersByIds(teamId string, userIds []string) ([]*model.TeamMember,
}
}
+func GetTeamUnread(teamId, userId string) (*model.TeamUnread, *model.AppError) {
+ result := <-Srv.Store.Team().GetChannelUnreadsForTeam(teamId, userId)
+ if result.Err != nil {
+ return nil, result.Err
+ }
+
+ channelUnreads := result.Data.([]*model.ChannelUnread)
+ var teamUnread = &model.TeamUnread{
+ MsgCount: 0,
+ MentionCount: 0,
+ TeamId: teamId,
+ }
+
+ for _, cu := range channelUnreads {
+ teamUnread.MentionCount += cu.MentionCount
+
+ if cu.NotifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
+ teamUnread.MsgCount += cu.MsgCount
+ }
+ }
+
+ return teamUnread, nil
+}
+
func RemoveUserFromTeam(teamId string, userId string) *model.AppError {
tchan := Srv.Store.Team().Get(teamId)
uchan := Srv.Store.User().Get(userId)
@@ -511,8 +535,8 @@ func FindTeamByName(name string) bool {
}
}
-func GetTeamsUnreadForUser(teamId string, userId string) ([]*model.TeamUnread, *model.AppError) {
- if result := <-Srv.Store.Team().GetTeamsUnreadForUser(teamId, userId); result.Err != nil {
+func GetTeamsUnreadForUser(excludeTeamId string, userId string) ([]*model.TeamUnread, *model.AppError) {
+ if result := <-Srv.Store.Team().GetChannelUnreadsForAllTeams(excludeTeamId, userId); result.Err != nil {
return nil, result.Err
} else {
data := result.Data.([]*model.ChannelUnread)
@@ -523,7 +547,7 @@ func GetTeamsUnreadForUser(teamId string, userId string) ([]*model.TeamUnread, *
tu.MentionCount += cu.MentionCount
if cu.NotifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
- tu.MsgCount += (cu.TotalMsgCount - cu.MsgCount)
+ tu.MsgCount += cu.MsgCount
}
return tu