예제 #1
0
        /// <summary>
        /// Tries connecting to Tinder servers and getting updates
        /// </summary>
        /// <returns></returns>
        public async Task <bool> GetMatches()
        {
            try
            {
                Updates = await TinderHelper.GetUpdates();

                if (MatchList == null && Updates.Matches != null)
                {
                    MatchList = Updates.Matches;
                }
                else
                {
                    MatchList = new ObservableCollection <MatchModel>();
                }

                MatchListSetup();

                SerializationHelper.UpdateLastUpdate(Updates.LastActivityDate);
                return(true);
            }
            catch (TinderRequestException e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Download all updates of matches
        /// </summary>
        private async void ForceDownloadMatches()
        {
            ConnectionStatus = Properties.Resources.tinder_update_getting_matches;
            try
            {
                bool setUpMatchList = false;
                var  updates        = await TinderHelper.GetUpdates();

                // FIXME For 200 matches this hangs for ~10s
                foreach (var item in updates.Matches.Where(x => x.Person != null))
                {
                    var match = MatchList.FirstOrDefault(x => x.Person.Id == item.Person.Id);
                    if (match != null)
                    {
                        SerializationHelper.UpdateMatchModel(match, item);
                    }
                    else
                    {
                        MatchList.Add(item);
                        setUpMatchList = true;
                    }
                }

                if (setUpMatchList)
                {
                    MatchListSetup();
                }

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

                ConnectionStatus = Properties.Resources.tinder_auth_okay;
            }
            catch (TinderRequestException e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #3
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);
            }
        }