Пример #1
0
func recvHeartHandler(r *http.Request, w http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {

	form := p.(recvHeartForm)

	// ws push
	event := &models.Event{
		Type: models.EventSystem,
		Time: time.Now().Unix(),
		Data: models.EventData{
			Type: models.EventRecvHeart,
			Id:   user.Id,
			From: user.Id,
			To:   form.Sender,
			Body: []models.MsgBody{
				{Type: "userid", Content: user.Id},
			},
		},
	}

	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())
		awards.Wealth = 1 * models.Satoshi
		GiveAwards(user, awards, redis)
	}
	redis.SetHeartRecv(user.Id, false)
	writeResponse(r.RequestURI, w, map[string]interface{}{"ExpEffect": awards}, nil)
}
Пример #2
0
func sendHeartHandler(r *http.Request, w http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {

	form := p.(sendHeartForm)

	receivers := redis.HeartReceivers(user.Id)

	if len(receivers) == 0 {
		writeResponse(r.RequestURI, w, nil, nil)
	}

	var target string
	for _, recv := range receivers {
		if recv != user.Id {
			target = recv
			break
		}
	}
	// ws push
	event := &models.Event{
		Type: models.EventSystem,
		Time: time.Now().Unix(),
		Data: models.EventData{
			Type: models.EventSendHeart,
			Id:   user.Id,
			From: user.Id,
			To:   target,
			Body: []models.MsgBody{
				{Type: "record_id", Content: form.Record},
				{Type: "userid", Content: user.Id},
			},
		},
	}
	if len(target) > 0 {
		event.Save()
		redis.PubMsg(models.EventSystem, target, event.Bytes())
		redis.LogHeartSend(user.Id)
		redis.SetHeartRecv(target, true)
	}

	writeResponse(r.RequestURI, w, nil, nil)
}