Результат выполнения запроса получения диалогов
Ejemplo n.º 1
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns>Объект типа MessagesGetObject</returns>
        public static MessagesGetObject FromJson(VkResponse response)
        {
            var dialogsGetObject = new MessagesGetObject
            {
                TotalCount = response["count"],
                Unread     = response["unread_dialogs"],
                RealOffset = response["real_offset"],
                Messages   = response["items"].ToReadOnlyCollectionOf <Message>(m => m)
            };

            return(dialogsGetObject);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static MessagesGetObject FromJson(VkResponse response)
        {
            var dialogsGetObject = new MessagesGetObject
            {
                TotalCount = response["count"],
                Unread = response["unread_dialogs"],
                RealOffset = response["real_offset"],
                Messages = response["items"].ToReadOnlyCollectionOf<Message>(m => m)
            };

            return dialogsGetObject;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> Объект типа MessagesGetObject </returns>
        public static MessagesGetObject FromJson(VkResponse response)
        {
            var dialogsGetObject = new MessagesGetObject
            {
                TotalCount   = response[key : "count"]
                , Unread     = response[key : "unread"] ?? response[key : "unread_dialogs"]
                , RealOffset = response[key : "real_offset"]
                , Messages   = response[key : "items"].ToReadOnlyCollectionOf <Message>(selector : m => m)
                , InRead     = response[key : "in_read"]
                , OutRead    = response[key : "out_read"]
            };

            return(dialogsGetObject);
        }
Ejemplo n.º 4
0
        // Получение сообщений и составление списка userIdsToGet
        /// <summary>
        /// Receives the messages.
        /// </summary>
        /// <param name="userIdsToGet">The user ids to get.</param>
        /// <param name="vkMessages">The vk messages.</param>
        /// <returns></returns>
        bool ReceiveMessages(List<long> userIdsToGet, ref MessagesGetObject vkMessages)
        {
            if (userIdsToGet == null) return false;
            MessagesGetParams vkMsgParams = new MessagesGetParams();

            vkMsgParams.Count = 100;
            vkMsgParams.Offset = 0;
            vkMsgParams.TimeOffset = 0;
            vkMsgParams.Filters = MessagesFilter.All;

            try
            {
                vkMessages = vk.Messages.Get(vkMsgParams);//vk.Messages.Get(0, out offset, 100, 0, new TimeSpan(0), 0);
            }
            catch (Exception)
            {
                return false;
            }

            // Составление списка userIdsToGet (id пользователей, которых надо получить с сервера) из сообщений
            foreach (var vkMessage in vkMessages.Messages)
            {
                long vkMessageUserId;

                if (vkMessage.UserId.HasValue)
                {
                    vkMessageUserId = vkMessage.UserId.Value;

                    if ((!usersDict.ContainsKey(vkMessageUserId)) && (!userIdsToGet.Contains(vkMessageUserId)))
                        userIdsToGet.Add(vkMessageUserId);
                }
            }
            return true;
        }
Ejemplo n.º 5
0
        // Формирование сообщений
        /// <summary>
        /// Forms the messages from vk messages.
        /// </summary>
        /// <param name="vkMessages">The vk messages.</param>
        void FormMessagesFromVkMessages(MessagesGetObject vkMessages)
        {
            foreach (var vkMessage in vkMessages.Messages)
            {
                long vkMessageUserId = 0;

                if (vkMessage.ReadState.HasValue)
                {
                    if (vkMessage.ReadState.Value == MessageReadState.Readed)
                        continue;
                }
                else continue;

                Message msg = new Message();

                if (vkMessage.UserId.HasValue)
                {
                    vkMessageUserId = vkMessage.UserId.Value;

                    if (usersDict.ContainsKey(vkMessageUserId))
                    {
                        if ((usersDict[vkMessageUserId].FirstName != null) && (usersDict[vkMessageUserId].LastName != null))
                            msg.SenderName = usersDict[vkMessageUserId].FirstName + " " + usersDict[vkMessageUserId].LastName;
                        else if (usersDict[vkMessageUserId].Nickname != null)
                            msg.SenderName = usersDict[vkMessageUserId].Nickname;
                    }
                }

                if (string.IsNullOrEmpty(msg.SenderName) && !string.IsNullOrEmpty(vkMessage.Title))
                    msg.SenderName = vkMessage.Title;

                if (vkMessage.Id.HasValue)
                    msg.Id = vkMessage.Id.Value;

                msg.MsgText = vkMessage.Body;

                if (vkMessage.ChatId.HasValue)
                {
                    msg.MsgType = MsgTypes.Dialog;
                    if (vkMessage.ChatId.HasValue)
                    {
                        msg.MsgUrl = "https://vk.com/im?msgid=" + msg.Id.ToString() + "&sel=c" + vkMessage.ChatId.Value;
                        msg.DomainUrl = "https://vk.com/im?sel=c" + vkMessage.ChatId.Value;
                    }
                    else
                    {
                        msg.MsgUrl = "https://vk.com/im";
                        msg.DomainUrl = "https://vk.com/im";
                    }

                }
                else
                {
                    msg.MsgType = MsgTypes.Personal;
                    msg.MsgUrl = "https://vk.com/im?msgid=" + msg.Id.ToString() + "&sel=" + vkMessageUserId.ToString();
                    msg.DomainUrl = "https://vk.com/im?sel=" + vkMessageUserId.ToString();
                }

                messageStack.Push(msg);
                //break;
            }
        }