Esempio n. 1
0
        private void OpenChat(MatchModel item)
        {
            var obj = new PassAroundItem();

            obj.Item    = item;
            obj.DirPath = GetSourceFolder(item);

            Messenger.Default.Send(obj, MessengerToken.NewChatWindow);

            // Adding match to UpdateMatches list is the least complex way to force serialization
            // when user sends messages
            if (!UpdatedMatches.Contains(item))
            {
                UpdatedMatches.Add(item);
            }
        }
Esempio n. 2
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);
            }
        }