Esempio n. 1
0
        /// <summary>
        /// Отправляет Push-уведомление внутри приложения.
        /// </summary>
        /// <param name="conversation">Беседа, уведомление для которой нужно отправить.</param>
        /// <param name="message">Сообщение для отправки.</param>
        private void SendPush(IConversation conversation, VKMessage message)
        {
            if ((message.Type & VKMessageType.Sent) == VKMessageType.Sent)
            {
                return;
            }

            var navParameter = new NavigateToPageMessage
            {
                Page      = AppViews.ConversationView,
                Parameter = conversation.ID
            };

            string title = null;

            if (message.IsChatMessage)
            {
                title = String.Format("{0}\n{1}", message.Sender.FullName, conversation.Title);
            }
            else
            {
                title = message.Sender.FullName;
            }

            CoreHelper.SendInAppPush(message.Body,
                                     title, PopupMessageType.Default,
                                     message.Sender.Photo50, parameter: navParameter);
        }
Esempio n. 2
0
        /// <summary>
        /// Обработать диалог для переданного сообщения.
        /// </summary>
        /// <param name="lastMessage">Последнее сообщение в диалоге.</param>
        private async void WorkOnDialog(VKMessage lastMessage)
        {
            if (Dialogs.Count == 0)
            {
                return;
            }

            VKDialog dialog = null;

            if (lastMessage.IsChatMessage)
            {
                dialog = Dialogs.FirstOrDefault(d => d.Message.ChatID == lastMessage.ChatID);
            }
            else
            {
                dialog = Dialogs.FirstOrDefault(d => !d.Message.IsChatMessage && d.Message.UserID == lastMessage.UserID);
            }

            if (dialog == null)
            {
                return;
            }

            dialog.Unread                   += 1;
            dialog.Message.Body              = lastMessage.Body;
            dialog.Message.Date              = lastMessage.Date;
            dialog.Message.Attachments       = lastMessage.Attachments;
            dialog.Message.Sender            = lastMessage.Sender;
            dialog.Message.UserID            = lastMessage.UserID;
            dialog.Message.ChatID            = lastMessage.ChatID;
            dialog.Message.Type              = lastMessage.Type;
            dialog.Message.ReadState         = lastMessage.ReadState;
            dialog.Message.Geo               = lastMessage.Geo;
            dialog.Message.Action            = lastMessage.Action;
            dialog.Message.ActionEmail       = lastMessage.ActionEmail;
            dialog.Message.ActionMid         = lastMessage.ActionMid;
            dialog.Message.ActionText        = lastMessage.ActionText;
            dialog.Message.ID                = lastMessage.ID;
            dialog.Message.IsDeleted         = lastMessage.IsDeleted;
            dialog.Message.ForwardedMessages = lastMessage.ForwardedMessages;
            dialog.Message.HasEmoji          = lastMessage.HasEmoji;
            dialog.Message.IsImportant       = lastMessage.IsImportant;

            lock (Dialogs)
            {
                var temp  = Dialogs[0];
                int index = Dialogs.IndexOf(dialog);
                Dialogs[0]     = Dialogs[index];
                Dialogs[index] = temp;
            }
        }
 public static IList<VKUser> getUsersByMessage(VKMessage message)
 {
     IList<VKUser> userList = new List<VKUser>();
     using (VKDataContext context = new VKDataContext(VKDataContext.DBConnectionString))
     {
         IQueryable<UserMessage> usermessagequery = from c in context.UserMessage where c.VKMessageID == message.VKMessageID select c;
         IList<UserMessage> usermessageList = usermessagequery.ToList();
         foreach (UserMessage um in usermessageList)
         {
             IQueryable<VKUser> userquery = from c in context.VKUser where c.VKUserID == um.VKUserID select c;
             foreach(VKUser user in userquery.ToList()){
                 userList.Add(user);
             }
         }
     }
     return userList;
 }
Esempio n. 4
0
        /// <summary>
        /// Отправляет сообщение в беседу.
        /// </summary>
        private async Task SendMessage()
        {
            var text = EnteredText.Trim();

            EnteredText = String.Empty;
            var msg = new VKMessage
            {
                Body        = text,
                Date        = DateTime.Now,
                ChatID      = IsChat ? ChatID : 0,
                UserID      = ServiceHelper.SettingsService.AccessToken.UserID,
                Type        = VKMessageType.Sent,
                SentType    = VKSentMessageType.Sending,
                Attachments = Attachments.ToList()
            };

            Messages.Insert(0, msg);
            Messages.NewSentMessages.Add(msg);

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

            param["message"] = text;

            if (IsChat)
            {
                param["chat_id"] = ChatID.ToString();
            }
            else
            {
                param["user_id"] = UserID.ToString();
            }

            var request  = new UniversalVKRequest <ulong>(VKMethodsConstants.MessageSend, param);
            var response = await request.ExecuteAsync();

            if (response.Error.ErrorType == VKErrors.None)
            {
                msg.ID       = response.Response;
                msg.SentType = VKSentMessageType.Unread;
            }
            else
            {
                msg.SentType = VKSentMessageType.Error;
            }
        }