diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-16 14:58:33 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-16 11:58:33 -0700 |
commit | d757645c2490dd4f0de16cc32e05551b1476d0a0 (patch) | |
tree | 5d6e4049aa296b7629a34ca5b02d0aba25dd27dc /store/sql_channel_store.go | |
parent | 04c0223c6402b12e67c61474ae310b0a56af6482 (diff) | |
download | chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.gz chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.bz2 chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.zip |
Implement some channel endpoints for APIv4 (#5767)
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r-- | store/sql_channel_store.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index a85bb0656..d72722f7c 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -309,6 +309,41 @@ func (s SqlChannelStore) extraUpdated(channel *model.Channel) StoreChannel { return storeChannel } +func (s SqlChannelStore) GetChannelUnread(channelId, userId string) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + var unreadChannel model.ChannelUnread + err := s.GetReplica().SelectOne(&unreadChannel, + `SELECT + Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps + FROM + Channels, ChannelMembers + WHERE + Id = ChannelId + AND Id = :ChannelId + AND UserId = :UserId + AND DeleteAt = 0`, + map[string]interface{}{"ChannelId": channelId, "UserId": userId}) + + if err != nil { + result.Err = model.NewAppError("SqlChannelStore.GetChannelUnread", "store.sql_channel.get_unread.app_error", nil, "channelId="+channelId+" "+err.Error(), http.StatusInternalServerError) + if err == sql.ErrNoRows { + result.Err.StatusCode = http.StatusNotFound + } + } else { + result.Data = &unreadChannel + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (us SqlChannelStore) InvalidateChannel(id string) { channelCache.Remove(id) } |