func UpdatePresence(u *url.URL, h http.Header, participant *models.ChannelParticipant, context *models.Context) (int, http.Header, interface{}, error) { query := context.OverrideQuery(request.GetQuery(u)) participant.ChannelId = query.Id // only requester can update their last seen date participant.AccountId = query.AccountId if err := checkChannelPrerequisites( query.Id, query.AccountId, []*models.ChannelParticipant{participant}, ); err != nil { return response.NewBadRequest(err) } // @todo add a new function into participant just // for updating with lastSeenDate if err := participant.FetchParticipant(); err != nil { return response.NewBadRequest(err) } // glance the channel if err := participant.Glance(); err != nil { return response.NewBadRequest(err) } return response.NewOK(participant) }
func RejectInvite(u *url.URL, h http.Header, participant *models.ChannelParticipant, ctx *models.Context) (int, http.Header, interface{}, error) { query := ctx.OverrideQuery(request.GetQuery(u)) participant.StatusConstant = models.ChannelParticipant_STATUS_LEFT cp, err := updateStatus(participant, query, ctx) if err != nil { return response.NewBadRequest(err) } if err := addLeaveActivity(query.Id, ctx.Client.Account.Id, cp); err != nil { return response.NewBadRequest(err) } ch := models.NewChannel() if err := ch.ById(query.Id); err != nil { return response.NewBadRequest(err) } go notifyParticipants(ch, models.ChannelParticipant_Removed_From_Channel_Event, []*models.ChannelParticipant{cp}) return response.NewDefaultOK() }
func AcceptInvite(u *url.URL, h http.Header, participant *models.ChannelParticipant, ctx *models.Context) (int, http.Header, interface{}, error) { query := ctx.OverrideQuery(request.GetQuery(u)) participant.StatusConstant = models.ChannelParticipant_STATUS_ACTIVE cp, err := updateStatus(participant, query, ctx) if err != nil { return response.NewBadRequest(err) } if err := addJoinActivity(query.Id, cp, 0); err != nil { return response.NewBadRequest(err) } ch := models.NewChannel() if err := ch.ById(query.Id); err != nil { return response.NewBadRequest(err) } go notifyParticipants(ch, models.ChannelParticipant_Added_To_Channel_Event, []*models.ChannelParticipant{cp}) return response.NewDefaultOK() }