mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-17 18:38:50 +00:00
Move DB queries related to 'users' in a separate module (2/2)
This commit is contained in:
@@ -39,6 +39,16 @@ module Invidious::Database::Users
|
||||
# Update (history)
|
||||
# -------------------
|
||||
|
||||
def update_watch_history(user : User)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET watched = $1
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, user.watched, user.email)
|
||||
end
|
||||
|
||||
def mark_watched(user : User, vid : String)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
@@ -73,6 +83,16 @@ module Invidious::Database::Users
|
||||
# Update (channels)
|
||||
# -------------------
|
||||
|
||||
def update_subscriptions(user : User)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET feed_needs_update = true, subscriptions = $1
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, user.subscriptions, user.email)
|
||||
end
|
||||
|
||||
def subscribe_channel(user : User, ucid : String)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
@@ -95,6 +115,65 @@ module Invidious::Database::Users
|
||||
PG_DB.exec(request, ucid, user.email)
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Update (notifs)
|
||||
# -------------------
|
||||
|
||||
def add_notification(video : ChannelVideo)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET notifications = array_append(notifications, $1),
|
||||
feed_needs_update = true
|
||||
WHERE $2 = ANY(subscriptions)
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, video.id, video.ucid)
|
||||
end
|
||||
|
||||
def remove_notification(user : User, vid : String)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET notifications = array_remove(notifications, $1)
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, vid, user.email)
|
||||
end
|
||||
|
||||
def clear_notifications(user : User)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET notifications = $1, updated = $2
|
||||
WHERE email = $3
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, [] of String, Time.utc, user)
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Update (misc)
|
||||
# -------------------
|
||||
|
||||
def update_preferences(user : User)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET preferences = $1
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, user.preferences.to_json, user.email)
|
||||
end
|
||||
|
||||
def update_password(user : User, pass : String)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET password = $1
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, user.email, pass)
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Select
|
||||
# -------------------
|
||||
@@ -126,4 +205,14 @@ module Invidious::Database::Users
|
||||
|
||||
return PG_DB.query_one?(request, token, as: User)
|
||||
end
|
||||
|
||||
def select_notifications(user : User) : Array(String)
|
||||
request = <<-SQL
|
||||
SELECT notifications
|
||||
FROM users
|
||||
WHERE email = $1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one(request, user.email, as: Array(String))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user