func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) { userIds := model.ArrayFromJson(r.Body) if len(userIds) == 0 { c.SetInvalidParam("getStatusesByIdsHttp", "user_ids") return } statusMap, err := GetStatusesByIds(userIds) if err != nil { c.Err = err return } w.Write([]byte(model.StringInterfaceToJson(statusMap))) }
func getStatuses(c *Context, w http.ResponseWriter, r *http.Request) { userIds := model.ArrayFromJson(r.Body) if len(userIds) == 0 { c.SetInvalidParam("getStatuses", "userIds") return } if result := <-Srv.Store.User().GetProfiles(c.Session.TeamId); result.Err != nil { c.Err = result.Err return } else { profiles := result.Data.(map[string]*model.User) statuses := map[string]string{} for _, profile := range profiles { found := false for _, uid := range userIds { if uid == profile.Id { found = true } } if !found { continue } if profile.IsOffline() { statuses[profile.Id] = model.USER_OFFLINE } else if profile.IsAway() { statuses[profile.Id] = model.USER_AWAY } else { statuses[profile.Id] = model.USER_ONLINE } } //w.Header().Set("Cache-Control", "max-age=9, public") // 2 mins w.Write([]byte(model.MapToJson(statuses))) return } }
func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) { userIds := model.ArrayFromJson(r.Body) if len(userIds) == 0 { c.SetInvalidParam("getTeamMembersByIds", "user_ids") return } if c.Session.GetTeamByTeamId(c.TeamId) == nil { if !HasPermissionToTeamContext(c, c.TeamId, model.PERMISSION_MANAGE_SYSTEM) { return } } if result := <-Srv.Store.Team().GetMembersByIds(c.TeamId, userIds); result.Err != nil { c.Err = result.Err return } else { members := result.Data.([]*model.TeamMember) w.Write([]byte(model.TeamMembersToJson(members))) return } }
func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelId := params["channel_id"] userIds := model.ArrayFromJson(r.Body) if len(userIds) == 0 { c.SetInvalidParam("getChannelMembersByIds", "user_ids") return } if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_READ_CHANNEL) { return } if result := <-app.Srv.Store.Channel().GetMembersByIds(channelId, userIds); result.Err != nil { c.Err = result.Err return } else { members := result.Data.(model.ChannelMembers) w.Write([]byte(members.ToJson())) return } }