From e7e10d36a9bfd2c4b1ef98aabe013f97c01baa9e Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 19 Sep 2017 16:05:20 -0500 Subject: interactive post update fix (#7477) --- model/post.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'model/post.go') diff --git a/model/post.go b/model/post.go index 2554c4f2e..d4fff7ef9 100644 --- a/model/post.go +++ b/model/post.go @@ -198,21 +198,14 @@ func (o *Post) PreSave() { } o.UpdateAt = o.CreateAt + o.PreCommit() +} +func (o *Post) PreCommit() { if o.Props == nil { o.Props = make(map[string]interface{}) } - if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok { - for _, attachment := range attachments { - for _, action := range attachment.Actions { - if action.Id == "" { - action.Id = NewId() - } - } - } - } - if o.Filenames == nil { o.Filenames = []string{} } @@ -220,6 +213,8 @@ func (o *Post) PreSave() { if o.FileIds == nil { o.FileIds = []string{} } + + o.GenerateActionIds() } func (o *Post) MakeNonNil() { @@ -330,3 +325,18 @@ func (o *Post) GetAction(id string) *PostAction { } return nil } + +func (o *Post) GenerateActionIds() { + if o.Props["attachments"] != nil { + o.Props["attachments"] = o.Attachments() + } + if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok { + for _, attachment := range attachments { + for _, action := range attachment.Actions { + if action.Id == "" { + action.Id = NewId() + } + } + } + } +} -- cgit v1.2.3-1-g7c22