예제 #1
0
        public async void PullNewMessages()
        {
            while (true)
            {
                foreach (var channel in DependencyManager.ChannelsPage.ViewModel.Channels)
                {
                    foreach (var message in RestService.GetMessageBy(channel.Id).Result)
                    {
                        if (channel.Messages.Exists(item => item.Id == message.Id))
                        {
                            continue;                                                         // If message exists
                        }
                        IDecrypt decryption = new DecryptionLogic(message, channel.KeyTable);
                        channel.View.ViewModel.Messages.Add(decryption.Decrypt());
                        channel.Messages.Add(message);
                        DependencyManager.Database.InsertWithChildren(message);
                        DependencyManager.Database.UpdateWithChildren(channel);

                        if (message.ProcessingCounter + 1 >= channel.Members.Count)
                        {
                            // TODO: Handle REST return
                            new Task(() => { RestService.DeleteMessageBy(message.Id); }).Start();
                        }
                        else
                        {
                            // TODO: Handle REST return
                            new Task(() => { RestService.UpdateMessageProcessingCounterBy(message.Id); }).Start();
                        }
                    }
                }
                await Task.Delay(5000); // 5 seconds
            }
        }
예제 #2
0
        public bool SendMessage(string message, Channel channel)
        {
            IEncrypt encryption      = new EncryptionLogic(new Message(DependencyManager.Me.Id, message), channel.KeyTable);
            var      preparedMessage = encryption.Encrypt();
            IDecrypt decryption      = new DecryptionLogic(preparedMessage, channel.KeyTable);

            channel.View.ViewModel.Messages.Add(decryption.Decrypt());
            channel.Messages.Add(preparedMessage);
            DependencyManager.Database.InsertWithChildren(preparedMessage);
            DependencyManager.Database.UpdateWithChildren(channel);

            // TODO: Handle REST return
            new Task(() => { RestService.SendMessage(preparedMessage); }).Start();
            return(true);
            //return RestService.SendMessage(preparedMessage).Result;
        }