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) }
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) }