Ejemplo n.º 1
0
        public static VkConversation FromJson(JToken json, string apiVersion = null)
        {
            if (json == null)
            {
                throw new Exception("Json can't be null");
            }

            var result = new VkConversation();

            if (json["id"] != null)
            {
                result.Id = (long)json["id"];
            }

            if (json["title"] != null)
            {
                result.Title = (string)json["title"];
            }

            if (json["admin_id"] != null)
            {
                result.AdminId = (long)json["admin_id"];
            }

            if (json["users"] != null)
            {
                result.Users = (from u in json["users"] select VkProfile.FromJson(u)).ToList();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <VkConversation> GetChat(long chatId, IEnumerable <long> chatIds = null, string fields = null, string nameCase = null)
        {
            if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired)
            {
                throw new Exception("Access token is not valid.");
            }

            var parametres = new Dictionary <string, string>();

            if (chatId != 0)
            {
                parametres.Add("chat_id", chatId.ToString());
            }
            else
            {
                if (chatIds != null)
                {
                    parametres.Add("chat_ids", string.Join(",", chatIds));
                }
                else
                {
                    throw new Exception("Chat id or chat ids must be specified.");
                }
            }

            if (!string.IsNullOrEmpty(fields))
            {
                parametres.Add("fields", fields);
            }

            if (!string.IsNullOrEmpty(nameCase))
            {
                parametres.Add("name_case", nameCase);
            }

            _vkontakte.SignMethod(parametres);

            var response = await VkRequest.GetAsync(VkConst.MethodBase + "messages.getChat", parametres);

            if (response["response"] != null)
            {
                return(VkConversation.FromJson(response["response"]));
            }

            return(null);
        }