private async void Save() { try { // If no exception is caught, it means update was succesful and we can continue updating everything var activeTime = await TinderHelper.UpdateUser(Bio, MinAge, MaxAge, Distance, InterestedIn); User.ActiveTime = activeTime; User.Bio = Bio; User.AgeFilterMin = MinAge; User.AgeFilterMax = MaxAge; User.DistanceFilter = Distance; User.InterestedIn.Clear(); if (InterestedIn == Gender.Both) { User.InterestedIn.Add(Gender.Man); User.InterestedIn.Add(Gender.Woman); } else { User.InterestedIn.Add(InterestedIn); } MessageBox.Show("Updated"); } catch (TinderRequestException e) { MessageBox.Show(e.Message); } }
/// <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); } }
private void SetLocation() { try { TinderHelper.PingLocation(MyLatitude, MyLongtitude); SerializationHelper.UpdateUserPosition(MyLatitude, MyLongtitude); } catch (TinderRequestException e) { MessageBox.Show(e.Message); } }
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(); }
/// <summary> /// Likes the selected recommendation /// </summary> /// <param name="superLike">True if a superlike should be send, default is false</param> private async Task Like(bool superLike = false, bool showMessage = true) { if (SelectedRec != null) { try { var likesent = await TinderHelper.LikeRecommendation(SelectedRec.Id, superLike); // It was a super like, update if neccesarry if (superLike) { SuperLikesLeft = likesent.SuperLikes.Remaining; if (likesent.SuperLikes.Remaining == 0) { SerializationHelper.UpdateSuperLikes(resetAt: likesent.SuperLikes.ResetsAt, likesLeft: likesent.SuperLikes.Remaining, max: likesent.SuperLikes.Allotment); CanSuperLike = false; } } var matchToMove = SelectedRec; RemoveRecomendations(SelectedRec); RecsView.UpdateLayout(); // If the method returns a non-null value, it means it's a match if (likesent.Match != null) { SerializationHelper.MoveRecToMatches(matchToMove); Messenger.Default.Send("", MessengerToken.ForceUpdate); if (showMessage) { MessageBox.Show("It's a match!"); } } else { SerializationHelper.MoveRecToPending(matchToMove); } } catch (TinderRequestException e) { MessageBox.Show(e.Message); } } }
/// <summary> /// Tries authenticating with Tinder servers and getting User Data /// </summary> /// <returns></returns> public async Task <bool> Authenticate(string fbId, string fbToken) { try { // We get tinder token everytime Auth = await TinderHelper.GetAuthData(fbId, fbToken); User = await TinderHelper.GetFullUserData(); return(true); } catch (TinderRequestException e) { MessageBox.Show(e.Message); return(false); } }
private async void SendMessage() { string msg = MessageToSend; try { MessageToSend = string.Empty; MessageModel sentMessage = await TinderHelper.SendMessage(Match.Id, msg); Match.Messages.Add(sentMessage); _lastActivity = sentMessage.SentDate; } catch (TinderRequestException e) { MessageBox.Show(e.Message); MessageToSend = msg; } }
private void Unmatch(MatchModel match) { var decision = MessageBox.Show($"Do you really want to unmatch with {match.Person.Name}?", "Are you sure about that?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (decision == MessageBoxResult.Yes) { try { SerializationHelper.MoveMatchToUnMatchedByMe(match); TinderHelper.UnmatchPerson(match.Id); MatchList.Remove(match); } catch (TinderRequestException e) { MessageBox.Show(e.Message); } } }
/// <summary> /// Passes the selected recommendation /// </summary> private async void Pass() { if (SelectedRec != null) { try { await TinderHelper.PassRecommendation(SelectedRec.Id); var matchToDelete = SelectedRec; RemoveRecomendations(SelectedRec); RecsView.UpdateLayout(); SerializationHelper.MoveRecToPassed(matchToDelete); } catch (TinderRequestException e) { MessageBox.Show(e.Message); } } }
/// <summary> /// Tries connecting to Tinder servers and getting recommendations /// </summary> /// <returns></returns> public async Task <bool> GetRecs() { try { var recs = await TinderHelper.GetRecommendations(); if (recs.Recommendations != null) { // Out of recs if (recs.Recommendations.Any(x => x.Id.Contains("tinder_rate_limited"))) { RecList.Clear(); SerializationHelper.EmptyRecommendations(); return(false); } // If it's the first time getting recs if (RecList == null) { RecList = new ObservableCollection <RecModel>(recs.Recommendations); } // Only useful if we force to download new recs in which case old // recs would be no use anyway RecList.Clear(); foreach (var item in recs.Recommendations) { RecList.Add(item); } return(true); } else { return(false); } } catch (TinderRequestException e) { MessageBox.Show(e.Message); return(false); } }
/// <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); } }
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); } }
/// <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); } } }