public bool AssignToAgent(string business_id, string thread_id, string agent_id) { var thread = UnAssignFromAgent(business_id, thread_id); var agent = !string.IsNullOrWhiteSpace(agent_id) ? _agentService.GetById(business_id, agent_id) : null; if (agent == null) { return(false); } thread = GetById(business_id, thread_id); business_id = thread.business_id; var oldAgentId = thread.agent_id; thread.agent_id = agent_id; thread.status = "active"; CreateThread(thread, true); var counter = new Counter { id = thread_id, count = 1 }; _counterRepository.AddThreadToAgents(business_id, agent_id, counter); if (thread.unread) { _counterRepository.AddTheadToAgentsUnread(business_id, agent_id, counter); } ; return(true); }
public bool AssignMessageToAgent(string business_id, MessageModel message, string agentId) { _messageRepository.AddGroupedByUser(business_id, message, agentId); if (message.sender_id != message.channel_id && message.sender_id != message.agent_id && !string.IsNullOrWhiteSpace(agentId) && agentId != "ALL") { var counter = new Counter { id = message.sender_id, count = 1 }; _counterRepository.AddThreadToAgents(business_id, agentId, counter); _counterRepository.AddTheadToAgentsUnread(business_id, agentId, counter); } return(true); }
public bool SendMessageToThreadWithCountersUpdate(string business_id, Message message, Thread thread) { message.thread_id = thread.id; _messageRepository.Upsert(message); BackgroundJob.Enqueue <MessageService>(x => x.CopyMessageToRealtimeDB(business_id, message.id, message.timestamp)); var counter = new Counter { id = thread.id, count = 1 }; _counterRepository.AddThreadToChannels(business_id, message.channel_id, counter); if (!string.IsNullOrWhiteSpace(thread.agent_id)) { _counterRepository.AddThreadToAgents(business_id, thread.agent_id, counter); } if (thread.unread) { _counterRepository.AddThreadToChannelsUnread(business_id, message.channel_id, counter); if (string.IsNullOrWhiteSpace(thread.agent_id)) { _counterRepository.AddThreadToChannelsUnassignedUnread(business_id, message.channel_id, counter); } else { _counterRepository.AddTheadToAgentsUnread(business_id, thread.agent_id, counter); } } else { try { _counterRepository.DeleteThreadFromChannelsUnread(business_id, message.channel_id, counter.id); } catch { } if (string.IsNullOrWhiteSpace(thread.agent_id)) { try { _counterRepository.DeleteThreadFromChannelsUnassignedUnread(business_id, message.channel_id, counter.id); } catch { } } else { try { _counterRepository.DeleteThreadFromAgentsUnread(business_id, thread.agent_id, counter.id); } catch { } } } return(true); }
public void AddSingleUnreadThreadToAgent(string business_id, string agent_id, string thread_id) { _counterRepository.AddTheadToAgentsUnread(business_id, agent_id, new Counter { id = thread_id, count = 1 }); }