Example #1
0
File: page.go Project: hxdyxd/pugo
func (ps *PageService) msgWrite(isUpdate bool, page *model.Page) {
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_PAGE_CREATE),
		"author": page.User().Name,
		"link":   page.Href(),
		"title":  page.Title,
		"time":   utils.TimeUnixFormat(page.CreateTime, "01/02 15:04:05"),
	}
	var body string
	if isUpdate {
		data["type"] = fmt.Sprint(model.MESSAGE_TYPE_PAGE_UPDATE)
		body = com.Expand(MessagePageUpdateTemplate, data)
	} else {
		body = com.Expand(MessagePageCreateTemplate, data)
	}
	message := &model.Message{
		UserId:     page.UserId,
		From:       model.MESSAGE_FROM_PAGE,
		FromId:     page.Id,
		Type:       model.MESSAGE_TYPE_PAGE_CREATE,
		Body:       body,
		CreateTime: page.CreateTime,
	}
	if isUpdate {
		message.Type = model.MESSAGE_TYPE_PAGE_UPDATE
	}
	Message.Save(message)
}
Example #2
0
File: page.go Project: hxdyxd/pugo
func (ps *PageService) msgDelete(id int64) {
	page := new(model.Page)
	if _, err := core.Db.Where("id = ?", id).Get(page); err != nil {
		return
	}
	if page == nil || page.Id != id {
		return
	}
	data := map[string]string{
		"type":   fmt.Sprint(model.MESSAGE_TYPE_PAGE_REMOVE),
		"author": page.User().Name,
		"title":  page.Title,
		"time":   utils.TimeUnixFormat(page.CreateTime, "01/02 15:04:05"),
	}
	body := com.Expand(MessagePageRemoveTemplate, data)
	message := &model.Message{
		UserId:     page.UserId,
		From:       model.MESSAGE_FROM_PAGE,
		FromId:     page.Id,
		Type:       model.MESSAGE_TYPE_PAGE_REMOVE,
		Body:       body,
		CreateTime: page.CreateTime,
	}
	Message.Save(message)
}