コード例 #1
0
        public async Task UIHandleIncomingMessage(SignalMessage message)
        {
            Debug.WriteLine("incoming lock await");
            using (await ActionInProgress.LockAsync())
            {
                Debug.WriteLine("incoming lock grabbed");
                var  thread      = ThreadsDictionary[message.ThreadId];
                uint unreadCount = thread.UnreadCount;
                if (SelectedThread == thread)
                {
                    message.Read = true;
                }
                await Task.Run(() =>
                {
                    SignalDBContext.SaveMessageLocked(message);
                });

                thread.MessagesCount += 1;
                if (SelectedThread == thread)
                {
                    var container = new SignalMessageContainer(message, (int)thread.MessagesCount - 1);
                    View.Thread.Append(container, false);
                    if (message.Direction == SignalMessageDirection.Synced)
                    {
                        View.Thread.AddToOutgoingMessagesCache(container);
                        unreadCount = 0;
                        thread.LastSeenMessageIndex = thread.MessagesCount;
                    }
                    else
                    {
                        //TODO don't increase unread if we did scroll automatically, and mark the message as seen
                        unreadCount++;
                    }
                }
                else
                {
                    if (message.Direction == SignalMessageDirection.Incoming)
                    {
                        unreadCount++;
                    }
                    else if (message.Direction == SignalMessageDirection.Synced)
                    {
                        unreadCount = 0;
                        thread.LastSeenMessageIndex = thread.MessagesCount;
                    }
                }
                thread.UnreadCount         = unreadCount;
                thread.LastActiveTimestamp = message.ReceivedTimestamp;
                thread.LastMessage         = message;
                thread.View.UpdateConversationDisplay(thread);
                MoveThreadToTop(thread);
            }
            Debug.WriteLine("incoming lock released");
        }
コード例 #2
0
 public async Task UIHandleIdentityKeyChange(string number)
 {
     Debug.WriteLine("IKChange lock await");
     using (await ActionInProgress.LockAsync())
     {
         Debug.WriteLine("IKChange lock grabbed");
         var messages = SignalDBContext.InsertIdentityChangedMessages(number);
         foreach (var message in messages)
         {
             var thread = ThreadsDictionary[message.ThreadId];
             thread.MessagesCount += 1;
             if (SelectedThread != null && SelectedThread.ThreadId == message.ThreadId)
             {
                 var container = new SignalMessageContainer(message, (int)thread.MessagesCount - 1);
                 View.Thread.Append(container, false);
             }
             thread.LastMessage = message;
             thread.View.UpdateConversationDisplay(thread);
         }
     }
     Debug.WriteLine("IKChange lock released");
 }
コード例 #3
0
        private async Task <bool> SendMessage(string messageText)
        {
            Debug.WriteLine("starting sendmessage");
            try
            {
                if (messageText != string.Empty)
                {
                    var           now     = Util.CurrentTimeMillis();
                    SignalMessage message = new SignalMessage()
                    {
                        Author            = null,
                        ComposedTimestamp = now,
                        Content           = new SignalMessageContent()
                        {
                            Content = messageText
                        },
                        ThreadId          = SelectedThread.ThreadId,
                        ReceivedTimestamp = now,
                        Direction         = SignalMessageDirection.Outgoing,
                        Read = true,
                        Type = SignalMessageType.Normal
                    };
                    Debug.WriteLine("keydown lock await");
                    using (await ActionInProgress.LockAsync())
                    {
                        Debug.WriteLine("keydown lock grabbed");

                        /* update in-memory data */
                        SelectedThread.MessagesCount       += 1;
                        SelectedThread.UnreadCount          = 0;
                        SelectedThread.LastMessage          = message;
                        SelectedThread.LastSeenMessageIndex = SelectedThread.MessagesCount;
                        SelectedThread.View.UpdateConversationDisplay(SelectedThread);
                        var container = new SignalMessageContainer(message, (int)SelectedThread.MessagesCount - 1);
                        View.Thread.Append(container, true);
                        MoveThreadToTop(SelectedThread);

                        /* save to disk */
                        await Task.Run(() =>
                        {
                            SignalDBContext.SaveMessageLocked(message);
                        });

                        /* add to OutgoingCache */
                        View.Thread.AddToOutgoingMessagesCache(container);

                        /* send */
                        OutgoingQueue.Add(message);
                    }
                    Debug.WriteLine("keydown lock released");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                return(false);
            }
        }