Exemplo n.º 1
0
        private async void DownloadFullMatchData(MatchModel param)
        {
            ConnectionStatus = Properties.Resources.tinder_update_getting_matches;

            var updatedMatch = await TinderHelper.GetFullMatchData(param.Person.Id);

            SerializationHelper.UpdateMatchModel(param, updatedMatch);
            new Task(() => SerializationHelper.SerializeMatch(param)).Start();

            ConnectionStatus = Properties.Resources.tinder_auth_okay;
            FilterVM.SortMatchList();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes matches with null value (don't know why they are there) and
        /// sorts by LastActivityDate in descending order
        /// </summary>
        private void MatchListSetup()
        {
            // Adds event handlers for each message list
            foreach (var item in MatchList)
            {
                item.Messages = item.Messages ?? new ObservableCollection <MessageModel>();

                // For when there are already handlers attached
                item.Messages.CollectionChanged -= Messages_CollectionChanged;
                item.Messages.CollectionChanged += Messages_CollectionChanged;
            }

            // Remove ghost matches, which I don't know why exist
            for (int i = 0; i < MatchList.Count; i++)
            {
                if (MatchList[i].Person == null)
                {
                    MatchList.RemoveAt(i--);
                }
            }

            FilterVM.SortMatchList();
        }
Exemplo n.º 3
0
 /// <summary>
 /// If there are new messages added to collection, updates the view
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Messages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     FilterVM.SortMatchList();
 }
Exemplo n.º 4
0
        private async void UpdateMatches(object sender, EventArgs e)
        {
            try
            {
                var newUpdates = await TinderHelper.GetUpdates(SerializationHelper.GetLastUpdate());

                if (newUpdates.Matches.Count != 0)
                {
                    SerializationHelper.UpdateLastUpdate(newUpdates.LastActivityDate);

                    foreach (var newMatch in newUpdates.Matches)
                    {
                        var matchToUpdate = MatchList.Where(item => item.Id == newMatch.Id).FirstOrDefault();

                        // There's an update to an existing match
                        if (matchToUpdate != null)
                        {
                            // Adds new messages the to list
                            foreach (var newMessage in newMatch.Messages)
                            {
                                if (!matchToUpdate.Messages.Contains(newMessage))
                                {
                                    matchToUpdate.Messages.Add(newMessage);
                                }
                            }

                            if (!UpdatedMatches.Contains(matchToUpdate))
                            {
                                UpdatedMatches.Add(matchToUpdate);
                            }

                            matchToUpdate.LastActivityDate = newMatch.LastActivityDate;

                            new Task(() => SerializationHelper.SerializeMatch(matchToUpdate)).Start();
                        }
                        // There's a new match
                        else
                        {
                            new Task(() => SerializationHelper.SerializeMatch(newMatch)).Start();
                            MatchList.Insert(0, newMatch);
                            NewMatchList.Add(newMatch);
                        }
                    }
                }

                if (newUpdates.Blocks.Count != 0)
                {
                    foreach (var unmatched in newUpdates.Blocks)
                    {
                        var match = MatchList.Where(x => x.Id == unmatched).FirstOrDefault();
                        if (match != null)
                        {
                            SerializationHelper.MoveMatchToUnMatched(match);
                            MatchList.Remove(match);
                            MessageBox.Show(match.Person.Name + " unmatched you");
                        }
                    }
                }

                FilterVM.SortMatchList();
            }
            catch (TinderRequestException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// First thing called. Entry point of some sort. Calls other methods to get Tinder data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void StartInitialize(object sender, EventArgs e)
        {
            ConnectionStatus = Resources.tinder_auth_connecting;

            // Only do full authorization if it's the first time or data is not saved yet
            if (string.IsNullOrEmpty(UserName))
            {
                if (await Authenticate(FbId, FbToken))
                {
                    UserName = User.ToString();

                    string lat = "0";
                    string lon = "0";

                    if (User.Pos != null)
                    {
                        lat = User.Pos.Latitude.Replace('.', ',');
                        lon = User.Pos.Longtitude.Replace('.', ',');
                    }

                    SerializationHelper.CreateUser(FbId, FbToken, UserName, User.LatestUpdateDate,
                                                   lat, lon);
                    SerializationHelper.UpdateTinderToken(Auth.Token);


                    // Gets matches
                    await GetMatches();

                    // Gets recs
                    await GetRecs();

                    int time = MatchList.Count * 3 / 60;
                    // Dont ask just save nobody cares what user wants
                    MessageBox.Show($"All your matches will be saved. It may take up to {time} minutes "
                                    + "for the download to complete. I recommend not to cancel this action.",
                                    "Downloading data", MessageBoxButton.OK, MessageBoxImage.Information);

                    Messenger.Default.Send(new SerializationPacket(MatchList, RecList, User),
                                           MessengerToken.ShowSerializationDialog);

                    Settings.Default["FirstStart"] = false;
                    Settings.Default.Save();

                    StartUpdatingMatches();
                    StartUpdatingRecs();
                    ConnectionStatus = Resources.tinder_auth_okay;
                }
            }
            // It's not the first time launching application
            else
            {
                SerializationHelper.CurrentUser = UserName;


                // FIXME hangs application for a second
                // Deserializes matches and recs first
                MatchList = SerializationHelper.DeserializeMatchList();


                MatchListSetup();
                FilterVM.UpdateStatusBar();

                RecList = SerializationHelper.DeserializeRecList();

                if (await Authenticate(FbId, FbToken))
                {
                    string lat = "0";
                    string lon = "0";

                    if (User.Pos != null)
                    {
                        lat = User.Pos.Latitude.Replace('.', ',');
                        lon = User.Pos.Longtitude.Replace('.', ',');
                        SerializationHelper.UpdateUserPosition(lat, lon);
                    }


                    SerializationHelper.UpdateTinderToken(Auth.Token);

                    // Updates last five matches
                    Parallel.ForEach(MatchList.OrderByDescending(x => x.LastActivityDate).Take(5), async x =>
                    {
                        try
                        {
                            var updatedMatch = await TinderHelper.GetFullMatchData(x.Person.Id);
                            SerializationHelper.UpdateMatchModel(x, updatedMatch);
                            new Task(() => SerializationHelper.SerializeMatch(x)).Start();
                        }
                        catch (TinderRequestException ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    });

                    FilterVM.SortMatchList();

                    UpdateMatches(this, null);
                    UpdateRecs(this, null);

                    ConnectionStatus = Resources.tinder_auth_okay;

                    // Starts automatic updates
                    StartUpdatingMatches();
                    StartUpdatingRecs();
                }
                else
                {
                    ConnectionStatus = Resources.tinder_auth_error;
                }
            }

            // Now we check if there's a new version available
            var restClient = new RestClient("https://api.github.com/");
            var request    = new RestRequest("repos/dainius14/twinder/releases/latest", Method.GET);
            var response   = await restClient.ExecuteTaskAsync(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var json = JsonConvert.DeserializeObject <dynamic>(response.Content);
                if (!("v" + Assembly.GetExecutingAssembly().GetName().Version.ToString()).StartsWith((string)json.tag_name))
                {
                    Messenger.Default.Send((string)json.html_url, MessengerToken.ShowUpdateAvailableDialog);
                }
            }
        }