本文整理汇总了Golang中github.com/mattermost/platform/model.Post.PreSave方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.PreSave方法的具体用法?Golang Post.PreSave怎么用?Golang Post.PreSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.Post
的用法示例。
在下文中一共展示了Post.PreSave方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}