コード例 #1
0
ファイル: form.go プロジェクト: trigrass2/wego
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
	changes := utils.FormChanges(post, form)
	if len(changes) == 0 {
		return nil
	}
	utils.SetFormValues(form, post)
	post.CategoryId = form.Category
	post.TopicId = form.Topic
	for _, c := range changes {
		if c == "Content" {
			post.ContentCache = utils.RenderMarkdown(form.Content)
			changes = append(changes, "ContentCache")
		}
	}

	// update last edit author
	if post.LastAuthorId != user.Id {
		post.LastAuthorId = user.Id
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return models.UpdateById(post.Id, post, models.Obj2Table(changes)...)
}
コード例 #2
0
ファイル: form.go プロジェクト: trigrass2/wego
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	post.UserId = form.User
	post.LastReplyId = form.LastReply
	post.LastAuthorId = form.LastAuthor
	post.TopicId = form.Topic
	//get category
	if topic, err := models.GetTopicById(form.Topic); err == nil {
		post.CategoryId = topic.CategoryId
	}
	post.ContentCache = utils.RenderMarkdown(post.Content)
}
コード例 #3
0
ファイル: form.go プロジェクト: trigrass2/wego
func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
	utils.SetFormValues(form, post)
	post.CategoryId = form.Category
	post.TopicId = form.Topic
	post.UserId = user.Id
	post.LastReplyId = user.Id
	post.LastAuthorId = user.Id
	post.CanEdit = true
	post.ContentCache = utils.RenderMarkdown(form.Content)

	// mentioned follow users
	FilterMentions(user, post.ContentCache)

	return post.Insert()
}