Esempio n. 1
0
        public FriendMessageList GetFriendsMessages(long accountId, long friendId)
        {
            var messages = new GetFriendMessagesQueryHandler(new DataBaseContext()).Handle(new GetFriendMessagesQuery
            {
                AccountId = accountId,
                FriendId  = friendId
            });

            return(new FriendMessageList
            {
                AccountId = accountId,
                FriendId = friendId,
                FriendMessages = messages.Select(data => new FriendMessage
                {
                    Id = data.Id,
                    Message = data.Message,
                    MessageDateTime = data.MessageDateTime,
                    MessageDirection = data.MessageDirection
                }).ToList()
            });
        }
Esempio n. 2
0
        public void SendMessageToUnanswered(AccountViewModel account, FriendData friend)
        {
            const string functionName = "Ответ на неотвеченные сообщения";

            if (friend.DialogIsCompleted || friend.Deleted)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Ошибка! Друг {0}({1}) удален, либо переписка с ним закончилась.", friend.FriendName, friend.FacebookId));
                return;
            }

            if (account.GroupSettingsId == null)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Ошибка! Не указана группа настроек."));
                return;
            }

            var friendIsBlocked = _friendsBlackListManager.CheckForFriendBlacklist(friend.FacebookId, (long)account.GroupSettingsId);

            if (friendIsBlocked)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Ошибка! Друг {0}({1}) находится в черном списке.", friend.FriendName, friend.FacebookId));
                return;
            }

            var allMessages = new GetFriendMessagesQueryHandler(new DataBaseContext()).Handle(new GetFriendMessagesQuery()
            {
                AccountId = account.Id,
                FriendId  = friend.Id
            });

            var lastBotMessages =
                allMessages.Where(data => data.MessageDirection == MessageDirection.ToFriend)
                .OrderByDescending(data => data.OrderNumber)
                .FirstOrDefault();

            if (lastBotMessages == null)
            {
                return;
            }

            _notice.AddNotice(functionName, account.Id, string.Format("Получаем экстра-сообщение"));

            var messageModel = _messageManager.GetRandomExtraMessage();

            if (messageModel == null)
            {
                return;
            }

            var message = new CalculateMessageTextQueryHandler(new DataBaseContext()).Handle(new CalculateMessageTextQuery
            {
                TextPattern = messageModel.Message,
                AccountId   = account.Id,
                FriendId    = friend.FacebookId
            });

            _notice.AddNotice(functionName, account.Id, string.Format("Отправляем экстра сообщение - '{0}'", message));

            var userAgent = new GetUserAgentQueryHandler(new DataBaseContext()).Handle(new GetUserAgentQuery
            {
                UserAgentId = account.UserAgentId
            });

            new SendMessageEngine().Execute(new SendMessageModel
            {
                AccountId     = account.FacebookId,
                Cookie        = account.Cookie,
                FriendId      = friend.FacebookId,
                Message       = message,
                Proxy         = _accountManager.GetAccountProxy(account),
                UrlParameters =
                    new GetUrlParametersQueryHandler(new DataBaseContext()).Handle(new GetUrlParametersQuery
                {
                    NameUrlParameter = NamesUrlParameter.SendMessage
                }),
                UserAgent = userAgent.UserAgentString
            });

            new SaveSentMessageCommandHandler(new DataBaseContext()).Handle(new SaveSentMessageCommand()
            {
                AccountId       = account.Id,
                FriendId        = friend.FacebookId,
                OrderNumber     = lastBotMessages.OrderNumber,
                Message         = message,
                MessageDateTime = DateTime.Now,
            });

            _notice.AddNotice(functionName, account.Id, string.Format("Отправка экстра сообщения завершена"));
        }