public void BeginDirectMessages_WithCustomParameters_SetsAllParameters()
        {
            // arrange
            const int sinceId = 1234;
            const int maxId = 5678;
            const int count = 10;
            const int page = 1;
            const bool trimUser = true;
            const bool includeEntities = true;

            var twitterClient = Substitute.For<IBaseTwitterClient>();
            twitterClient.When(a => a.BeginRequest(Arg.Any<string>(), Arg.Any<IDictionary<string, string>>(), Arg.Any<WebMethod>(), Arg.Any<RestCallback>()))
                         .Do(c =>
                         {
                             c.AssertParameter("trim_user", trimUser);
                             c.AssertParameter("include_entities", includeEntities);
                             c.AssertParameter("since_id", sinceId);
                             c.AssertParameter("max_id", maxId);
                             c.AssertParameter("count", count);
                             c.AssertParameter("page", page);
                         });
            var statuses = new DirectMessages(twitterClient);

            // act
            statuses.BeginDirectMessages(sinceId, maxId, count, page, trimUser, includeEntities, (a, b, c) => { });
        }
Esempio n. 2
0
        public TwitterClient(IRestClient client, string consumerKey, string consumerSecret, string callback)
            : base(client)
        {
            Encode = true;
            Statuses = new Statuses(this);
            Account = new Account(this);
            DirectMessages = new DirectMessages(this);
            Favourites = new Favourites(this);
            Block = new Block(this);
            Friendships = new Friendship(this);
            Lists = new List(this);
            Search = new Search(this);
            Users = new Users(this);
            FriendsAndFollowers = new FriendsAndFollowers(this);

            OAuthBase = "https://api.twitter.com/oauth/";
            TokenRequestUrl = "request_token";
            TokenAuthUrl = "authorize";
            TokenAccessUrl = "access_token";
            Authority = "https://api.twitter.com/";
            Version = "1";

#if !SILVERLIGHT
            ServicePointManager.Expect100Continue = false;
#endif
            Credentials = new OAuthCredentials
            {
                ConsumerKey = consumerKey,
                ConsumerSecret = consumerSecret,
            };

            if (!string.IsNullOrEmpty(callback))
                ((OAuthCredentials)Credentials).CallbackUrl = callback;
        }
Esempio n. 3
0
 /// <summary>
 /// スタックをクリアする
 /// </summary>
 public static void Clear()
 {
     if (DirectMessages != null)
     {
         DirectMessages.Clear();
     }
 }
        private void RefreshWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // retrieve id argument
            string id = e.Argument as string;

            // call twitter api
            TwitterClient  client         = new TwitterClient(_username, _password);
            DirectMessages directMessages = null;

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    directMessages = client.DirectMessages();
                }
                else
                {
                    directMessages = client.DirectMessages(id);
                }
                client.Close();
                e.Result = new DirectMessagesResult {
                    Id = id, DirectMessages = directMessages
                };
            }
            finally
            {
                client.Abort();
            }
        }
Esempio n. 5
0
        public void OnDirectMessageUpdate(object sender, PropertyChangedEventArgs e)
        {
            var dm  = kbtter.LatestDirectMessage.DirectMessage;
            var dml = DirectMessages.FirstOrDefault(p => p.CheckUserPair(dm.Recipient.ScreenName, dm.Sender.ScreenName));

            if (dml == null)
            {
                var  nd = new DirectMessageViewModel(this, kbtter.AuthenticatedUser.ScreenName);
                User tus;
                if (dm.Recipient.Id == kbtter.AuthenticatedUser.Id)
                {
                    tus = dm.Sender;
                }
                else
                {
                    tus = dm.Recipient;
                }
                nd.TargetUserName       = tus.Name;
                nd.TargetUserScreenName = tus.ScreenName;
                nd.TargetUserImageUri   = tus.ProfileImageUrlHttps;
                DirectMessages.Add(nd);
                dml = nd;
            }
            dml.AddMessage(dm);
            RaisePropertyChanged("DirectMessage");
        }
Esempio n. 6
0
        public async void AddDirectMessageTarget()
        {
            try
            {
                var fs = await kbtter.Token.Friendships.ShowAsync(source_id => kbtter.AuthenticatedUser.ScreenName, target_screen_name => NewDirectMessageTargetScreenName);

                if (!fs.Target.CanDM ?? false)
                {
                    NotifyInformation("そのユーザーにはダイレクトメッセージを送れません");
                    return;
                }
                else
                {
                    var user = await kbtter.Token.Users.ShowAsync(screen_name => NewDirectMessageTargetScreenName);

                    var dmvm = new DirectMessageViewModel(this, kbtter.AuthenticatedUser.ScreenName);
                    dmvm.TargetUserName       = user.Name;
                    dmvm.TargetUserScreenName = user.ScreenName;
                    dmvm.TargetUserImageUri   = user.ProfileImageUrlHttps;
                    DirectMessages.Add(dmvm);
                }
            }
            catch (TwitterException e)
            {
                NotifyInformation(string.Format("ユーザー情報の取得に失敗しました : {0}", e.Message));
            }
            catch
            { }
        }
