From b085bc2d56bdc98101b8cb50848aee248d42af28 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Thu, 5 Nov 2015 23:32:44 +0100 Subject: PLT-857: Support for Incoming Webhooks - Try #2 --- model/post.go | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'model/post.go') diff --git a/model/post.go b/model/post.go index e0074b348..248d40321 100644 --- a/model/post.go +++ b/model/post.go @@ -10,27 +10,28 @@ import ( ) const ( - POST_DEFAULT = "" - POST_JOIN_LEAVE = "join_leave" + POST_DEFAULT = "" + POST_SLACK_ATTACHMENT = "slack_attachment" + POST_JOIN_LEAVE = "join_leave" ) type Post struct { - Id string `json:"id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` - DeleteAt int64 `json:"delete_at"` - UserId string `json:"user_id"` - ChannelId string `json:"channel_id"` - RootId string `json:"root_id"` - ParentId string `json:"parent_id"` - OriginalId string `json:"original_id"` - Message string `json:"message"` - ImgCount int64 `json:"img_count"` - Type string `json:"type"` - Props StringMap `json:"props"` - Hashtags string `json:"hashtags"` - Filenames StringArray `json:"filenames"` - PendingPostId string `json:"pending_post_id" db:"-"` + Id string `json:"id"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + DeleteAt int64 `json:"delete_at"` + UserId string `json:"user_id"` + ChannelId string `json:"channel_id"` + RootId string `json:"root_id"` + ParentId string `json:"parent_id"` + OriginalId string `json:"original_id"` + Message string `json:"message"` + ImgCount int64 `json:"img_count"` + Type string `json:"type"` + Props StringInterface `json:"props"` + Hashtags string `json:"hashtags"` + Filenames StringArray `json:"filenames"` + PendingPostId string `json:"pending_post_id" db:"-"` } func (o *Post) ToJson() string { @@ -103,7 +104,8 @@ func (o *Post) IsValid() *AppError { return NewAppError("Post.IsValid", "Invalid hashtags", "id="+o.Id) } - if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE) { + // should be removed once more message types are supported + if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT) { return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type) } @@ -128,7 +130,7 @@ func (o *Post) PreSave() { o.UpdateAt = o.CreateAt if o.Props == nil { - o.Props = make(map[string]string) + o.Props = make(map[string]interface{}) } if o.Filenames == nil { @@ -138,14 +140,14 @@ func (o *Post) PreSave() { func (o *Post) MakeNonNil() { if o.Props == nil { - o.Props = make(map[string]string) + o.Props = make(map[string]interface{}) } if o.Filenames == nil { o.Filenames = []string{} } } -func (o *Post) AddProp(key string, value string) { +func (o *Post) AddProp(key string, value interface{}) { o.MakeNonNil() -- cgit v1.2.3-1-g7c22