Beispiel #1
0
        public bool UpdateThreadCounters(string business_id, Thread thread)
        {
            var counter = new Counter {
                id = thread.id, count = 1
            };

            _counterRepository.AddThreadToChannels(business_id, thread.channel_id, counter);
            if (!string.IsNullOrWhiteSpace(thread.agent_id))
            {
                _counterRepository.AddThreadToAgents(business_id, thread.agent_id, counter);
            }
            if (thread.unread)
            {
                _counterRepository.AddThreadToChannelsUnread(business_id, thread.channel_id, counter);
                if (string.IsNullOrWhiteSpace(thread.agent_id))
                {
                    _counterRepository.AddThreadToChannelsUnassignedUnread(business_id, thread.channel_id, counter);
                }
                else
                {
                    _counterRepository.AddTheadToAgentsUnread(business_id, thread.agent_id, counter);
                }
            }
            else
            {
                try
                {
                    _counterRepository.DeleteThreadFromChannelsUnread(business_id, thread.channel_id, counter.id);
                }
                catch { }
                if (string.IsNullOrWhiteSpace(thread.agent_id))
                {
                    try
                    {
                        _counterRepository.DeleteThreadFromChannelsUnassignedUnread(business_id, thread.channel_id, counter.id);
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        _counterRepository.DeleteThreadFromAgentsUnread(business_id, thread.agent_id, counter.id);
                    }
                    catch { }
                }
            }

            return(true);
        }
Beispiel #2
0
        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 bool SendMessageToThreadWithCountersUpdate(string business_id, MessageModel message, Thread thread)
        {
            //_messageRepository.Add(message);
            _messageRepository.Upsert(business_id, message);
            _messageRepository.AddGroupedByThread(business_id, message, thread.id);
            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);
        }
Beispiel #4
0
        public Thread MarkAsUnRead(string business_id, string thread_id, string agent_id)
        {
            var thread = GetById(business_id, thread_id);

            business_id = thread.business_id;
            string channel_id      = thread.channel_id;
            var    previous_unread = thread.unread;

            if (previous_unread)
            {
                return(null);
            }
            if (!thread.unread)
            {
                thread.unread  = true;
                thread.read_at = 0;
                thread.read_by = null;
                CreateThread(thread, true);

                //update counters
                var counter = new Counter {
                    id = thread_id, count = 1
                };
                if (!string.IsNullOrWhiteSpace(agent_id))
                {
                    //AssignToAgent(business_id, thread_id, agent_id);
                    try
                    {
                        _counterRepository.AddTheadToAgentsUnread(business_id, agent_id, counter);
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        _counterRepository.AddThreadToChannelsUnassignedUnread(business_id, thread.channel_id, counter);
                    }
                    catch { }
                }
                try
                {
                    _counterRepository.AddThreadToChannelsUnread(business_id, thread.channel_id, counter);
                }
                catch { }
            }
            return(thread);
        }