public async Task <Status> ReShareOption(Status status)
        {
            // TODO: This "works", but it could be more simple. The API layer needs to be tweeked.
            // It would make more sense to replace the status object in the list with the one it gets from the API
            // But it's not updating, because OnPropertyChanged is not in Status...
            // Reblog returns "reblogged" status, not the original status updated.
            try
            {
                Status newStatus = status;
                if (status.Reblogged == null)
                {
                    await Client.Reblog(status.Id);

                    newStatus.Reblogged   = true;
                    newStatus.ReblogCount = newStatus.ReblogCount + 1;
                }
                else
                {
                    var reblogged = !status.Reblogged.Value;
                    if (reblogged)
                    {
                        await Client.Reblog(status.Id);

                        newStatus.Reblogged   = true;
                        newStatus.ReblogCount = newStatus.ReblogCount + 1;
                    }
                    else
                    {
                        await Client.Unreblog(status.Id);

                        newStatus.Reblogged   = false;
                        newStatus.ReblogCount = newStatus.ReblogCount - 1;
                    }
                }
                if (Statuses != null)
                {
                    var index = Statuses.IndexOf(status);
                    Statuses[index] = newStatus;
                }
                var notifications = Notifications?.Where(node => node.Status == status).ToList();
                if (notifications != null)
                {
                    for (var i = 0; i < notifications.Count(); i++)
                    {
                        var index           = Notifications.IndexOf(notifications[i]);
                        var newNotification = notifications[i];
                        newNotification.Status = newStatus;
                        Notifications[index]   = newNotification;
                    }
                }
                status = newStatus;
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }
            return(status);
        }
        public async Task <Status> FavoriteOption(Status status)
        {
            // TODO: This "works", but it could be more simple. The API layer needs to be tweeked.
            // It would make more sense to replace the status object in the list with the one it gets from the API
            // But it's not updating, because OnPropertyChanged is not in Status...
            try
            {
                Status newStatus;
                if (status.Favourited == null)
                {
                    newStatus = await Client.Favourite(status.Id);
                }
                else
                {
                    var favorite = !status.Favourited.Value;
                    if (favorite)
                    {
                        newStatus = await Client.Favourite(status.Id);
                    }
                    else
                    {
                        // API Bug: Unfavorite returns a status that still says it's favorited, even though it's not.
                        // Not sure if it's mastodon, or the instance I'm on. So for now, we'll force it to say it's
                        // not there.
                        newStatus = await Client.Unfavourite(status.Id);

                        newStatus.Favourited      = false;
                        newStatus.FavouritesCount = newStatus.FavouritesCount - 1;
                    }
                }
                if (Statuses != null)
                {
                    var index = Statuses.IndexOf(status);
                    Statuses[index] = newStatus;
                }
                var notifications = Notifications?.Where(node => node.Status == status).ToList();
                if (notifications != null)
                {
                    for (var i = 0; i < notifications.Count(); i++)
                    {
                        var index           = Notifications.IndexOf(notifications[i]);
                        var newNotification = notifications[i];
                        newNotification.Status = newStatus;
                        Notifications[index]   = newNotification;
                    }
                }
                status = newStatus;
            }
            catch (Exception e)
            {
                await MessageDialogMaker.SendMessageDialogAsync(e.Message, false);
            }
            return(status);
        }
        public async Task ShowNSFWPost(Status status)
        {
            Status newStatus = status;

            newStatus.Sensitive   = false;
            newStatus.SpoilerText = string.Empty;
            if (Statuses != null)
            {
                var index = Statuses.IndexOf(status);
                Statuses[index] = newStatus;
            }
        }
Example #4
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 #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;
        }