FEAT: Added more info & functionality to UserPage & Added ability to follow streamers on both UserPage and VideoPage;

Added shortcut to toggle chat;
This commit is contained in:
Chris-1010
2025-02-07 02:11:22 +00:00
parent 1499e042cb
commit 16dc8f1ea2
16 changed files with 438 additions and 240 deletions

View File

@@ -95,7 +95,7 @@ def get_following_categories_streams():
@stream_bp.route('/user/<string:username>/status')
def get_user_live_status(username):
"""
Returns a streamer's status, if they are live or not and their most recent stream (their current stream if live)
Returns a streamer's status, if they are live or not and their most recent stream (as a vod) (their current stream if live)
"""
user_id = get_user_id(username)

View File

@@ -10,7 +10,7 @@ r = redis.from_url(redis_url, decode_responses=True)
user_bp = Blueprint("user", __name__)
@user_bp.route('/user/<string:username>')
def get_user_data(username):
def get_user_data(username: str):
"""
Returns a given user's data
"""
@@ -45,43 +45,38 @@ def user_subscription_expiration(subscribed_id: int):
return jsonify({"remaining_time": remaining_time})
## Follow Routes
@user_bp.route('/user/<int:user_id>/follows/<int:followed_id>')
def user_following(user_id: int, followed_id: int):
@user_bp.route('/user/following/<string:followed_username>')
def user_following(followed_username: str):
"""
Checks to see if user is following a streamer
Checks to see if user is following another streamer
"""
user_id = session.get("user_id")
followed_id = get_user_id(followed_username)
if is_following(user_id, followed_id):
return jsonify({"following": True})
return jsonify({"following": False})
@login_required
@user_bp.route('/user/follow/<string:username>')
def follow_user(username):
@user_bp.route('/user/follow/<int:target_user_id>')
def follow_user(target_user_id: int):
"""
Follows a user
"""
user_id = session.get("user_id")
following_id = get_user_id(username)
if follow(user_id, following_id):
return jsonify({"success": True,
"already_following": False})
return jsonify({"success": True,
"already_following": True})
return follow(user_id, target_user_id)
@login_required
@user_bp.route('/user/unfollow/<string:username>')
def unfollow_user(username):
@user_bp.route('/user/unfollow/<int:target_user_id>')
def unfollow_user(target_user_id: int):
"""
Unfollows a user
"""
user_id = session.get("user_id")
followed_id = get_user_id(username)
unfollow(user_id, followed_id)
return jsonify({"success": True})
return unfollow(user_id, target_user_id)
@login_required
@user_bp.route('/user/following')
def get_followed_streamers_():
def get_followed_streamers():
"""
Queries DB to get a list of followed streamers
"""

View File

@@ -88,32 +88,33 @@ def is_following(user_id: int, followed_id: int) -> bool:
""", (user_id, followed_id))
return bool(result)
def follow(user_id: int, following_id: int):
def follow(user_id: int, followed_id: int):
"""
Follows following_id user from user_id user
Follows followed_id user from user_id user
"""
if not is_following(user_id, following_id):
with Database() as db:
db.execute("""
INSERT INTO follows (user_id, followed_id)
VALUES(?,?);
""", (user_id, following_id))
return True
return False
if is_following(user_id, followed_id):
return {"success": False, "error": "Already following user"}, 400
with Database() as db:
db.execute("""
INSERT INTO follows (user_id, followed_id)
VALUES(?,?);
""", (user_id, followed_id))
return {"success": True}
def unfollow(user_id: int, followed_id: int):
"""
Unfollows follow_id user from user_id user
Unfollows followed_id user from user_id user
"""
if is_following(user_id, followed_id):
with Database() as db:
db.execute("""
DELETE FROM follows
WHERE user_id = ?
AND followed_id = ?
""", (user_id, followed_id))
return True
return False
if not is_following(user_id, followed_id):
return {"success": False, "error": "Not following user"}, 400
with Database() as db:
db.execute("""
DELETE FROM follows
WHERE user_id = ?
AND followed_id = ?
""", (user_id, followed_id))
return {"success": True}
def subscription_expiration(user_id: int, subscribed_id: int) -> int:
@@ -197,11 +198,11 @@ def get_followed_streamers(user_id: int) -> Optional[List[dict]]:
def get_user(user_id: int) -> Optional[dict]:
"""
Returns username, bio, number of followers, and if user is partnered from user_id
Returns information about a user from user_id
"""
with Database() as db:
data = db.fetchone("""
SELECT username, bio, num_followers, is_partnered FROM users
SELECT user_id, username, bio, num_followers, is_partnered, is_live FROM users
WHERE user_id = ?;
""", (user_id,))
return data