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);
        }