Пример #1
0
func (as *ArticleService) msgWrite(isUpdate bool, article *model.Article) {
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_CREATE),
		"author": article.User().Name,
		"link":   article.Href(),
		"title":  article.Title,
		"time":   utils.TimeUnixFormat(article.CreateTime, "01/02 15:04:05"),
	}
	var body string
	if isUpdate {
		data["type"] = fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_UPDATE)
		data["time"] = utils.TimeUnixFormat(article.UpdateTime, "01/02 15:04:05")
		body = com.Expand(MessageArticleUpdateTemplate, data)
	} else {
		body = com.Expand(MessageArticleCreateTemplate, data)
	}
	message := &model.Message{
		UserId:     article.UserId,
		From:       model.MESSAGE_FROM_ARTICLE,
		FromId:     article.Id,
		Type:       model.MESSAGE_TYPE_ARTICLE_CREATE,
		Body:       body,
		CreateTime: article.CreateTime,
	}
	if isUpdate {
		message.Type = model.MESSAGE_TYPE_ARTICLE_UPDATE
	}
	Message.Save(message)
}
Пример #2
0
func (as *ArticleService) msgDelete(id int64) {
	article := new(model.Article)
	if _, err := core.Db.Where("id = ?", id).Get(article); err != nil {
		return
	}
	if article == nil || article.Id != id {
		return
	}
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_ARTICLE_REMOVE),
		"author": article.User().Name,
		"title":  article.Title,
		"time":   utils.TimeUnixFormat(article.CreateTime, "01/02 15:04:05"),
	}
	body := com.Expand(MessageArticleRemoveTemplate, data)
	message := &model.Message{
		UserId:     article.UserId,
		From:       model.MESSAGE_FROM_ARTICLE,
		FromId:     article.Id,
		Type:       model.MESSAGE_TYPE_ARTICLE_REMOVE,
		Body:       body,
		CreateTime: article.CreateTime,
	}
	Message.Save(message)
}
Пример #3
0
func (cs *CommentService) msgSave(cmt *model.Comment) {
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_COMMENT_CREATE),
		"time":   utils.TimeUnixFormat(cmt.CreateTime, "01/02 15:04:05"),
		"author": cmt.Name,
		"site":   cmt.AuthorUrl(),
		"body":   cmt.Body,
		"title":  cmt.FromTitle(),
	}

	message := &model.Message{
		UserId:     cmt.UserId,
		From:       model.MESSAGE_FROM_COMMENT,
		FromId:     cmt.Id,
		Type:       model.MESSAGE_TYPE_COMMENT_CREATE,
		CreateTime: cmt.CreateTime,
	}

	if cmt.ParentId > 0 {
		if p := cmt.GetParent(); p != nil {
			data["parent"] = p.Name
			data["parent_content"] = p.Body
			fmt.Println("--------------", p)
			message.Type = model.MESSAGE_TYPE_COMMENT_REPLY
			message.Body = com.Expand(MessageCommentReplyTemplate, data)
			Message.Save(message)
			return
		}
	}
	message.Body = com.Expand(MessageCommentLeaveTemplate, data)
	Message.Save(message)
}
Пример #4
0
func (ms *MediaService) msgUpload(m *model.Media) {
	user, err := getUserBy("id", m.UserId)
	if err != nil {
		return
	}
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_MEDIA_UPLOAD),
		"time":   utils.TimeUnixFormat(m.CreateTime, "01/02 15:04:05"),
		"author": user.Name,
		"file":   m.Name,
	}
	message := &model.Message{
		UserId:     m.UserId,
		From:       model.MESSAGE_FROM_MEDIA,
		FromId:     m.Id,
		Type:       model.MESSAGE_TYPE_MEDIA_UPLOAD,
		CreateTime: m.CreateTime,
		Body:       com.Expand(MessageMediaUploadTemplate, data),
	}
	Message.Save(message)
}
Пример #5
0
func (bs *BackupService) msgCreate(file string) {
	info, err := os.Stat(file)
	if err != nil {
		return
	}
	data := map[string]string{
		"type": fmt.Sprint(model.MESSAGE_TYPE_BACKUP_CREATE),
		"file": filepath.Base(file),
		"time": utils.TimeUnixFormat(info.ModTime().Unix(), "01/02 15:04:05"),
	}
	body := com.Expand(MessageBackupCreateTemplate, data)
	message := &model.Message{
		UserId:     0,
		From:       model.MESSAGE_FROM_BACKUP,
		FromId:     0,
		Type:       model.MESSAGE_TYPE_BACKUP_CREATE,
		Body:       body,
		CreateTime: info.ModTime().Unix(),
	}
	Message.Save(message)
}