Exemplo n.º 1
0
        /// <summary>
        /// 移除好友
        /// </summary>
        /// <param name="userIdentifier">用户标识</param>
        /// <param name="friend">好友缓存项</param>
        public void RemoveFriend(UserIdentifier userIdentifier, FriendCacheItem friend)
        {
            var user = GetCacheItemOrNull(userIdentifier);

            if (user == null)
            {
                return;
            }

            lock (_syncObj)
            {
                if (user.Friends.ContainsFriend(friend))
                {
                    user.Friends.Remove(friend);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新好友
        /// </summary>
        /// <param name="userIdentifier">用户标识</param>
        /// <param name="friend">好友缓存项</param>
        public void UpdateFriend(UserIdentifier userIdentifier, FriendCacheItem friend)
        {
            var user = GetCacheItemOrNull(userIdentifier);

            if (user == null)
            {
                return;
            }

            lock (_syncObj)
            {
                var existingFriendIndex = user.Friends.FindIndex(
                    f => f.FriendUserId == friend.FriendUserId &&
                    f.FriendTenantId == friend.FriendTenantId
                    );

                if (existingFriendIndex >= 0)
                {
                    user.Friends[existingFriendIndex] = friend;
                }
            }
        }
 /// <summary>
 /// 是否包含好友
 /// </summary>
 /// <param name="items">好友缓存项列表</param>
 /// <param name="item">好友缓存项</param>
 /// <returns></returns>
 public static bool ContainsFriend(this List <FriendCacheItem> items, FriendCacheItem item)
 {
     return(items.Any(f => f.FriendTenantId == item.FriendTenantId && f.FriendUserId == item.FriendUserId));
 }