Esempio n. 7
0
        public IdenticaClient(string username, string password)
        {
            Statuses = new Statuses(this);
            Account = new Account(this);
            DirectMessages = new DirectMessages(this);
            Favourites = new Favourites(this);
            Block = new Block(this);
            Friendships = new Friendship(this);
            Lists = new List(this);
            Search = new Search(this);
            Users = new Users(this);
            FriendsAndFollowers = new FriendsAndFollowers(this);

            Credentials = new BasicAuthCredentials
            {
                Username = username,
                Password = password
            };

            Client = new RestClient
                         {
                             Authority = "http://identi.ca/api",

                         };            
            
            Authority = "http://identi.ca/api";

            Encode = false;
        }
Esempio n. 8
0
 /// <summary>
 /// ダイレクトメッセージをスタックに積む
 /// </summary>
 /// <param name="user">送ってきたユーザー</param>
 /// <param name="message">送られてきたダイレクトメッセージ</param>
 public static void StackMention(User user, CoreTweet.DirectMessage message)
 {
     if (DirectMessages == null)
     {
         DirectMessages = new ObservableCollection <DirectMessage>();
         BindingOperations.EnableCollectionSynchronization(DirectMessages, new object());
     }
     DirectMessages.Add(new DirectMessage()
     {
         User    = new UserOverviewProperties(user),
         Message = message
     });
 }
Esempio n. 9
0
        public ResponseVM PostDirectMessages(DirectMessageVM obj)
        {
            Conversations conversation = db.Conversations.Find(obj.conversationID);

            if (conversation == null)
            {
                return new ResponseVM
                       {
                           responseCode    = 404,
                           responseMessage = "Not found."
                       }
            }
            ;

            int receiverID = conversation.User1ID;

            if (obj.senderID == conversation.User1ID)
            {
                receiverID = conversation.User2ID;
            }

            DirectMessages directMessage = new DirectMessages()
            {
                ConversationID = obj.conversationID,
                SenderID       = obj.senderID,
                ReceiverID     = receiverID,
                Content        = obj.content,
                DateCreated    = DateTime.Now
            };

            try
            {
                db.DirectMessages.Add(directMessage);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(new ResponseVM
                {
                    responseCode = 400,
                    responseMessage = "An error occured."
                });
            }

            return(new ResponseVM
            {
                responseCode = 200,
                responseMessage = "Direct message posted successfully"
            });
        }
    }
        public void BeginDirectMessages_ForAllScenarios_SetsParameter()
        {
            // arrange
            var twitterClient = Substitute.For<IBaseTwitterClient>();
            twitterClient.When(a => a.BeginRequest(Arg.Any<string>(), Arg.Any<IDictionary<string, string>>(), Arg.Any<WebMethod>(), Arg.Any<RestCallback>()))
                         .Do(c =>
                         {
                             c.AssertParameter("trim_user", false);
                             c.AssertParameter("include_entities", false);
                         });
            var statuses = new DirectMessages(twitterClient);

            // act
            statuses.BeginDirectMessages((a, b, c) => { });
        }
        public async Task SaveMessage(User sender, int receiverId, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            var directMessage = new DirectMessages()
            {
                SenderId    = sender.Id,
                ReceiverId  = receiverId,
                Message     = message,
                CreatedDate = DateTime.UtcNow
            };

            _context.DirrectMessages.Add(directMessage);
            await _context.SaveChangesAsync();
        }
Esempio n. 12
0
        ChannelViewModel GetChannelByID(string id)
        {
            ChannelViewModel channel = PublicChannels.FirstOrDefault(c => c.ID == id);

            if (channel != null)
            {
                return(channel);
            }

            channel = PrivateGroups.FirstOrDefault(c => c.ID == id);

            if (channel != null)
            {
                return(channel);
            }

            return(DirectMessages.FirstOrDefault(c => c.ID == id));
        }
        public void BeginDirectMessages_ForAllScenarios_ReturnsListOfMessages()
        {
            // arrange
            var wasCalled = false;
            var twitterClient = Substitute.For<IBaseTwitterClient>();
            twitterClient.SetReponseBasedOnRequestPath();
            var directMessages = new DirectMessages(twitterClient);

            // assert
            GenericResponseDelegate endCreate = (a, b, c) =>
            {
                wasCalled = true;
                var results = c as IEnumerable<DirectMessage>;
                Assert.That(results, Is.Not.Null);
                Assert.That(results, Is.Not.Empty);
            };

            // act
            directMessages.BeginDirectMessages(endCreate);

            Assert.That(wasCalled, Errors.CallbackDidNotFire);
        }
 public void Refresh()
 {
     try
     {
         // if local tweet count is 0, get all tweets from server
         // otherwise, get tweets since the latest one
         if (0 == _tweets.Count)
         {
             RefreshAll();
         }
         else
         {
             // update tweets collection
             DirectMessage  newestDirectMessage = _tweets.GetNewest();
             DirectMessages newDirectMessages   = _twitterApiClient.DirectMessages(newestDirectMessage.Id);
             _tweets.Add(newDirectMessages);
         }
     }
     catch (Exception ex)
     {
         // TODO: notify UI layer refresh lite failed
     }
 }
