Example #1
0
 /// <summary>
 /// Binds the data.
 /// </summary>
 private void BindData()
 {
     Entities = localSql.GetReverseEntities();
     Statuses = localSql.GetReverseStatuses();
     Statuses.Insert(0, new IntegerComboBoxModel {
         Name = "All", Value = 0
     });
 }
Example #2
0
        private void OnStatus(object sender, PropertyChangedEventArgs e)
        {
            var st = kbtter.LatestStatus;

            Query.ClearVariables();
            Query.SetVariable("Status", st.Status);
            var ret = Query.Execute();

            if (ret)
            {
                main.NotifyInformation("合致");
                Statuses.Insert(0, StatusViewModelExtension.CreateStatusViewModel(main, st.Status));
            }
        }
Example #3
0
        public void EditStatuses(Statuses statuses)
        {
            var book = Statuses.Where(b => b.Id == statuses.Id).FirstOrDefault();

            if (book == null)
            {
                if (position == 0 || position == 2)
                {
                    Statuses.Insert(0, statuses);
                }
            }
            else
            {
                var index = Statuses.IndexOf(book);
                Statuses[index] = statuses;
            }
            if (LoadStatus == LoadMoreStatus.StausNodata)
            {
                LoadStatus = LoadMoreStatus.StausEnd;
            }
        }
Example #4
0
        protected virtual bool AddStatus(StatusModel model, bool isNewArrival)
        {
            if (!CheckStatusAdd(model.Status, true))
            {
                return(false);
            }

            var stamp = model.Status.CreatedAt;

            Statuses.Insert(
                i => i.TakeWhile(s => s.Status.CreatedAt > stamp).Count(),
                model);
            // check auto trim
            if (IsAutoTrimEnabled &&
                _statusIdCache.Count > TimelineChunkCount + TimelineChunkCountBounce &&
                Interlocked.Exchange(ref _trimCount, 1) == 0)
            {
                TrimTimeline();
            }
            return(true);
        }
Example #5
0
        public async Task UpdateStatuses(long maxid = 0)
        {
            if (UpdatingStatuses)
            {
                return;
            }

            if (_userId == 0 || Tokens == null)
            {
                return;
            }

            UpdatingStatuses = true;

            try
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "user_id", _userId },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                var userTweets = await Tokens.Statuses.UserTimelineAsync(param);

                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                foreach (var status in userTweets)
                {
                    Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                     new TweetEventArgs(status, Tokens.UserId, new List <string> {
                        "none://"
                    }, false));

                    var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                    var index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                    if (index == -1)
                    {
                        index = Statuses.IndexOf(
                            Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                        if (index == -1)
                        {
                            Statuses.Add(status);
                        }
                        else
                        {
                            Statuses.Insert(index, status);
                        }
                    }
                }
            }
            catch
            {
                if (maxid == 0)
                {
                    Statuses.Clear();
                }

                UpdatingStatuses = false;
                return;
            }

            UpdatingStatuses = false;
        }
Example #6
0
        public async Task UpdateStatuses(long maxid = 0, bool clear = true)
        {
            if (UpdatingStatusSearch)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(_statusSearchWords) || Tokens == null)
            {
                return;
            }

            UpdatingStatusSearch = true;

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            IEnumerable <Status> search;

            if (SettingService.Setting.UseOfficialApi &&
                TwitterConnectionHelper.OfficialConsumerKeyList.Contains(Tokens.ConsumerKey))
            {
                var param = new Dictionary <string, object>
                {
                    { "q", _statusSearchWords },
                    { "count", 20 },
                    { "result_type", "recent" },
                    { "modules", "status" },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param["q"] = param["q"] + " max_id:" + maxid;
                }

                try
                {
                    var res = await Tokens.TwitterTokens.SendRequestAsync(CoreTweet.MethodType.Get,
                                                                          "https://api.twitter.com/1.1/search/universal.json", param);

                    var json = await res.Source.Content.ReadAsStringAsync();

                    var jsonObject = JObject.Parse(json);
                    var modules    = jsonObject["modules"].Children <JObject>();

                    var tweets = new List <CoreTweet.Status>();
                    foreach (var status in modules)
                    {
                        foreach (var prop in status.Properties())
                        {
                            if (prop.Name == "status")
                            {
                                tweets.Add(
                                    CoreTweet.Core.CoreBase.Convert <CoreTweet.Status>(
                                        JsonConvert.SerializeObject(status["status"]["data"])));
                            }
                        }
                    }

                    search = tweets.Select(x => new Status(x));
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }
            else
            {
                var param = new Dictionary <string, object>
                {
                    { "count", 20 },
                    { "include_entities", true },
                    { "q", _statusSearchWords },
                    { "tweet_mode", CoreTweet.TweetMode.Extended }
                };
                if (maxid != 0)
                {
                    param.Add("max_id", maxid);
                }

                try
                {
                    search = await Tokens.Search.TweetsAsync(param);
                }
                catch
                {
                    if (maxid == 0 && clear)
                    {
                        Statuses.Clear();
                    }

                    UpdatingStatusSearch = false;
                    return;
                }
            }

            if (maxid == 0 && clear)
            {
                Statuses.Clear();
            }

            foreach (var status in search)
            {
                Connecter.Instance.TweetReceive_OnCommandExecute(this,
                                                                 new TweetEventArgs(status, Tokens.UserId, new List <string> {
                    "none://"
                }, false));

                var id    = status.HasRetweetInformation ? status.RetweetInformation.Id : status.Id;
                var index = Statuses.IndexOf(
                    Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) == id));
                if (index == -1)
                {
                    index = Statuses.IndexOf(
                        Statuses.FirstOrDefault(x => (x.HasRetweetInformation ? x.RetweetInformation.Id : x.Id) < id));
                    if (index == -1)
                    {
                        Statuses.Add(status);
                    }
                    else
                    {
                        Statuses.Insert(index, status);
                    }
                }
            }

            UpdatingStatusSearch = false;
        }