Beispiel #1
0
        /// <summary> Освобождение ресурсов </summary>
        public void Dispose()
        {
            if (!String.IsNullOrWhiteSpace(CurrentModelChatMessage.StringContent) || _currentListQuotedMessage.Count > 0)
            {
                CurrentModelChatMessage.Sender   = DataSourceContact.ModelContactIam;
                CurrentModelChatMessage.SendTime = DateTime.Now;
                CurrentModelChatMessage.ModelEnumChatMessageTypeObj = ModelEnumChatMessageType.GetModelEnum(7);
                CurrentModelChatMessage.IdChat = CurrentModelChat.Id;
                if (_currentListQuotedMessage.Count > 0)
                {
                    CurrentModelChatMessage.ListQuotedModelChatMessage = new ObservableCollection <ModelChatMessage>(_currentListQuotedMessage);
                }

                if (DataSourceChat.SaveDraftModelChatMessage(CurrentModelChatMessage))
                {
                    CurrentModelChat.DraftMessage = CurrentModelChatMessage;
                }
            }
            else
            {
                if (CurrentModelChat.DraftMessage != null)
                {
                    DataSourceChat.SaveDraftModelChatMessage(CurrentModelChatMessage);
                    CurrentModelChat.DraftMessage = null;
                }
            }

            CallbackRouter.Instance.ListModelChatMessageChanged         -= OnListModelChatMessageChanged;
            CallbackRouter.Instance.ListModelContactStatusChanged       -= OnListModelContactStatusChanged;
            CallbackRouter.Instance.ListModelContactSubscriptionChanged -= OnListModelContactSubscriptionChanged;
            CallbackRouter.Instance.ModelUserSettingsChanged            -= OnModelUserSettingsChanged;
        }
Beispiel #2
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);
        }
Beispiel #3
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;
            }
        }
Beispiel #4
0
        /// <summary> Удалить сообщение </summary>
        public void DeleteModelChatMessage(ModelChatMessage modelChatMessage)
        {
            if (modelChatMessage.Sender.Iam)
            {
                if (DataSourceChat.DeleteModelChatMessage(modelChatMessage))
                {
                    modelChatMessage.ModelEnumChatMessageTypeObj = ModelEnumChatMessageType.GetModelEnum(5);
                }
            }
            else
            {
                modelChatMessage.ModelEnumChatMessageTypeObj = ModelEnumChatMessageType.GetModelEnum(5);
            }

            if (modelChatMessage.ListQuotedModelChatMessage != null)
            {
                modelChatMessage.ListQuotedModelChatMessage.Clear();
            }
        }