Esempio n. 15
0
        public ActionResult Outbox()
        {
            var model = new DirectMessages();

            if (_mu != null)
                ViewBag.RecordCount = model.GetMailPageWiseFromUser(1, PageSize, Convert.ToInt32(_mu.ProviderUserKey));

            model.AllInInbox = false;

            ViewBag.DirectMessages = model.ToUnorderdList;

            return View();
        }
Esempio n. 16
0
        void Process(string Line)
        {
            if (Line.StartsWith("PING "))
            {
                String payload = "PONG " + Line.Substring(5);
                SendData(payload);
                return; // no further processing required
            }
            Match NumCommand  = ServerMessageRegex.Match(Line);
            Match TextCommand = CommandRegex.Match(Line);

            if (NumCommand.Success)
            {
                //Console.WriteLine ("Server Message: " + Line);
                StatusCode status = (StatusCode)Convert.ToInt32(NumCommand.Groups[2].Value);
                Match      R;
                switch (status)
                {
                case StatusCode.Welcome:
                    Had001.Set(true);
                    break;

                case StatusCode.Motd:
                    Console.WriteLine(NumCommand.Groups[4].Value);
                    //add to motd string
                    break;

                case StatusCode.NicknameInUse:
                    Configuration.Nick += "_";
                    Console.WriteLine("Nick Was In Use, Using {0}", Configuration.Nick);
                    SendData(string.Format("NICK {0}", Configuration.Nick));
                    break;

                case StatusCode.TooManyChannels:
                case StatusCode.ChannelIsFull:
                case StatusCode.UnknownMode:
                case StatusCode.InviteOnlyChannel:
                case StatusCode.BannedFromChannel:
                case StatusCode.BadChannelKey:
                case StatusCode.NoPrivileges:
                    String channel = Regex.Match(NumCommand.Groups[4].Value, @"([#0-9A-Za-z_\-\[\]\{\}\\`\|]+) :.+").Groups[1].Value;
                    if (Channels.ContainsKey(channel))
                    {
                        Channels[channel].Response = status;
                    }
                    break;

                case StatusCode.EndOfNames:

                    R = Regex.Match(NumCommand.Groups[4].Value, @"([#0-9A-Za-z_\-\[\]\{\}\\`\|\+]+) :(.+)");
                    if (Channels.ContainsKey(R.Groups[1].Value))
                    {
                        Channels[R.Groups[1].Value].EndOfNames = true;
                    }
                    break;

                case StatusCode.NamReply:

                    R = Regex.Match(NumCommand.Groups[4].Value, @". ([#0-9A-Za-z_\-\[\]\{\}\\`\|\+]+) :(.+)");
                    if (Channels.ContainsKey(R.Groups[1].Value))
                    {
                        if (Channels[R.Groups[1].Value].EndOfNames)
                        {
                            Channels[R.Groups[1].Value].EndOfNames = false;
                            Channels[R.Groups[1].Value].Inside_Users.Clear();
                        }
                        foreach (String name in R.Groups[2].Value.Split(null))
                        {
                            Channels[R.Groups[1].Value].Inside_Users.Add(name);
                        }
                    }
                    break;

                default:
                    Console.WriteLine("{0}: {1}", status.ToString(), NumCommand.Groups[4].Value);
                    break;
                }
            }
            else if (TextCommand.Success)
            {
                try {
                    Command c = (Command)Enum.Parse(typeof(Command), TextCommand.Groups[4].Value);
                    switch (c)
                    {
                    case Command.JOIN:
                        String ChannelName = TextCommand.Groups[5].Value;
                        if (ChannelName.StartsWith(":"))
                        {
                            ChannelName = ChannelName.Substring(1);
                        }
                        if (TextCommand.Groups[1].Value == Configuration.Nick)
                        {
                            Channels[ChannelName].Response = StatusCode.JOIN;
                        }
                        else
                        {
                            Console.WriteLine(TextCommand.Groups[1].Value);
                        }
                        SendData(String.Format("NAMES {0}", ChannelName));
                        break;

                    case Command.PRIVMSG:
                        Match Priv = Regex.Match(TextCommand.Groups[5].Value, @"(\S+) :(.+)");
                        if (Priv.Groups[1].Value.StartsWith("#"))        // Channel
                        {
                            Message message = new Message(TextCommand.Groups[1].Value, Priv.Groups[2].Value);
                            Channels[Priv.Groups[1].Value].MessageQueue.ExecuteFunction(q => { q.Enqueue(message); return(0); });
                        }
                        else                 // DM
                        {
                            DirectMessages.ExecuteFunction(x => {
                                if (!x.ContainsKey(TextCommand.Groups[1].Value))
                                {
                                    x[TextCommand.Groups[1].Value] = new Queue <string> ();
                                }
                                Console.WriteLine(TextCommand.Groups[1].Value);
                                x[TextCommand.Groups[1].Value].Enqueue(Priv.Groups[2].Value);
                                return(0);
                            });
                        }
                        break;

                    default:
                        Console.WriteLine("Unhandled {0} Command", TextCommand.Groups[4].Value);
                        break;
                    }
                } catch (ArgumentException) {
                    Console.WriteLine("Unrecognised {0} Command", TextCommand.Groups[4].Value);
                }
            }
            else
            {
                Console.WriteLine("Unknown Message Type: " + Line);
            }
        }
        public void BeginCreate_ForAllScenarios_SetsParameter()
        {
            // arrange
            var screenName = "abcde";
            var text = "defgh";
            var twitterClient = Substitute.For<IBaseTwitterClient>();
            twitterClient.When(a => a.BeginRequest(Arg.Any<string>(), Arg.Any<IDictionary<string, string>>(), Arg.Any<WebMethod>(), Arg.Any<RestCallback>()))
                         .Do(c =>
                         {
                             c.AssertParameter("screen_name", screenName);
                             c.AssertParameter("text", text);
                         });
            var statuses = new DirectMessages(twitterClient);

            // act
            statuses.BeginCreate(screenName, text, (a, b, c) => { });
        }
        public void BeginCreate_ForAllScenarios_ReturnsNewMessage()
        {
            // arrange
            var wasCalled = false;
            var twitterClient = Substitute.For<IBaseTwitterClient>();
            twitterClient.SetReponseBasedOnRequestPath();
            var directMessages = new DirectMessages(twitterClient);

            GenericResponseDelegate endCreate = (a, b, c) =>
            {
                wasCalled = true;
                var results = c as DirectMessage;
                Assert.That(results, Is.Not.Null);
            };

            // act
            directMessages.BeginCreate("abcde", "foo", endCreate);

            Assert.That(wasCalled, Errors.CallbackDidNotFire);
        }
