Ejemplo n.º 1
0
        /// <summary> Получить ModelChatMessage из ChatMessageModelManaged </summary>
        private static ModelChatMessage GetModelChatMessageFromChatMessageModelManaged(ChatMessageModelManaged chatMessageModelManaged)
        {
            if (chatMessageModelManaged == null)
            {
                return(null);
            }

            var dataSourceContact = new DataSourceContact();

            var result = new ModelChatMessage
            {
                Id            = chatMessageModelManaged.Id,
                IdChat        = chatMessageModelManaged.ChatId,
                SendTime      = chatMessageModelManaged.SendTime,
                Servered      = chatMessageModelManaged.Servered,
                Readed        = chatMessageModelManaged.Readed,
                StringContent = chatMessageModelManaged.StringContent,
                Changed       = chatMessageModelManaged.Changed,
                Rownum        = chatMessageModelManaged.Rownum,
                Encrypted     = chatMessageModelManaged.Encrypted,

                Sender           = DataSourceContact.GetModelContactFromContactModelManaged(chatMessageModelManaged.Sender),
                ModelContactData = DataSourceContact.GetModelContactFromContactModelManaged(chatMessageModelManaged.ContactData),

                ModelEnumChatMessageTypeObj          = ModelEnumChatMessageType.GetModelEnum((int)chatMessageModelManaged.Type),
                ModelEnumChatMessageQuoteTypeObj     = ModelEnumChatMessageQuoteType.GetModelEnum((int)chatMessageModelManaged.QuoteType),
                ModelEnumChatMessageSecurityLevelObj = ModelEnumChatMessageSecurityLevel.GetModelEnum((int)chatMessageModelManaged.SecurityLevel)
            };

            if (result.ModelContactData != null)
            {
                DataSourceContact.RefreshModelContactStatus(result.ModelContactData);
            }

            var quotedMessages = ConvertChatMessageModelManagedAtModelChatMessage(chatMessageModelManaged.QuotedMessages);

            if (quotedMessages.Count != 0)
            {
                result.ListQuotedModelChatMessage = new ObservableCollection <ModelChatMessage>(quotedMessages);
            }

            if (chatMessageModelManaged.NotificationData != null)
            {
                result.ModelNotificationDataObj = new ModelNotificationData()
                {
                    ListModelContact = DataSourceContact.GetListModelContactFromArrayContactModelManaged(chatMessageModelManaged.NotificationData.Contacts),
                    ModelEnumChatNotificationTypeObj = ModelEnumChatNotificationType.GetModelEnum((int)chatMessageModelManaged.NotificationData.Type)
                };
            }



            return(result);
        }
Ejemplo n.º 2
0
        /// <summary> Метод отправки сообщения </summary>
        private void SendModelMessage()
        {
            CurrentModelChatMessage.Sender   = DataSourceContact.ModelContactIam;
            CurrentModelChatMessage.SendTime = DateTime.Now;
            CurrentModelChatMessage.ModelEnumChatMessageTypeObj = ModelEnumChatMessageType.GetModelEnum(0); // простое тесктовое сообщение
            CurrentModelChatMessage.IdChat = CurrentModelChat.Id;

            if (CurrentModelChat.IsP2P)
            {
                CurrentModelChatMessage.ModelEnumChatMessageSecurityLevelObj = ModelEnumChatMessageSecurityLevel.GetModelEnum(1); //сообщения зашифрованые
            }
            else
            {
                CurrentModelChatMessage.ModelEnumChatMessageSecurityLevelObj = ModelEnumChatMessageSecurityLevel.GetModelEnum(0); //сообщения не зашифрованые
            }

            if (_currentListQuotedMessage.Count != 0)
            {
                if (_currentListQuotedMessage.Count == 1 && JustAnswerCurrentMessage && String.IsNullOrWhiteSpace(_currentListQuotedMessage.First().StringContent))
                {
                    JustAnswerCurrentMessage = false;
                }

                DataSourceChat.QuoteAndSendMessages(CurrentModelChatMessage, _currentListQuotedMessage, JustAnswerCurrentMessage);

                _currentListQuotedMessage.Clear();
                CurrentModelChatMessage = new ModelChatMessage();
            }
            else
            {
                if (DataSourceChat.SendModelChatMessage(CurrentModelChatMessage))
                {
                    OnEventViewModel("SendModelMessage", CurrentModelChatMessage);

                    ListModelChatMessage.Add(CurrentModelChatMessage);

                    CurrentModelChatMessage = new ModelChatMessage();
                }
            }

            if (CurrentModelChat.DraftMessage != null)
            {
                CurrentModelChat.DraftMessage = null;
            }
        }