コード例 #1
0
        public async Task<List<ChannelState>> QueryChannels(QueryChannelsOptions opts)
        {
            var request = this.BuildAppRequest("channels", HttpMethod.GET);
            opts.Apply(request);

            var response = await this.MakeRequest(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var root = JObject.Parse(response.Content);
                var chans = root.Property("channels").Value as JArray;
                var result = new List<ChannelState>();
                foreach (var chan in chans)
                {
                    var chanObj = chan as JObject;
                    result.Add(ChannelState.FromJObject(chanObj));
                }
                return result;
            }
            throw StreamChatException.FromResponse(response);
        }
コード例 #2
0
ファイル: ChannelState.cs プロジェクト: tjkb/stream-chat-net
        internal static ChannelState FromJObject(JObject jObj)
        {
            var result = new ChannelState();
            var data   = JsonHelpers.FromJObject(result, jObj);

            var chanObj = data.GetData <JObject>("channel");

            if (chanObj != null)
            {
                result.Channel = ChannelObjectWithInfo.FromJObject(chanObj);
            }

            var msgs = data.GetData <JArray>("messages");

            if (msgs != null)
            {
                var messages = new List <Message>();
                foreach (var msg in msgs)
                {
                    var msgObj = msg as JObject;
                    messages.Add(Message.FromJObject(msgObj));
                }
                result.Messages = messages;
            }

            var usrs = data.GetData <JArray>("watchers");

            if (usrs != null)
            {
                var users = new List <User>();
                foreach (var usr in usrs)
                {
                    var usrObj = usr as JObject;
                    users.Add(User.FromJObject(usrObj));
                }
                result.Watchers = users;
            }

            var reads = data.GetData <JArray>("read");

            if (reads != null)
            {
                var readsList = new List <Read>();
                foreach (var read in reads)
                {
                    var readObj = read as JObject;
                    readsList.Add(Read.FromJObject(readObj));
                }
                result.Reads = readsList;
            }

            var mbrs = data.GetData <JArray>("members");

            if (mbrs != null)
            {
                var members = new List <ChannelMember>();
                foreach (var mbr in mbrs)
                {
                    var memberObj = mbr as JObject;
                    members.Add(ChannelMember.FromJObject(memberObj));
                }
                result.Members = members;
            }

            return(result);
        }