From 61771a0fc53a9c50f096b0dcc422f12ce80baf20 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Fri, 6 Jan 2017 18:10:00 +0100 Subject: inital draft (#4883) --- api/post_test.go | 30 ++++++++++++++++++++++++++++++ model/client.go | 15 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/api/post_test.go b/api/post_test.go index 509432a25..e48debcae 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -1389,3 +1389,33 @@ func TestGetPostById(t *testing.T) { t.Fatal(respMetadata.Error) } } + +func TestGetPermalinkTmp(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + channel1 := th.BasicChannel + + time.Sleep(10 * time.Millisecond) + post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post) + + time.Sleep(10 * time.Millisecond) + post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} + post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post) + + etag := Client.Must(Client.GetPost(channel1.Id, post1.Id, "")).Etag + + // test etag caching + if cache_result, respMetadata := Client.GetPermalink(channel1.Id, post1.Id, etag); respMetadata.Error != nil { + t.Fatal(respMetadata.Error) + } else if cache_result != nil { + t.Log(cache_result) + t.Fatal("cache should be empty") + } + + if results, respMetadata := Client.GetPermalink(channel1.Id, post1.Id, ""); respMetadata.Error != nil { + t.Fatal(respMetadata.Error) + } else if results == nil { + t.Fatal("should not be empty") + } +} diff --git a/model/client.go b/model/client.go index 540bc747f..b5c22c6ca 100644 --- a/model/client.go +++ b/model/client.go @@ -1471,6 +1471,21 @@ func (c *Client) GetPostById(postId string, etag string) (*PostList, *ResponseMe } } +// GetPermalink returns a post list, based on the provided channel and post ID. +func (c *Client) GetPermalink(channelId string, postId string, etag string) (*PostList, *ResponseMetadata) { + if r, err := c.DoApiGet(c.GetTeamRoute()+fmt.Sprintf("/pltmp/%v", postId), "", etag); err != nil { + return nil, &ResponseMetadata{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return PostListFromJson(r.Body), + &ResponseMetadata{ + StatusCode: r.StatusCode, + RequestId: r.Header.Get(HEADER_REQUEST_ID), + Etag: r.Header.Get(HEADER_ETAG_SERVER), + } + } +} + func (c *Client) DeletePost(channelId string, postId string) (*Result, *AppError) { if r, err := c.DoApiPost(c.GetChannelRoute(channelId)+fmt.Sprintf("/posts/%v/delete", postId), ""); err != nil { return nil, err -- cgit v1.2.3-1-g7c22