Esempio n. 19
0
        private static void UpdateReadMessages(DirectMessages model, int currentUserId)
        {
            foreach (var item in model)
            {
                if (item.IsRead) continue;
                if (item.ToUserAccountID != currentUserId) continue;

                item.IsRead = true;
                item.Update();
            }
        }
Esempio n. 20
0
        public JsonResult ReplyMailItems(string userName, int pageNumber)
        {
            var ua = new UserAccount(userName);
            var currentUserId = Convert.ToInt32(_mu.ProviderUserKey);
            var model = new DirectMessages();

            if (_mu != null)
                model.GetMailPageWiseToUser(pageNumber, PageSize,
                    currentUserId, ua.UserAccountID);

            var sb = new StringBuilder();

            foreach (DirectMessage cnt in model)
            {
                sb.Append(cnt.ToUnorderdListItem);
            }

            UpdateReadMessages(model, currentUserId);

            return Json(new
            {
                ListItems = sb.ToString()
            },
            JsonRequestBehavior.AllowGet);
        }
Esempio n. 21
0
        public ActionResult Reply(string userName)
        {
            _ua = new UserAccount(userName);

            ViewBag.DisplayName = _ua.UserName;

            var model = new DirectMessages();
            var currentUserId = Convert.ToInt32(_mu.ProviderUserKey);

            if (_mu != null)
                ViewBag.RecordCount = model.GetMailPageWiseToUser(1,
                    PageSize,
                    currentUserId,
                    _ua.UserAccountID);

            ViewBag.DirectMessages = model.ToUnorderdList;

            UpdateReadMessages(model, currentUserId);

            return View();
        }
Esempio n. 22
0
        public JsonResult OutboxMailItems(int pageNumber)
        {
            var model = new DirectMessages();

            if (_mu != null) model.GetMailPageWiseFromUser(pageNumber, PageSize, Convert.ToInt32(_mu.ProviderUserKey));

            model.AllInInbox = false;

            return Json(new
            {
                ListItems = model.ToUnorderdList
            });
        }