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; } } }
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)"); }
public static void PropagateFlag2Thread(IResource res) { ResourceFlag currentFlag = ResourceFlag.GetResourceFlag(res); IResourceList subTree = ConversationBuilder.UnrollConversationFromCurrent(res); Core.ResourceAP.QueueJob(new AssignFlagsDelegate(AssignFlags2List), currentFlag, subTree); }
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); } } } }
/// <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); } } } }
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); }
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); }
private static void MarkConversationsRead(IResourceList selectedResources) { foreach (IResource res in selectedResources) { if (!res.IsDeleted) { ConversationBuilder.MarkConversationRead(res, true); } } }
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)); } } } }
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."); } }
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)); }
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); }
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); }
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); }
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}"); }
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); }
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); }