summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeviot Systems <oss@teviot.com.au>2015-10-02 20:16:27 +1000
committerTeviot Systems <oss@teviot.com.au>2015-10-02 20:16:27 +1000
commitfc82f57102ae4b8f89d8ad65ae3097aba9891272 (patch)
tree238630b1b6050dab81480dd7eaa03851222bfc45
parent9083f0b15c8a2f842eb6ed54f14ecdfb4808dbe2 (diff)
downloadchat-fc82f57102ae4b8f89d8ad65ae3097aba9891272.tar.gz
chat-fc82f57102ae4b8f89d8ad65ae3097aba9891272.tar.bz2
chat-fc82f57102ae4b8f89d8ad65ae3097aba9891272.zip
Pass-through post creation time when importing posts
-rw-r--r--api/post.go2
-rw-r--r--model/post.go5
-rw-r--r--model/post_test.go13
3 files changed, 19 insertions, 1 deletions
diff --git a/api/post.go b/api/post.go
index 2b683fb7d..65dad0eb6 100644
--- a/api/post.go
+++ b/api/post.go
@@ -88,6 +88,8 @@ func CreatePost(c *Context, post *model.Post, doUpdateLastViewed bool) (*model.P
}
}
+ post.CreateAt = 0
+
post.Hashtags, _ = model.ParseHashtags(post.Message)
post.UserId = c.Session.UserId
diff --git a/model/post.go b/model/post.go
index e78469940..1fc5963c3 100644
--- a/model/post.go
+++ b/model/post.go
@@ -120,7 +120,10 @@ func (o *Post) PreSave() {
o.OriginalId = ""
- o.CreateAt = GetMillis()
+ if o.CreateAt == 0 {
+ o.CreateAt = GetMillis()
+ }
+
o.UpdateAt = o.CreateAt
if o.Props == nil {
diff --git a/model/post_test.go b/model/post_test.go
index 38f4b4c98..a6b880fa0 100644
--- a/model/post_test.go
+++ b/model/post_test.go
@@ -83,5 +83,18 @@ func TestPostIsValid(t *testing.T) {
func TestPostPreSave(t *testing.T) {
o := Post{Message: "test"}
o.PreSave()
+
+ if o.CreateAt == 0 {
+ t.Fatal("should be set")
+ }
+
+ past := GetMillis() - 1
+ o = Post{Message: "test", CreateAt: past}
+ o.PreSave()
+
+ if o.CreateAt > past {
+ t.Fatal("should not be updated")
+ }
+
o.Etag()
}