Example #1
0
        public override void Update(IActionContext context, ref ActionPresentation presentation)
        {
            base.Update(context, ref presentation);
            bool anyHasThreadHandler = false;

            for (int i = 0; i < context.SelectedResources.Count; i++)
            {
                string resType = context.SelectedResources [i].Type;
                IResourceThreadingHandler threadingHandler = Core.PluginLoader.GetResourceThreadingHandler(resType);
                if (threadingHandler != null)
                {
                    IResource threadRoot = ConversationBuilder.GetConversationRoot(context.SelectedResources [i]);
                    if (threadingHandler.CanExpandThread(threadRoot, ThreadExpandReason.Enumerate))
                    {
                        anyHasThreadHandler = true;
                        break;
                    }
                }
            }

            if (!anyHasThreadHandler)
            {
                if (context.Kind == ActionContextKind.MainMenu)
                {
                    presentation.Enabled = false;
                }
                else
                {
                    presentation.Visible = false;
                }
            }
        }
Example #2
0
        public static void Start(ConversationBuilder method)
        {
            Log.Debug($"{nameof(Start)} (enter)");

            if (!IsRunning)
            {
                SetConversationBuilder(method);
                ComService.SetIncomingMessageHandler(ProcessIncomingMessage);

                IsRunning = true;
                new Task(() =>
                {
                    var timeout = Config.GetInt(Config.DEFAULT_TIMEOUT);
                    while (IsRunning)
                    {
                        foreach (var conv in conversations.Values)
                        {
                            var timeSinceUpdate = (int)(DateTime.Now - conv.LastUpdateTime).TotalMilliseconds;
                            if (timeSinceUpdate > timeout)
                            {
                                conv.HandleTimeout();
                            }
                        }
                        Thread.Sleep(15);
                    }
                }).Start();
            }
            else
            {
                Log.Warn("ConversationManager already running. Did you try to start it more than once?");
            }

            Log.Debug($"{nameof(Start)} (exit)");
        }
Example #3
0
        public static void  PropagateFlag2Thread(IResource res)
        {
            ResourceFlag  currentFlag = ResourceFlag.GetResourceFlag(res);
            IResourceList subTree     = ConversationBuilder.UnrollConversationFromCurrent(res);

            Core.ResourceAP.QueueJob(new AssignFlagsDelegate(AssignFlags2List), currentFlag, subTree);
        }
