Пример #1
0
        public virtual void DeleteFriend(long userId, long fid, String ip)
        {
            FollowerService followService = new FollowerService();

            String     condition = "User.Id=" + userId + " and Friend.Id=" + fid + " and Status=" + FriendStatus.Approved;
            FriendShip ship      = db.find <FriendShip>(condition).first();

            if (ship != null)
            {
                db.delete(ship);
                if (followService.IsFollowing(userId, fid) == false)
                {
                    followService.Follow(userId, fid, ip);
                }
                recountFriends(userId);
                recountFriends(fid);

                return;
            }

            condition = "User.Id=" + fid + " and Friend.Id=" + userId + " and Status=" + FriendStatus.Approved;
            ship      = db.find <FriendShip>(condition).first();
            if (ship != null)
            {
                db.delete(ship);
                if (followService.IsFollowing(fid, userId) == false)
                {
                    followService.Follow(fid, userId, ip);
                }
                recountFriends(userId);
                recountFriends(fid);
            }
        }
Пример #2
0
        public virtual Result AddFriend( int userId, int friendId, String msg )
        {
            Result result = CanAddFriend( userId, friendId );
            if (result.HasErrors) return result;

            FriendShip fs = new FriendShip();

            User user = userService.GetById( userId );
            User friend = userService.GetById( friendId );

            fs.User = user;
            fs.Friend = friend;
            fs.Msg = msg;

            fs.Status = FriendStatus.Waiting;

            result = db.insert( fs );
            if (result.IsValid) {
                string userLink = Link.ToMember( user );
                String note = string.Format( "<a href=\"{0}\" target=\"_blank\" class=\"requestUser\">{1}</a> " + lang.get( "requestFriend" ), userLink, user.Name );
                if (strUtil.HasText( msg )) {
                    note += "<br/><span class=\"quote\">" + msg + "</span>";
                }
                notificationService.sendFriendRequest( userId, friendId, note );

                // 顺带添加关注
                FollowerService followService = new FollowerService();
                if (followService.IsFollowing( userId, friendId ) == false)
                    followService.Follow( userId, friendId );
            }
            return result;
        }
Пример #3
0
        public virtual Result AddFriend(long userId, long friendId, String msg, String ip)
        {
            Result result = CanAddFriend(userId, friendId);

            if (result.HasErrors)
            {
                return(result);
            }

            FriendShip fs = new FriendShip();

            User user   = userService.GetById(userId);
            User friend = userService.GetById(friendId);

            fs.User   = user;
            fs.Friend = friend;
            fs.Msg    = msg;

            fs.Status = FriendStatus.Waiting;
            fs.Ip     = ip;

            result = db.insert(fs);
            if (result.IsValid)
            {
                string userLink = Link.ToMember(user);
                String note     = string.Format("<a href=\"{0}\" target=\"_blank\" class=\"requestUser\">{1}</a> " + lang.get("requestFriend"), userLink, user.Name);
                if (strUtil.HasText(msg))
                {
                    note += "<br/><span class=\"quote\">" + msg + "</span>";
                }
                notificationService.sendFriendRequest(userId, friendId, note);

                // 顺带添加关注
                FollowerService followService = new FollowerService();
                if (followService.IsFollowing(userId, friendId) == false)
                {
                    followService.Follow(userId, friendId, ip);
                }
            }
            return(result);
        }
Пример #4
0
        public virtual void DeleteFriend( int userId, int fid )
        {
            FollowerService followService = new FollowerService();

            String condition = "User.Id=" + userId + " and Friend.Id=" + fid + " and Status=" + FriendStatus.Approved;
            FriendShip ship = db.find<FriendShip>( condition ).first();
            if (ship != null) {
                db.delete( ship );
                if (followService.IsFollowing( userId, fid ) == false) followService.Follow( userId, fid );
                recountFriends( userId );
                recountFriends( fid );

                return;
            }

            condition = "User.Id=" + fid + " and Friend.Id=" + userId + " and Status=" + FriendStatus.Approved;
            ship = db.find<FriendShip>( condition ).first();
            if (ship != null) {
                db.delete( ship );
                if (followService.IsFollowing( fid, userId ) == false) followService.Follow( fid, userId );
                recountFriends( userId );
                recountFriends( fid );

            }
        }