当前位置: 首页>>代码示例>>Golang>>正文


Golang Post.AddProp方法代码示例

本文整理汇总了Golang中github.com/mattermost/platform/model.Post.AddProp方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.AddProp方法的具体用法?Golang Post.AddProp怎么用?Golang Post.AddProp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/mattermost/platform/model.Post的用法示例。


在下文中一共展示了Post.AddProp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseSlackAttachment

// This method only parses and processes the attachments,
// all else should be set in the post which is passed
func parseSlackAttachment(post *model.Post, attachments interface{}) {
	post.Type = model.POST_SLACK_ATTACHMENT

	if list, success := attachments.([]interface{}); success {
		for i, aInt := range list {
			attachment := aInt.(map[string]interface{})
			if aText, ok := attachment["text"].(string); ok {
				aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
				attachment["text"] = aText
				list[i] = attachment
			}
			if aText, ok := attachment["pretext"].(string); ok {
				aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
				attachment["pretext"] = aText
				list[i] = attachment
			}
			if fVal, ok := attachment["fields"]; ok {
				if fields, ok := fVal.([]interface{}); ok {
					// parse attachment field links into Markdown format
					for j, fInt := range fields {
						field := fInt.(map[string]interface{})
						if fValue, ok := field["value"].(string); ok {
							fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})")
							field["value"] = fValue
							fields[j] = field
						}
					}
					attachment["fields"] = fields
					list[i] = attachment
				}
			}
		}
		post.AddProp("attachments", list)
	}
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:37,代码来源:post.go

示例2: ImportIncomingWebhookPost

func ImportIncomingWebhookPost(post *model.Post, props model.StringInterface) {
	linkWithTextRegex := regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
	post.Message = linkWithTextRegex.ReplaceAllString(post.Message, "[${2}](${1})")

	post.AddProp("from_webhook", "true")

	if _, ok := props["override_username"]; !ok {
		post.AddProp("override_username", model.DEFAULT_WEBHOOK_USERNAME)
	}

	if len(props) > 0 {
		for key, val := range props {
			if key == "attachments" {
				if list, success := val.([]interface{}); success {
					// parse attachment links into Markdown format
					for i, aInt := range list {
						attachment := aInt.(map[string]interface{})
						if aText, ok := attachment["text"].(string); ok {
							aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
							attachment["text"] = aText
							list[i] = attachment
						}
						if aText, ok := attachment["pretext"].(string); ok {
							aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
							attachment["pretext"] = aText
							list[i] = attachment
						}
						if fVal, ok := attachment["fields"]; ok {
							if fields, ok := fVal.([]interface{}); ok {
								// parse attachment field links into Markdown format
								for j, fInt := range fields {
									field := fInt.(map[string]interface{})
									if fValue, ok := field["value"].(string); ok {
										fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})")
										field["value"] = fValue
										fields[j] = field
									}
								}
								attachment["fields"] = fields
								list[i] = attachment
							}
						}
					}
					post.AddProp(key, list)
				}
			} else if key != "from_webhook" {
				post.AddProp(key, val)
			}
		}
	}

	ImportPost(post)
}
开发者ID:sunchips,项目名称:platform,代码行数:53,代码来源:import.go


注:本文中的github.com/mattermost/platform/model.Post.AddProp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。