Exemplo n.º 1
0
func convertArticle(article *models.Article) *Article {
	u := &models.Account{Id: article.Author}
	u.FindByUserid(article.Author)
	coverText, _ := article.Cover()

	a := &Article{
		Id: "A" + article.Id.Hex(),
		Author: author{
			Id:     u.Id,
			Name:   u.Nickname,
			Avatar: u.Profile,
			Score:  strconv.Itoa(u.Score),
		},
		Comment:    true,
		Comments:   len(article.Reviews),
		Content:    formatContent(article.Contents),
		Cover:      "",
		PubTime:    article.PubTime.Unix() * 1000,
		UpdateTime: article.PubTime.Unix() * 1000,
		Title:      coverText,
	}
	for _, t := range article.Tags {
		a.TagList = append(a.TagList, tag{
			Id:  t,
			Tag: t,
		})
	}
	return a
}
Exemplo n.º 2
0
func comments(article *models.Article) (a []*Article) {
	_, list, _ := article.AdminComments(0, 0)
	for _, c := range list {
		art := convertArticle(&c)
		if len(c.Reviews) > 0 {
			art.CommentList = comments(&c)
		}
		a = append(a, art)
	}
	return a
}
Exemplo n.º 3
0
func comments(redis *models.RedisLogger, article *models.Article, pageIndex, pageCount int) (a []*articleInfo) {
	_, list, _ := article.AdminComments(pageIndex, pageCount)
	for _, c := range list {
		art := convertArticle(&c, redis)
		if len(c.Reviews) > 0 {
			art.Comments = comments(redis, &c, 0, 0)
		}
		a = append(a, art)
	}
	return a
}
Exemplo n.º 4
0
func taskSharedHandler(r *http.Request, w http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {
	form := p.(taskSharedForm)

	u := &models.Account{}
	u.FindByUserid(form.Sender)

	// ws push
	event := &models.Event{
		Type: models.EventSystem,
		Time: time.Now().Unix(),
		Data: models.EventData{
			Id:   user.Id,
			From: user.Id,
			To:   form.Sender,
		},
	}

	var article *models.Article

	switch form.Type {
	case models.TaskRunning:
		event.Data.Type = models.EventRunShared
		article = &models.Article{
			Author:  user.Id,
			PubTime: time.Now(),
			Contents: []models.Segment{
				{ContentType: "TEXT", ContentText: "我和" + u.Nickname + "约好一起跑步,有想一起参加的吗?" +
					"\n跑步地点: " + form.Addr +
					"\n跑步时间: " + time.Unix(form.Time, 0).Format("2006-01-02 3:04 PM")},
				{ContentType: "IMAGE", ContentText: form.Image},
			},
		}
	case models.TaskPost:
		article := &models.Article{}
		if find, _ := article.FindById(form.ArticleId); find {
			article.SetThumb(user.Id, true)
		}
		event.Data.Type = models.EventPostShared
	case models.TaskGame:
		event.Data.Type = models.EventPKShared
		result := u.Nickname + " 主动PK " + user.Nickname + "大获全胜。"
		if u.Props.Score < user.Props.Score {
			result = u.Nickname + " 主动PK " + user.Nickname + "大败亏输。"
		}
		article = &models.Article{
			Author:  user.Id,
			Type:    "pk",
			PubTime: time.Now(),
			Contents: []models.Segment{
				{ContentType: "TEXT", ContentText: result},
				{ContentType: "IMAGE", ContentText: form.Image},
			},
		}
	default:
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
		return
	}

	awards := Awards{}
	if form.Accept {
		redis.SetRelationship(user.Id, []string{form.Sender}, models.RelFriend, true)
		event.Save()
		redis.PubMsg(models.EventSystem, form.Sender, event.Bytes())
		user.UpdateRatio(form.Type, true)
		if article != nil {
			article.Save()
		}
		awards.Wealth = 1 * models.Satoshi
		GiveAwards(user, awards, redis)
	}

	redis.SetTaskShare(user.Id, false)

	writeResponse(r.RequestURI, w, map[string]interface{}{"ExpEffect": awards}, nil)
}