public async Task <FriendDto> CreateFriendshipRequest(CreateFriendshipRequestInput input) { var userIdentifier = AbpSession.ToUserIdentifier(); var probableFriend = new UserIdentifier(input.TenantId, input.UserId); _chatFeatureChecker.CheckChatFeatures(userIdentifier.TenantId, probableFriend.TenantId); if (await _friendshipManager.GetFriendshipOrNullAsync(userIdentifier, probableFriend) != null) { throw new UserFriendlyException(L("YouAlreadySentAFriendshipRequestToThisUser")); } var user = await UserManager.FindByIdAsync(AbpSession.GetUserId().ToString()); User probableFriendUser; using (CurrentUnitOfWork.SetTenantId(input.TenantId)) { probableFriendUser = await UserManager.FindByIdAsync(input.UserId.ToString()); } var friendTenancyName = probableFriend.TenantId.HasValue ? _tenantCache.Get(probableFriend.TenantId.Value).TenancyName : null; var sourceFriendship = new Friendship(userIdentifier, probableFriend, friendTenancyName, probableFriendUser.UserName, probableFriendUser.ProfilePictureId, FriendshipState.Accepted); await _friendshipManager.CreateFriendshipAsync(sourceFriendship); var userTenancyName = user.TenantId.HasValue ? _tenantCache.Get(user.TenantId.Value).TenancyName : null; var targetFriendship = new Friendship(probableFriend, userIdentifier, userTenancyName, user.UserName, user.ProfilePictureId, FriendshipState.Accepted); await _friendshipManager.CreateFriendshipAsync(targetFriendship); var clients = _onlineClientManager.GetAllByUserId(probableFriend); if (clients.Any()) { var isFriendOnline = _onlineClientManager.IsOnline(sourceFriendship.ToUserIdentifier()); _chatCommunicator.SendFriendshipRequestToClient(clients, targetFriendship, false, isFriendOnline); } var senderClients = _onlineClientManager.GetAllByUserId(userIdentifier); if (senderClients.Any()) { var isFriendOnline = _onlineClientManager.IsOnline(targetFriendship.ToUserIdentifier()); _chatCommunicator.SendFriendshipRequestToClient(senderClients, sourceFriendship, true, isFriendOnline); } var sourceFriendshipRequest = ObjectMapper.Map <FriendDto>(sourceFriendship); sourceFriendshipRequest.IsOnline = _onlineClientManager.GetAllByUserId(probableFriend).Any(); return(sourceFriendshipRequest); }
public GetUserChatFriendsWithSettingsOutput GetUserChatFriendsWithSettings() { var userIdentifier = AbpSession.ToUserIdentifier(); if (userIdentifier == null) { return(new GetUserChatFriendsWithSettingsOutput()); } var cacheItem = _userFriendsCache.GetCacheItem(userIdentifier); var friends = ObjectMapper.Map <List <FriendDto> >(cacheItem.Friends); foreach (var friend in friends) { friend.IsOnline = _onlineClientManager.IsOnline( new UserIdentifier(friend.FriendTenantId, friend.FriendUserId) ); } return(new GetUserChatFriendsWithSettingsOutput { Friends = friends, ServerTime = Clock.Now }); }
public GetUserChatFriendsWithSettingsOutput GetUserChatFriendsWithSettings() { var cacheItem = _userFriendsCache.GetCacheItem(InfrastructureSession.ToUserIdentifier()); var friends = cacheItem.Friends.MapTo <List <FriendDto> >(); foreach (var friend in friends) { friend.IsOnline = _onlineClientManager.IsOnline( new UserIdentifier(friend.FriendTenantId, friend.FriendUserId) ); } return(new GetUserChatFriendsWithSettingsOutput { Friends = friends, ServerTime = Clock.Now }); }
public GetUserChatFriendsWithSettingsOutput GetUserChatFriendsWithSettings() { var cacheItem = _userFriendsCache.GetCacheItem(AbpSession.ToUserIdentifier()); var friends = cacheItem.Friends.MapTo <List <FriendDto> >(); foreach (var friend in friends) { friend.IsOnline = _onlineClientManager.IsOnline( new UserIdentifier(friend.FriendTenantId, friend.FriendUserId) ); } return(new GetUserChatFriendsWithSettingsOutput { Friends = friends.Where(n => n.State == Friendships.FriendshipState.Accepted).ToList(), Blockes = friends.Where(n => n.State == Friendships.FriendshipState.Blocked).ToList(), ServerTime = Clock.Now }); }