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