예제 #1
0
파일: group.go 프로젝트: shevilangle/sports
func setGroupHandler(request *http.Request, resp http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {

	form := p.(setGroupForm)

	group := &models.Group{
		Gid:     form.Id,
		Name:    form.Name,
		Profile: form.Profile,
		Desc:    form.Desc,
		Creator: user.Id,
		Time:    time.Now(),
	}

	if form.Address.String() != "" {
		group.Addr = &form.Address
		loc := models.Addr2Loc(form.Address)
		group.Loc = &loc
	}

	var err error
	if len(form.Id) == 0 {
		err = group.Save()
		if err == nil {
			redis.JoinGroup(user.Id, group.Gid, true)
		}
	} else {
		err = group.Update()
	}

	writeResponse(request.RequestURI, resp, map[string]string{"group_id": group.Gid}, err)
}
예제 #2
0
파일: group.go 프로젝트: shevilangle/sports
func joinGroupHandler(request *http.Request, resp http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {

	form := p.(joinGroupForm)

	redis.JoinGroup(user.Id, form.Gid, !form.Leave)
	writeResponse(request.RequestURI, resp, nil, nil)

	event := &models.Event{
		Type: "message",
		Data: models.EventData{
			From: user.Id,
			To:   form.Gid,
		},
	}
	if !form.Leave {
		event.Data.Type = "subscribe"
	} else {
		event.Data.Type = "unsubscribe"
	}

	redis.PubMsg(event.Data.Type, user.Id, event.Bytes())
}