public async Task RemoveFriend(Guid friendshipId) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var toRemove = Friends.FirstOrDefault(f => f.FriendshipId == friendshipId); Friends.Remove(toRemove); }); }
/// <summary> /// Given the html node of a timeline post, create a TimelinePost entity from the available data. /// </summary> /// <param name="node"></param> /// <returns></returns> public override TimelinePost ParseEntityFromHtml(HtmlNode node) { DateTime postDate; string postText = ""; int? postFriendId = null; string postComment = null; //The first node is always a date/time. Get the date string with timezone portion trimmed var nextNode = node.FirstChild; var dateString = nextNode.InnerHtml.Substring(0, nextNode.InnerHtml.Length - 4); postDate = DateTime.ParseExact(dateString, DateFormat, CultureInfoProvider); //Check if the post is empty if (nextNode.NextSibling != null) { nextNode = nextNode.NextSibling; //Check if the post's text is one html block if (nextNode.NextSibling == null) { postText = nextNode.InnerHtml; } else { //Check if the post was made by a friend if (nextNode.Name == "div" && !nextNode.Attributes.Any(attr => attr.Name == "class" && attr.Value == "comment")) { //Retrieve the friends name by getting all characters up to the beginning of a <br /> tag, which always follows the name var friendName = WebUtility.HtmlDecode(nextNode.InnerHtml.Substring(0, nextNode.InnerHtml.IndexOf('<'))); var friend = Friends.FirstOrDefault(x => x.Name == friendName); if (friend != null) { postFriendId = friend.Id; } nextNode = nextNode.NextSibling; } //Check if the post has text if (nextNode.Name == "#text") { postText = nextNode.InnerHtml; nextNode = nextNode.NextSibling; } //Check if the post has a comment if (nextNode != null) { postComment = nextNode.InnerHtml; } } } var timelinePost = new TimelinePost { PostComment = WebUtility.HtmlDecode(postComment), PostDate = postDate, PostFriendId = postFriendId, PostText = WebUtility.HtmlDecode(postText) }; return(timelinePost); }
public void RemoveFriend(string userId) { var foundFriend = Friends.FirstOrDefault(f => f.UserId == userId); if (foundFriend != null) { _friends.Remove(foundFriend); } }
private void ChangeUserOnlineStatus(int userId, bool online) { var friend = Friends.FirstOrDefault(f => f.Id == userId); if (friend != null) { friend.Online = online ? 1 : 0; } }
private static void SetConnectionState(KeyValuePair <ConnectionState, int> keyValuePairStateId) { Friends.FirstOrDefault(f => f.Id == keyValuePairStateId.Value).State = keyValuePairStateId.Key; ListBoxFriends.Dispatcher.Invoke(new Action(() => { ListBoxFriends.ItemsSource = Friends; ListBoxFriends.Items.Refresh(); })); }
private void Proxy_AccountRemoved(string id) { var removedFriend = GetFriend(id); RemoveFriendOnUiThread(removedFriend); if (SelectedFriend == removedFriend) { SelectedFriend = Friends.FirstOrDefault(); } }
public void AddFriend(Passenger passenger) { if (Friends.FirstOrDefault(p => p.Passenger2 == passenger || p.Passenger == passenger) == null) { Friends.Add(new Friend() { Passenger = this, Passenger2 = passenger, PassengerId = this.Id, Passenger2Id = passenger.Id }); } }
public IEnumerable <Account> FollowBack() { foreach (var user in Followers) { if (Friends.FirstOrDefault(e => e.Id == user.Id) == null) { client.Follow(user.Id); Logger.NLogInfo($"FollowBack to {user.UserName} on {Instance}."); yield return(user); } } }
private Message GetMessage(string friendId) { var msg = _messages.FirstOrDefault(m => m.Friend.Id == friendId); if (msg == null) { _messages.Add(msg = new Message { Friend = Friends.FirstOrDefault(a => a.Id == friendId) }); } return(msg); }
public async Task SetOnline(Guid friendshipId, bool isOnline) { CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var friend = Friends.FirstOrDefault(f => f.FriendshipId == friendshipId); if (friend != null) { var newFriend = new FriendDto { FriendshipId = friendshipId, Username = friend.Username, IsOnline = isOnline }; Friends[Friends.IndexOf(friend)] = newFriend; } }); }
void OnPersonaState(SK.SteamFriends.PersonaStateCallback callback) { SteamUser user; if (callback.FriendID.ToString() == CurrentUser.SteamId.SteamId32) { user = CurrentUser; // TODO: This check here is not properly done. Rethink. if (user.Name == null) { ClientFullyLoaded?.Invoke(this, null); } } else { user = Friends.FirstOrDefault(f => f.SteamId.SteamId32 == callback.FriendID.ToString()); } if (user == null) { return; } bool newStatus = (callback.State != 0); user.AvatarHash = community.GetFriendAvatar(new SK.SteamID(user.SteamId.SteamId32)); user.Name = community.GetPersonaName(); user.LastOnlineDate = new DateTime(Math.Max(callback.LastLogOn.Ticks, callback.LastLogOff.Ticks)); if (user.IsOnline != newStatus) { if (newStatus == true) { Console.WriteLine($"User '{user.Name}' is now online"); } else { Console.WriteLine($"User '{user.Name}' is now offline"); } user.IsOnline = newStatus; } }
public FriendModel GetUserById(string userId) { Func <FriendModel, bool> predicate = user => user.Id.Equals(userId); var result = Friends.FirstOrDefault(predicate); if (result == null) { result = Pending.FirstOrDefault(predicate); } if (result == null) { result = Blocked.FirstOrDefault(predicate); } if (result == null) { result = Requested.FirstOrDefault(predicate); } return(result); }
public MessengerUser GetFriend(int userId) => Friends.FirstOrDefault(friend => friend.PlayerData.Id == userId);
private FriendViewModel FindFriend(int friendNumber) { return(Friends.FirstOrDefault(friend => friend.FriendNumber == friendNumber)); }
private Account GetFriend(string id) => Friends.FirstOrDefault(f => f.Id == id);
public async Task ExecuteSearchForFriendCommand(string search) { search.Trim(); if (IsBusy) { return; } LoadingMessage = "Finding Friend..."; using (BusyContext()) { using (App.Logger.TrackTimeContext("FriendSearch")) { try { App.Logger.Track("FriendSearch"); if (!search.IsValidEmail()) { App.MessageDialog.SendToast("Please enter a valide email address."); return; } if (!await RefreshToken()) { return; } var userManager = new UserManager(Settings.AccessToken); var result = await userManager.GetUserViaEmail(search); IsBusy = false; //did not find anyone //add them and send invite if (result == null || result.Devices == null) { var newFriend = new Friend { FriendId = Settings.GenerateTempFriendId(), Name = search }; await DataManager.AddOrSaveFriendAsync(newFriend); await FriendsSemaphore.WaitAsync(); Friends.Add(newFriend); FriendsSemaphore.Release(); await userManager.SendUserInvite(search); RaiseNotification("Your friend hasn't signed up for Inner 6 Chat yet. We have sent them an invite!", "Friend Request Sent"); App.Logger.Track("FriendRequestSent"); return; } //did you enter yourself? if (!string.IsNullOrWhiteSpace(Settings.Email) && result.Email.ToLowerInvariant() == Settings.Email.ToLowerInvariant()) { RaiseNotification("This is you!"); return; } //did you already friend them? await FriendsSemaphore.WaitAsync(); var alreadyFriend = Friends.FirstOrDefault(f => f.FriendId == result.Id) != null; FriendsSemaphore.Release(); if (alreadyFriend) { RaiseNotification("Friend already added."); return; } //new friend found and we want to add them. var msg = string.Format("We found {0} do you want to add to friend list?", result.NickName); App.MessageDialog.SendConfirmation(msg, "Friend found!", async add => { if (!add) { return; } var newFriend = new Friend { FriendId = result.Id, Name = result.NickName, Photo = EndPoints.BaseUrl + result.Avatar.Location, AvatarType = result.Avatar.Type }; await DataManager.AddOrSaveFriendAsync(newFriend); await FriendsSemaphore.WaitAsync(); Friends.Add(newFriend); FriendsSemaphore.Release(); RaiseNotification("Friend added!"); App.Logger.Track("FriendAdded"); }); } catch (Exception ex) { App.Logger.Report(ex); RaiseError("Something has gone wrong, please try to search again."); } } } }
private bool IsFriend() { return(Friends.FirstOrDefault(c => c.Id == interlocutor.Id) != null); }