Example #4
0
        private static void CheckArticleInSelfThread(IResource article)
        {
            IResource from = article.GetLinkProp(Core.ContactManager.Props.LinkFrom);

            if (from != null && from.HasProp(Core.ContactManager.Props.Myself))
            {
                article.SetProp(NntpPlugin._propIsSelfThread, true);
            }
            else
            {
                IResource root;
                bool      hasProp = ConversationBuilder.CheckPropOnParents(article,
                                                                           NntpPlugin._propIsSelfThread,
                                                                           out root);
                if (hasProp)
                {
                    article.SetProp(NntpPlugin._propIsSelfThread, true);

                    //  We have not only to set property for this article, but
                    //  also check downwards the thread because it is possible
                    //  for replies to be downloaded before the source article.

                    IResourceList thread = ConversationBuilder.UnrollConversation(article);
                    foreach (IResource res in thread)
                    {
                        res.SetProp(NntpPlugin._propIsSelfThread, true);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// When new article comes check whether it is linked to the thread
        /// which was paused for updates. In such case, simply delete the
        /// article (non-permanently, through registered IResourceDeleter).
        /// </summary>
        private static void CheckArticleInIgnoredThreads(IResource article)
        {
            IResource root;
            bool      ignore = ConversationBuilder.CheckPropOnParents(article,
                                                                      NntpPlugin._propIsIgnoredThread,
                                                                      out root);

            if (ignore)
            {
                //  We have not only to delete this article, but also check
                //  downwards the thread because it is possible for replies
                //  to be downloaded before the source article.

                IResourceDeleter deleter = Core.PluginLoader.GetResourceDeleter(article.Type);
                deleter.DeleteResource(article);

                DateTime      ignoreStartDate = root.GetDateProp(NntpPlugin._propThreadVisibilityToggleDate);
                IResourceList thread          = ConversationBuilder.UnrollConversation(article);
                foreach (IResource res in thread)
                {
                    DateTime dateTime = res.GetDateProp(Core.Props.Date);
                    if (!res.HasProp(Core.Props.IsDeleted) && dateTime > ignoreStartDate)
                    {
                        deleter.UndeleteResource(res);
                    }
                }
            }
        }
Example #6
0
        public bool DecorateNode(IResource res, RichText nodeText)
        {
            if (res.Type == NntpPlugin._newsGroup)
            {
                int count = 0;

                if (_groups2watchedHeads.ContainsKey(res))
                {
                    IResourceList groupItems = NntpPlugin.CollectArticles(res, false);
                    groupItems = groupItems.Intersect(_unreadArticles);

                    List <IResource> heads = _groups2watchedHeads[res];
                    foreach (IResource head in heads)
                    {
                        IResourceList thread = ConversationBuilder.UnrollConversationFromCurrent(head);
                        count += thread.Intersect(groupItems).Count;
                    }
                }

                if (count != 0)
                {
                    nodeText.Append(" !", _watchedTextStyle);
                }
                return(count != 0);
            }
            return(false);
        }
Example #7
0
        public void  PropagateUnreadState2Thread(IResource res, bool state)
        {
            IResourceList subTree = ConversationBuilder.UnrollConversationFromCurrent(res);

            subTree = subTree.Minus(res.ToResourceList());
            Core.ResourceAP.QueueJob(new AssignStatusDelegate(SetListUnreadState), state, subTree);
        }
Example #8
0
 private static void MarkConversationsRead(IResourceList selectedResources)
 {
     foreach (IResource res in selectedResources)
     {
         if (!res.IsDeleted)
         {
             ConversationBuilder.MarkConversationRead(res, true);
         }
     }
 }
Example #9
0
 private void _unreadArticles_Updated(object sender, ResourceIndexEventArgs e)
 {
     if (DecorationChanged != null)
     {
         foreach (IResource head in _heads)
         {
             if (ConversationBuilder.AreLinked(head, e.Resource))
             {
                 DecorationChanged(this, new ResourceEventArgs(e.Resource));
             }
         }
     }
 }
Example #10
0
 public static void SetConversationBuilder(ConversationBuilder method)
 {
     if (conversationBuilder?.GetInvocationList().Length > 0)
     {
         throw new Exception("ConversationFromMessageBuilder can only be set once.");
     }
     else if (method != null)
     {
         conversationBuilder = new ConversationBuilder(method);
     }
     else
     {
         Log.Warn($"SetConversationBuilder was given a null ConversationBuilder.");
     }
 }
Example #11
0
        public async Task <PagedList <Conversation> > GetConversations(GetConversationsPaginationRequest paginationRequest)
        {
            var sender = await profileService.GetCurrentUser();

            var senderFriends = sender.FriendsSent.Concat(sender.FriendsReceived);

            var conversations = sender.MessagesSent.Concat(sender.MessagesReceived)
                                .Where(m => string.IsNullOrEmpty(paginationRequest.Username) ? true
                    : (m.SenderId == sender.Id ? m.Recipient.Username.ToLower().Contains(paginationRequest.Username.ToLower())
                    : m.Sender.Username.ToLower().Contains(paginationRequest.Username.ToLower())))
                                .OrderByDescending(m => m.DateSent)
                                .GroupBy(m => new { m.SenderId, m.RecipientId })
                                .Select(g =>
            {
                var message = g.First();

                var conversation = new ConversationBuilder()
                                   .SentBy(message.SenderId)
                                   .SentTo(message.RecipientId)
                                   .SetLastMessage(new LastMessageBuilder()
                                                   .SetText(message.Text)
                                                   .SentBy(message.SenderId, message.Sender.Username, message.Sender.PhotoUrl)
                                                   .Sent(message.DateSent)
                                                   .MarkAsRead(message.IsRead)
                                                   .Build())
                                   .SetUserData(sender.Id == message.SenderId ? message.Recipient.Username : message.Sender.Username,
                                                sender.Id == message.SenderId ? message.Recipient.PhotoUrl : message.Sender.PhotoUrl)
                                   .Build();

                return(conversation);
            })
                                .Where(c => senderFriends.Any(f => (f.SenderAccepted && f.RecipientAccepted) && (f.SenderId == c.SenderId || f.SenderId == c.RecipientId) &&
                                                              (f.RecipientId == c.SenderId || f.RecipientId == c.RecipientId)))
                                .ToList();

            var uniqueConversations = new List <Conversation>();

            conversations.ForEach(c =>
            {
                if (uniqueConversations.Count == 0 || !uniqueConversations.Any(uc => (uc.SenderId == c.SenderId && uc.RecipientId == c.RecipientId) ||
                                                                               (uc.SenderId == c.RecipientId && uc.RecipientId == c.SenderId)))
                {
                    uniqueConversations.Add(c);
                }
            });

            return(uniqueConversations.ToPagedList <Conversation>(paginationRequest.PageNumber, paginationRequest.PageSize));
        }
Example #12
0
 protected override void OnModelCreating(ModelBuilder builder)
 {
     MessageBuilder.Build(builder);
     UserBuilder.Build(builder);
     ConversationBuilder.Build(builder);
     FriendsRequestBuilder.Build(builder);
     MessageBuilder.Build(builder);
     UserContactBuilder.Build(builder);
     ContactBuilder.Build(builder);
     NotificationBuilder.Build(builder);
     NotificationTypeBuilder.Build(builder);
     ParticipantBuilder.Build(builder);
     FileStorageBuilder.Build(builder);
     ReadReceiptBuilder.Build(builder);
     MemberBuilder.Build(builder);
 }
Example #13
0
        private string BuildResponse(string message)
        {
            string replyMessage        = Resources.en_us.resources.defaultMessage;
            var    conversationbuilder = new ConversationBuilder();

            try
            {
                if (conversationbuilder.Read(message) != string.Empty)
                {
                    replyMessage = conversationbuilder.Read(message);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            return(replyMessage);
        }
Example #14
0
            public async Task WhenTheTurnIdIsThesameAsTheCurentOne_ThenTheInnerHandlerIsNotCalled()
            {
                // arrange
                Conversation lastConversation = new ConversationBuilder()
                                                .WithId(_testOutgoingSms.Conversation.ConversationId)
                                                .WithTurnId(2);

                _testOutgoingSms.Conversation.TurnId = lastConversation.TurnId;

                var command = new SendSmsCommand(_testOutgoingSms, _testQueueMessage);

                _mockConversationRepository
                .Setup(m => m.Get(_testOutgoingSms.Conversation.ConversationId))
                .ReturnsAsync(lastConversation);

                // act
                await _sut.HandleAsync(command);

                //assert
                _mockHandler.Verify(m => m.HandleAsync(command, It.IsAny <CancellationToken>()), Times.Never);
            }
Example #15
0
            public void WhenTheTurnIdIsOutOfOrder_ThenAnOutOfOrderExceptionIscalled()
            {
                // arrange
                Conversation lastConversation = new ConversationBuilder()
                                                .WithId(_testOutgoingSms.Conversation.ConversationId)
                                                .WithTurnId(3);

                _testOutgoingSms.Conversation.TurnId = lastConversation.TurnId + 2;

                var command = new SendSmsCommand(_testOutgoingSms, _testQueueMessage);

                _mockConversationRepository
                .Setup(m => m.Get(_testOutgoingSms.Conversation.ConversationId))
                .ReturnsAsync(lastConversation);

                // act
                Func <Task> action = async() => await _sut.HandleAsync(command);

                //assert
                action.Should().ThrowExactly <OutOfOrderException>().WithMessage($"Message for conversation {_testOutgoingSms.Conversation.ConversationId} processed out of order.  Expected turnId {lastConversation.TurnId + 1} but received turnId {command.Message.Conversation.TurnId} with activityId {command.Message.Conversation.ActivityId}");
            }
Example #16
0
            public async Task WhenTheConversationHasAlreadyBeenStartedAndTheCommandIsInOrder_ThenTheInnerHandlerIsCalled()
            {
                // arrange
                Conversation lastConversation = new ConversationBuilder()
                                                .WithId(_testOutgoingSms.Conversation.ConversationId)
                                                .WithTurnId(2);

                _testOutgoingSms.Conversation.TurnId = lastConversation.TurnId + 1;

                var command = new SendSmsCommand(_testOutgoingSms, _testQueueMessage);

                _mockConversationRepository
                .Setup(m => m.Get(_testOutgoingSms.Conversation.ConversationId))
                .ReturnsAsync(lastConversation);

                // act
                await _sut.HandleAsync(command);

                //assert
                _mockHandler.Verify(m => m.HandleAsync(command, It.IsAny <CancellationToken>()), Times.Once);
            }
Example #17
0
            public void WhenTheTurnIdIsOutOfOrder_ThenTheInnerHandlerIsNotCalled()
            {
                // arrange
                Conversation lastConversation = new ConversationBuilder()
                                                .WithId(_testOutgoingSms.Conversation.ConversationId)
                                                .WithTurnId(3);

                _testOutgoingSms.Conversation.TurnId = lastConversation.TurnId + 2;

                var command = new SendSmsCommand(_testOutgoingSms, _testQueueMessage);

                _mockConversationRepository
                .Setup(m => m.Get(_testOutgoingSms.Conversation.ConversationId))
                .ReturnsAsync(lastConversation);

                // act
                Func <Task> action = async() => await _sut.HandleAsync(command);

                action.Invoke();

                //assert
                _mockHandler.Verify(m => m.HandleAsync(It.IsAny <SendSmsCommand>(), It.IsAny <CancellationToken>()), Times.Never);
            }