Esempio n. 1
0
        async Task ProcessMessage(ChatMessage message)
        {
            message.IsSender = message.Sender.TronAddress == _walletManager.Wallet.Address;
            message.Decrypt(_walletManager.Wallet, Chat.ChatPartner.PublicKey);

            for (var i = Messages.Count - 1; i >= 0; i--)
            {
                var msg = Messages[i];
                if (message.ExtendedMessage?.PendingID == msg.ExtendedMessage?.PendingID && msg.ExtendedMessage.IsPending)
                {
                    try
                    {
                        if (Messages.Remove(msg))
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }
            }


            Messages.Add(message);

            if (message.IsSender && message.ExtendedMessage != null)
            {
                // try deleting from table
                await _database.PendingMessages.Delete(Chat.ID, message.ExtendedMessage.PendingID);

                // delete from messages list

                /*var moved = 0;
                 * for (var i = 0; i < Messages.Count - moved; i++)
                 * {
                 *  if (Messages[i].ExtendedMessage?.IsPending == true)
                 *  {
                 *      moved++;
                 *      Messages.Move(i, Messages.Count - 1);
                 *  }
                 * }*/
            }
        }