本文整理汇总了Golang中github.com/mattermost/platform/model.Post类的典型用法代码示例。如果您正苦于以下问题:Golang Post类的具体用法?Golang Post怎么用?Golang Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateValetPost
func CreateValetPost(c *Context, post *model.Post) (*model.Post, *model.AppError) {
post.Hashtags, _ = model.ParseHashtags(post.Message)
post.Filenames = []string{} // no files allowed in valet posts yet
if result := <-Srv.Store.User().GetByUsername(c.Session.TeamId, "valet"); result.Err != nil {
// if the bot doesn't exist, create it
if tresult := <-Srv.Store.Team().Get(c.Session.TeamId); tresult.Err != nil {
return nil, tresult.Err
} else {
post.UserId = (CreateValet(c, tresult.Data.(*model.Team))).Id
}
} else {
post.UserId = result.Data.(*model.User).Id
}
var rpost *model.Post
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
} else {
rpost = result.Data.(*model.Post)
}
fireAndForgetNotifications(rpost, c.Session.TeamId, c.TeamUrl)
return rpost, nil
}
开发者ID:ralder,项目名称:platform,代码行数:27,代码来源:post.go
示例2: 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
示例3: sendReactionEvent
func sendReactionEvent(event string, channelId string, reaction *model.Reaction, postHadReactions bool) {
// send out that a reaction has been added/removed
go func() {
message := model.NewWebSocketEvent(event, "", channelId, "", nil)
message.Add("reaction", reaction.ToJson())
app.Publish(message)
}()
// send out that a post was updated if post.HasReactions has changed
go func() {
var post *model.Post
if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
l4g.Warn(utils.T("api.reaction.send_reaction_event.post.app_error"))
return
} else {
post = result.Data.(*model.PostList).Posts[reaction.PostId]
}
if post.HasReactions != postHadReactions {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil)
message.Add("post", post.ToJson())
app.Publish(message)
}
}()
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:27,代码来源:reaction.go
示例4: ImportPost
func ImportPost(post *model.Post) {
// Workaround for empty messages, which may be the case if they are webhook posts.
firstIteration := true
for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0 || firstIteration; messageRuneCount = utf8.RuneCountInString(post.Message) {
firstIteration = false
var remainder string
if messageRuneCount > model.POST_MESSAGE_MAX_RUNES {
remainder = string(([]rune(post.Message))[model.POST_MESSAGE_MAX_RUNES:])
post.Message = truncateRunes(post.Message, model.POST_MESSAGE_MAX_RUNES)
} else {
remainder = ""
}
post.Hashtags, _ = model.ParseHashtags(post.Message)
if result := <-app.Srv.Store.Post().Save(post); result.Err != nil {
l4g.Debug(utils.T("api.import.import_post.saving.debug"), post.UserId, post.Message)
}
for _, fileId := range post.FileIds {
if result := <-app.Srv.Store.FileInfo().AttachToPost(fileId, post.Id); result.Err != nil {
l4g.Error(utils.T("api.import.import_post.attach_files.error"), post.Id, post.FileIds, result.Err)
}
}
post.Id = ""
post.CreateAt++
post.Message = remainder
}
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:30,代码来源:import.go
示例5: CreatePost
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
var pchan store.StoreChannel
if len(post.RootId) > 0 {
pchan = Srv.Store.Post().Get(post.RootId)
}
// Verify the parent/child relationships are correct
if pchan != nil {
if presult := <-pchan; presult.Err != nil {
return nil, model.NewLocAppError("createPost", "api.post.create_post.root_id.app_error", nil, "")
} else {
list := presult.Data.(*model.PostList)
if len(list.Posts) == 0 || !list.IsChannelId(post.ChannelId) {
return nil, model.NewLocAppError("createPost", "api.post.create_post.channel_root_id.app_error", nil, "")
}
if post.ParentId == "" {
post.ParentId = post.RootId
}
if post.RootId != post.ParentId {
parent := list.Posts[post.ParentId]
if parent == nil {
return nil, model.NewLocAppError("createPost", "api.post.create_post.parent_id.app_error", nil, "")
}
}
}
}
if post.CreateAt != 0 && !HasPermissionToContext(c, model.PERMISSION_MANAGE_SYSTEM) {
post.CreateAt = 0
c.Err = nil
}
post.Hashtags, _ = model.ParseHashtags(post.Message)
var rpost *model.Post
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
} else {
rpost = result.Data.(*model.Post)
}
if len(post.FileIds) > 0 {
// There's a rare bug where the client sends up duplicate FileIds so protect against that
post.FileIds = utils.RemoveDuplicatesFromStringArray(post.FileIds)
for _, fileId := range post.FileIds {
if result := <-Srv.Store.FileInfo().AttachToPost(fileId, post.Id); result.Err != nil {
l4g.Error(utils.T("api.post.create_post.attach_files.error"), post.Id, post.FileIds, c.Session.UserId, result.Err)
}
}
}
handlePostEvents(c, rpost, triggerWebhooks)
return rpost, nil
}
开发者ID:rodrigocorsi2,项目名称:platform,代码行数:58,代码来源:post.go
示例6: Get
func (s SqlPostStore) Get(id string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
pl := &model.PostList{}
var post model.Post
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = ? AND DeleteAt = 0", id)
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetPost", "We couldn't get the post", "id="+id+err.Error())
}
if post.ImgCount > 0 {
post.Filenames = []string{}
for i := 0; int64(i) < post.ImgCount; i++ {
fileUrl := "/api/v1/files/get_image/" + post.ChannelId + "/" + post.Id + "/" + strconv.Itoa(i+1) + ".png"
post.Filenames = append(post.Filenames, fileUrl)
}
}
pl.AddPost(&post)
pl.AddOrder(id)
rootId := post.RootId
if rootId == "" {
rootId = post.Id
}
var posts []*model.Post
_, err = s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE (Id = ? OR RootId = ?) AND DeleteAt = 0", rootId, rootId)
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetPost", "We couldn't get the post", "root_id="+rootId+err.Error())
} else {
for _, p := range posts {
pl.AddPost(p)
}
}
result.Data = pl
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
开发者ID:Dahlgren,项目名称:platform,代码行数:48,代码来源:sql_post_store.go
示例7: 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
示例8: TestPostStoreSave
func TestPostStoreSave(t *testing.T) {
Setup()
o1 := model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
if err := (<-store.Post().Save(&o1)).Err; err != nil {
t.Fatal("couldn't save item", err)
}
if err := (<-store.Post().Save(&o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
}
开发者ID:kidhero,项目名称:platform,代码行数:16,代码来源:sql_post_store_test.go
示例9: Save
func (s SqlPostStore) Save(post *model.Post) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
if len(post.Id) > 0 {
result.Err = model.NewAppError("SqlPostStore.Save",
"You cannot update an existing Post", "id="+post.Id)
storeChannel <- result
close(storeChannel)
return
}
post.PreSave()
if result.Err = post.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if err := s.GetMaster().Insert(post); err != nil {
result.Err = model.NewAppError("SqlPostStore.Save", "We couldn't save the Post", "id="+post.Id+", "+err.Error())
} else {
time := model.GetMillis()
if post.Type != model.POST_JOIN_LEAVE {
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt, TotalMsgCount = TotalMsgCount + 1 WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": post.ChannelId})
} else {
// don't update TotalMsgCount for unimportant messages so that the channel isn't marked as unread
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": post.ChannelId})
}
if len(post.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = :UpdateAt WHERE Id = :RootId", map[string]interface{}{"UpdateAt": time, "RootId": post.RootId})
}
result.Data = post
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
开发者ID:raghavenc5,项目名称:TabGen,代码行数:46,代码来源:sql_post_store.go
示例10: Update
func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
editPost := *oldPost
editPost.Message = newMessage
editPost.UpdateAt = model.GetMillis()
editPost.Hashtags = newHashtags
oldPost.DeleteAt = editPost.UpdateAt
oldPost.UpdateAt = editPost.UpdateAt
oldPost.OriginalId = oldPost.Id
oldPost.Id = model.NewId()
if result.Err = editPost.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if _, err := s.GetMaster().Update(&editPost); err != nil {
result.Err = model.NewAppError("SqlPostStore.Update", "We couldn't update the Post", "id="+editPost.Id+", "+err.Error())
} else {
time := model.GetMillis()
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": editPost.ChannelId})
if len(editPost.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = :UpdateAt WHERE Id = :RootId", map[string]interface{}{"UpdateAt": time, "RootId": editPost.RootId})
}
// mark the old post as deleted
s.GetMaster().Insert(oldPost)
result.Data = &editPost
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
开发者ID:raghavenc5,项目名称:TabGen,代码行数:44,代码来源:sql_post_store.go
示例11: ImportPost
func ImportPost(post *model.Post) {
for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0; messageRuneCount = utf8.RuneCountInString(post.Message) {
var remainder string
if messageRuneCount > model.POST_MESSAGE_MAX_RUNES {
remainder = string(([]rune(post.Message))[model.POST_MESSAGE_MAX_RUNES:])
post.Message = truncateRunes(post.Message, model.POST_MESSAGE_MAX_RUNES)
} else {
remainder = ""
}
post.Hashtags, _ = model.ParseHashtags(post.Message)
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
l4g.Debug(utils.T("api.import.import_post.saving.debug"), post.UserId, post.Message)
}
post.Id = ""
post.CreateAt++
post.Message = remainder
}
}
开发者ID:Rudloff,项目名称:platform,代码行数:21,代码来源:import.go
示例12: Save
func (s SqlPostStore) Save(post *model.Post) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
if len(post.Id) > 0 {
result.Err = model.NewAppError("SqlPostStore.Save",
"You cannot update an existing Post", "id="+post.Id)
storeChannel <- result
close(storeChannel)
return
}
post.PreSave()
if result.Err = post.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if err := s.GetMaster().Insert(post); err != nil {
result.Err = model.NewAppError("SqlPostStore.Save", "We couldn't save the Post", "id="+post.Id+", "+err.Error())
} else {
time := model.GetMillis()
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = ?, TotalMsgCount = TotalMsgCount + 1 WHERE Id = ?", time, post.ChannelId)
if len(post.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ?", time, post.RootId)
}
result.Data = post
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
开发者ID:Dahlgren,项目名称:platform,代码行数:40,代码来源:sql_post_store.go
示例13: CreateCommandPost
func CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse) (*model.Post, *model.AppError) {
post.Message = parseSlackLinksToMarkdown(response.Text)
post.CreateAt = model.GetMillis()
if response.Attachments != nil {
parseSlackAttachment(post, response.Attachments)
}
switch response.ResponseType {
case model.COMMAND_RESPONSE_TYPE_IN_CHANNEL:
return CreatePost(post, teamId, true)
case model.COMMAND_RESPONSE_TYPE_EPHEMERAL:
if response.Text == "" {
return post, nil
}
post.ParentId = ""
SendEphemeralPost(teamId, post.UserId, post)
}
return post, nil
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:22,代码来源:command.go
示例14: Update
func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
newPost.UpdateAt = model.GetMillis()
oldPost.DeleteAt = newPost.UpdateAt
oldPost.UpdateAt = newPost.UpdateAt
oldPost.OriginalId = oldPost.Id
oldPost.Id = model.NewId()
if result.Err = newPost.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if _, err := s.GetMaster().Update(newPost); err != nil {
result.Err = model.NewLocAppError("SqlPostStore.Update", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+err.Error())
} else {
time := model.GetMillis()
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": newPost.ChannelId})
if len(newPost.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = :UpdateAt WHERE Id = :RootId", map[string]interface{}{"UpdateAt": time, "RootId": newPost.RootId})
}
// mark the old post as deleted
s.GetMaster().Insert(oldPost)
result.Data = newPost
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:41,代码来源:sql_post_store.go
示例15: SendEphemeralPost
func SendEphemeralPost(teamId, userId string, post *model.Post) {
post.Type = model.POST_EPHEMERAL
// fill in fields which haven't been specified which have sensible defaults
if post.Id == "" {
post.Id = model.NewId()
}
if post.CreateAt == 0 {
post.CreateAt = model.GetMillis()
}
if post.Props == nil {
post.Props = model.StringInterface{}
}
if post.Filenames == nil {
post.Filenames = []string{}
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_EPHEMERAL_MESSAGE, "", post.ChannelId, userId, nil)
message.Add("post", post.ToJson())
go Publish(message)
}
开发者ID:lfbrock,项目名称:platform,代码行数:22,代码来源:post.go
示例16: SendEphemeralPost
func SendEphemeralPost(teamId, userId string, post *model.Post) {
post.Type = model.POST_EPHEMERAL
// fill in fields which haven't been specified which have sensible defaults
if post.Id == "" {
post.Id = model.NewId()
}
if post.CreateAt == 0 {
post.CreateAt = model.GetMillis()
}
if post.Props == nil {
post.Props = model.StringInterface{}
}
if post.Filenames == nil {
post.Filenames = []string{}
}
message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
message.Add("post", post.ToJson())
PublishAndForget(message)
}
开发者ID:carriercomm,项目名称:platform,代码行数:22,代码来源:post.go
示例17: fireAndForgetNotifications
func fireAndForgetNotifications(post *model.Post, teamId, teamUrl string) {
go func() {
// Get a list of user names (to be used as keywords) and ids for the given team
uchan := Srv.Store.User().GetProfiles(teamId)
echan := Srv.Store.Channel().GetMembers(post.ChannelId)
cchan := Srv.Store.Channel().Get(post.ChannelId)
tchan := Srv.Store.Team().Get(teamId)
var channel *model.Channel
var channelName string
var bodyText string
var subjectText string
if result := <-cchan; result.Err != nil {
l4g.Error("Failed to retrieve channel channel_id=%v, err=%v", post.ChannelId, result.Err)
return
} else {
channel = result.Data.(*model.Channel)
if channel.Type == model.CHANNEL_DIRECT {
bodyText = "You have one new message."
subjectText = "New Direct Message"
} else {
bodyText = "You have one new mention."
subjectText = "New Mention"
channelName = channel.DisplayName
}
}
var mentionedUsers []string
if result := <-uchan; result.Err != nil {
l4g.Error("Failed to retrieve user profiles team_id=%v, err=%v", teamId, result.Err)
return
} else {
profileMap := result.Data.(map[string]*model.User)
if _, ok := profileMap[post.UserId]; !ok {
l4g.Error("Post user_id not returned by GetProfiles user_id=%v", post.UserId)
return
}
senderName := profileMap[post.UserId].Username
toEmailMap := make(map[string]bool)
if channel.Type == model.CHANNEL_DIRECT {
var otherUserId string
if userIds := strings.Split(channel.Name, "__"); userIds[0] == post.UserId {
otherUserId = userIds[1]
channelName = profileMap[userIds[1]].Username
} else {
otherUserId = userIds[0]
channelName = profileMap[userIds[0]].Username
}
otherUser := profileMap[otherUserId]
sendEmail := true
if _, ok := otherUser.NotifyProps["email"]; ok && otherUser.NotifyProps["email"] == "false" {
sendEmail = false
}
if sendEmail && (otherUser.IsOffline() || otherUser.IsAway()) {
toEmailMap[otherUserId] = true
}
} else {
// Find out who is a member of the channel only keep those profiles
if eResult := <-echan; eResult.Err != nil {
l4g.Error("Failed to get channel members channel_id=%v err=%v", post.ChannelId, eResult.Err.Message)
return
} else {
tempProfileMap := make(map[string]*model.User)
members := eResult.Data.([]model.ChannelMember)
for _, member := range members {
tempProfileMap[member.UserId] = profileMap[member.UserId]
}
profileMap = tempProfileMap
}
// Build map for keywords
keywordMap := make(map[string][]string)
for _, profile := range profileMap {
if len(profile.NotifyProps["mention_keys"]) > 0 {
// Add all the user's mention keys
splitKeys := strings.Split(profile.NotifyProps["mention_keys"], ",")
for _, k := range splitKeys {
keywordMap[k] = append(keywordMap[strings.ToLower(k)], profile.Id)
}
// If turned on, add the user's case sensitive first name
if profile.NotifyProps["first_name"] == "true" {
splitName := strings.Split(profile.FullName, " ")
if len(splitName) > 0 && splitName[0] != "" {
keywordMap[splitName[0]] = append(keywordMap[splitName[0]], profile.Id)
}
}
}
}
//.........这里部分代码省略.........
开发者ID:Dahlgren,项目名称:platform,代码行数:101,代码来源:post.go
示例18: sendNotifications
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel, profileMap map[string]*model.User, members []model.ChannelMember) {
var channelName string
var bodyText string
var subjectText string
var mentionedUsers []string
if _, ok := profileMap[post.UserId]; !ok {
l4g.Error(utils.T("api.post.send_notifications_and_forget.user_id.error"), post.UserId)
return
}
senderName := profileMap[post.UserId].Username
toEmailMap := make(map[string]bool)
if channel.Type == model.CHANNEL_DIRECT {
var otherUserId string
if userIds := strings.Split(channel.Name, "__"); userIds[0] == post.UserId {
otherUserId = userIds[1]
channelName = profileMap[userIds[1]].Username
} else {
otherUserId = userIds[0]
channelName = profileMap[userIds[0]].Username
}
otherUser := profileMap[otherUserId]
sendEmail := true
if _, ok := otherUser.NotifyProps["email"]; ok && otherUser.NotifyProps["email"] == "false" {
sendEmail = false
}
if sendEmail && (otherUser.IsOffline() || otherUser.IsAway()) {
toEmailMap[otherUserId] = true
}
} else {
// Find out who is a member of the channel, only keep those profiles
tempProfileMap := make(map[string]*model.User)
for _, member := range members {
tempProfileMap[member.UserId] = profileMap[member.UserId]
}
profileMap = tempProfileMap
// Build map for keywords
keywordMap := make(map[string][]string)
for _, profile := range profileMap {
if len(profile.NotifyProps["mention_keys"]) > 0 {
// Add all the user's mention keys
splitKeys := strings.Split(profile.NotifyProps["mention_keys"], ",")
for _, k := range splitKeys {
keywordMap[k] = append(keywordMap[strings.ToLower(k)], profile.Id)
}
}
// If turned on, add the user's case sensitive first name
if profile.NotifyProps["first_name"] == "true" {
keywordMap[profile.FirstName] = append(keywordMap[profile.FirstName], profile.Id)
}
// Add @all to keywords if user has them turned on
// if profile.NotifyProps["all"] == "true" {
// keywordMap["@all"] = append(keywordMap["@all"], profile.Id)
// }
// Add @channel to keywords if user has them turned on
if profile.NotifyProps["channel"] == "true" {
keywordMap["@channel"] = append(keywordMap["@channel"], profile.Id)
}
}
// Build a map as a list of unique user_ids that are mentioned in this post
splitF := func(c rune) bool {
return model.SplitRunes[c]
}
splitMessage := strings.Fields(post.Message)
for _, word := range splitMessage {
var userIds []string
// Non-case-sensitive check for regular keys
if ids, match := keywordMap[strings.ToLower(word)]; match {
userIds = append(userIds, ids...)
}
// Case-sensitive check for first name
if ids, match := keywordMap[word]; match {
userIds = append(userIds, ids...)
}
if len(userIds) == 0 {
// No matches were found with the string split just on whitespace so try further splitting
// the message on punctuation
splitWords := strings.FieldsFunc(word, splitF)
for _, splitWord := range splitWords {
// Non-case-sensitive check for regular keys
if ids, match := keywordMap[strings.ToLower(splitWord)]; match {
userIds = append(userIds, ids...)
}
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:platform,代码行数:101,代码来源:post.go
示例19: CreatePost
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
var pchan store.StoreChannel
if len(post.RootId) > 0 {
pchan = Srv.Store.Post().Get(post.RootId)
}
// Verify the parent/child relationships are correct
if pchan != nil {
if presult := <-pchan; presult.Err != nil {
return nil, model.NewLocAppError("createPost", "api.post.create_post.root_id.app_error", nil, "")
} else {
list := presult.Data.(*model.PostList)
if len(list.Posts) == 0 || !list.IsChannelId(post.ChannelId) {
return nil, model.NewLocAppError("createPost", "api.post.create_post.channel_root_id.app_error", nil, "")
}
if post.ParentId == "" {
post.ParentId = post.RootId
}
if post.RootId != post.ParentId {
parent := list.Posts[post.ParentId]
if parent == nil {
return nil, model.NewLocAppError("createPost", "api.post.create_post.parent_id.app_error", nil, "")
}
}
}
}
post.CreateAt = 0
post.Hashtags, _ = model.ParseHashtags(post.Message)
post.UserId = c.Session.UserId
if len(post.Filenames) > 0 {
doRemove := false
for i := len(post.Filenames) - 1; i >= 0; i-- {
path := post.Filenames[i]
doRemove = false
if model.UrlRegex.MatchString(path) {
continue
} else if model.PartialUrlRegex.MatchString(path) {
matches := model.PartialUrlRegex.FindAllStringSubmatch(path, -1)
if len(matches) == 0 || len(matches[0]) < 4 {
doRemove = true
}
channelId := matches[0][1]
if channelId != post.ChannelId {
doRemove = true
}
userId := matches[0][2]
if userId != post.UserId {
doRemove = true
}
} else {
doRemove = true
}
if doRemove {
l4g.Error(utils.T("api.post.create_post.bad_filename.error"), path)
post.Filenames = append(post.Filenames[:i], post.Filenames[i+1:]...)
}
}
}
var rpost *model.Post
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
} else {
rpost = result.Data.(*model.Post)
handlePostEventsAndForget(c, rpost, triggerWebhooks)
}
return rpost, nil
}
开发者ID:carriercomm,项目名称:platform,代码行数:80,代码来源:post.go
示例20: sendNotifications
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel, profileMap map[string]*model.User, members []model.ChannelMember) {
if _, ok := profileMap[post.UserId]; !ok {
l4g.Error(utils.T("api.post.send_notifications_and_forget.user_id.error"), post.UserId)
return
}
mentionedUserIds := make(map[string]bool)
alwaysNotifyUserIds := []string{}
if channel.Type == model.CHANNEL_DIRECT {
var otherUserId string
if userIds := strings.Split(channel.Name, "__"); userIds[0] == post.UserId {
otherUserId = userIds[1]
} else {
otherUserId = userIds[0]
}
mentionedUserIds[otherUserId] = true
} else {
// Find out who is a member of the channel, only keep those profiles
tempProfileMap := make(map[string]*model.User)
for _, member := range members {
if profile, ok := profileMap[member.UserId]; ok {
tempProfileMap[member.UserId] = profile
}
}
profileMap = tempProfileMap
// Build map for keywords
keywordMap := make(map[string][]string)
for _, profile := range profileMap {
if len(profile.NotifyProps["mention_keys"]) > 0 {
// Add all the user's mention keys
splitKeys := strings.Split(profile.NotifyProps["mention_keys"], ",")
for _, k := range splitKeys {
keywordMap[k] = append(keywordMap[strings.ToLower(k)], profile.Id)
}
}
// If turned on, add the user's case sensitive first name
if profile.NotifyProps["first_name"] == "true" {
keywordMap[profile.FirstName] = append(keywordMap[profile.FirstName], profile.Id)
}
// Add @channel and @all to keywords if user has them turned on
if profile.NotifyProps["channel"] == "true" {
keywordMap["@channel"] = append(keywordMap["@channel"], profile.Id)
keywordMap["@all"] = append(keywordMap["@all"], profile.Id)
}
if profile.NotifyProps["push"] == model.USER_NOTIFY_ALL &&
(post.UserId != profile.Id || post.Props["from_webhook"] == "true") &&
!post.IsSystemMessage() {
alwaysNotifyUserIds = append(alwaysNotifyUserIds, profile.Id)
}
}
// Build a map as a list of unique user_ids that are mentioned in this post
splitF := func(c rune) bool {
return model.SplitRunes[c]
}
splitMessage := strings.Fields(post.Message)
for _, word := range splitMessage {
var userIds []string
// Non-case-sensitive check for regular keys
if ids, match := keywordMap[strings.ToLower(word)]; match {
userIds = append(userIds, ids...)
}
// Case-sensitive check for first name
if ids, match := keywordMap[word]; match {
userIds = append(userIds, ids...)
}
if len(userIds) == 0 {
// No matches were found with the string split just on whitespace so try further splitting
// the message on punctuation
splitWords := strings.FieldsFunc(word, splitF)
for _, splitWord := range splitWords {
// Non-case-sensitive check for regular keys
if ids, match := keywordMap[strings.ToLower(splitWord)]; match {
userIds = append(userIds, ids...)
}
// Case-sensitive check for first name
if ids, match := keywordMap[splitWord]; match {
userIds = append(userIds, ids...)
}
}
}
for _, userId := range userIds {
if post.UserId == userId && post.Props["from_webhook"] != "true" {
continue
//.........这里部分代码省略.........
开发者ID:42wim,项目名称:platform,代码行数:101,代码来源:post.go
注:本文中的github.com/mattermost/platform/model.Post类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论