summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-09-29 11:45:59 -0400
committerChristopher Speller <crspeller@gmail.com>2017-09-29 08:45:59 -0700
commit8b9dbb86133ff0fd6002a391268383d1593918ca (patch)
treeb8399f2bae881afe12f3bdb34ec725e97307144a /api4
parent5e50d3f4612dc8e6dffeff268f024a3d383a329c (diff)
downloadchat-8b9dbb86133ff0fd6002a391268383d1593918ca.tar.gz
chat-8b9dbb86133ff0fd6002a391268383d1593918ca.tar.bz2
chat-8b9dbb86133ff0fd6002a391268383d1593918ca.zip
PLT-7404 Return viewed at times in view channel API response (#7428)
* Return viewed at times in view channel API response * Updated transaction to read and write once * Remove transaction and only update if new value greater than older
Diffstat (limited to 'api4')
-rw-r--r--api4/channel.go12
-rw-r--r--api4/channel_test.go12
2 files changed, 19 insertions, 5 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 9eaa6ec8a..74eb1a972 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -709,12 +709,20 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := c.App.ViewChannel(view, c.Params.UserId, !c.Session.IsMobileApp()); err != nil {
+ times, err := c.App.ViewChannel(view, c.Params.UserId, !c.Session.IsMobileApp())
+
+ if err != nil {
c.Err = err
return
}
- ReturnStatusOK(w)
+ // Returning {"status": "OK", ...} for backwards compatability
+ resp := &model.ChannelViewResponse{
+ Status: "OK",
+ LastViewedAtTimes: times,
+ }
+
+ w.Write([]byte(resp.ToJson()))
}
func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
diff --git a/api4/channel_test.go b/api4/channel_test.go
index fbe96728d..517d166dc 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -1375,13 +1375,19 @@ func TestViewChannel(t *testing.T) {
ChannelId: th.BasicChannel.Id,
}
- pass, resp := Client.ViewChannel(th.BasicUser.Id, view)
+ viewResp, resp := Client.ViewChannel(th.BasicUser.Id, view)
CheckNoError(t, resp)
- if !pass {
+ if viewResp.Status != "OK" {
t.Fatal("should have passed")
}
+ channel, _ := th.App.GetChannel(th.BasicChannel.Id)
+
+ if lastViewedAt := viewResp.LastViewedAtTimes[channel.Id]; lastViewedAt != channel.LastPostAt {
+ t.Fatal("LastPostAt does not match returned LastViewedAt time")
+ }
+
view.PrevChannelId = th.BasicChannel.Id
_, resp = Client.ViewChannel(th.BasicUser.Id, view)
CheckNoError(t, resp)
@@ -1396,7 +1402,7 @@ func TestViewChannel(t *testing.T) {
member, resp := Client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
CheckNoError(t, resp)
- channel, resp := Client.GetChannel(th.BasicChannel.Id, "")
+ channel, resp = Client.GetChannel(th.BasicChannel.Id, "")
CheckNoError(t, resp)
if member.MsgCount != channel.TotalMsgCount {