Esempio n. 1
0
        public Message ReplyTwitterTweetMessage(int conversationId, int twitterAccountId, string content, bool isCloseConversation = false)
        {
            var          twitterService = DependencyResolver.Resolve <ITwitterService>();
            Conversation conversation   = _conversationService.CheckIfExists(conversationId);

            if (conversation.Source != ConversationSource.TwitterTweet)
            {
                throw SocialExceptions.BadRequest("Conversation source must be twitter tweet.");
            }

            SocialAccount twitterAccount = _socialAccountService.FindAllWithDeleted().FirstOrDefault(t => t.Id == twitterAccountId);

            if (twitterAccount != null && twitterAccount.IsDeleted)
            {
                twitterAccount = _socialAccountService.FindAll().FirstOrDefault(t => t.SocialUser.OriginalId == twitterAccount.SocialUser.OriginalId);
            }
            if (twitterAccount == null)
            {
                throw SocialExceptions.BadRequest("Twitter account has been deleted.");
            }

            var     messages         = Repository.FindAll().Include(t => t.Sender).Include(t => t.Receiver).Where(t => t.ConversationId == conversation.Id).ToList();
            var     previousMessages = messages.Where(t => t.SenderId != twitterAccountId).OrderByDescending(t => t.SendTime);
            Message replyMessage     = null;

            foreach (var previousMessage in previousMessages)
            {
                if (previousMessage.IsDeleted)
                {
                    continue;
                }
                //if (previousMessage.Sender.Type == SocialUserType.IntegrationAccount)
                //{
                //    continue;
                //}

                ITweet previousTweet = twitterService.GetTweet(twitterAccount, long.Parse(previousMessage.OriginalId));
                if (previousTweet != null && !previousTweet.IsTweetDestroyed)
                {
                    // publish tweet
                    if (!content.Contains("@" + previousTweet.CreatedBy.ScreenName))
                    {
                        content = "@" + previousTweet.CreatedBy.ScreenName + " " + content;
                    }
                    var replyTweet = twitterService.ReplyTweet(twitterAccount, previousTweet, content);
                    if (replyTweet == null)
                    {
                        continue;
                    }

                    // add message
                    replyMessage = TwitterConverter.ConvertToMessage(replyTweet);
                    replyMessage.ConversationId = conversation.Id;
                    replyMessage.SenderId       = twitterAccount.Id;
                    replyMessage.SendAgentId    = UserContext.UserId;
                    replyMessage.ReceiverId     = previousMessage.Sender.Id;

                    Save(replyMessage, isCloseConversation);

                    break;
                }
            }

            if (replyMessage == null)
            {
                throw SocialExceptions.OriginalPostOrTweetHasBeenDeleted();
            }

            return(this.Find(replyMessage.Id));
        }
Esempio n. 2
0
 public IList <TwitterAccountListDto> GetAccounts()
 {
     return(_socialAccountService.FindAll().Where(t => t.SocialUser.Type == SocialUserType.IntegrationAccount && t.SocialUser.Source == SocialUserSource.Twitter).ProjectTo <TwitterAccountListDto>().ToList());
 }
Esempio n. 3
0
 public IList <FacebookPageListDto> GetPages()
 {
     return(_socialAccountService.FindAll()
            .Where(t => t.SocialUser.Type == SocialUserType.IntegrationAccount && t.SocialUser.Source == SocialUserSource.Facebook)
            .ProjectTo <FacebookPageListDto>().ToList());
 }