summaryrefslogtreecommitdiffstats
path: root/src/helpers.cr
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-03-31 19:09:27 -0500
committerOmar Roth <omarroth@hotmail.com>2018-03-31 19:09:27 -0500
commit57102c54c776a08eab79bf6cb0bc6473a8c7a557 (patch)
tree3c90ccf5c6ebf4439c1e3375a43df6dbe9623cd3 /src/helpers.cr
parent823f679cef1d9d0547cc0da1e9cd5a191a65a43b (diff)
downloadinvidious-57102c54c776a08eab79bf6cb0bc6473a8c7a557.tar.gz
invidious-57102c54c776a08eab79bf6cb0bc6473a8c7a557.tar.bz2
invidious-57102c54c776a08eab79bf6cb0bc6473a8c7a557.zip
Add notifications
Diffstat (limited to 'src/helpers.cr')
-rw-r--r--src/helpers.cr20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/helpers.cr b/src/helpers.cr
index 9bfa8b19..bca3954e 100644
--- a/src/helpers.cr
+++ b/src/helpers.cr
@@ -81,12 +81,11 @@ end
class User
add_mapping({
- id: String,
- updated: Time,
- notifications: Int32,
- subscriptions: Array(String),
- notifications_viewed: Time,
- email: String,
+ id: String,
+ updated: Time,
+ notifications: Array(String),
+ subscriptions: Array(String),
+ email: String,
})
end
@@ -547,6 +546,11 @@ def fetch_channel(id, client, db)
video_array = video.to_a
args = arg_array(video_array)
+ db.exec("UPDATE users SET notifications = notifications || $1 \
+ WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video_id, published, ucid)
+
+ # UPDATE users SET notifications = notifications || ARRAY['Os9Rypn2rEQ'] WHERE updated < '2018-03-24 20:48:46' AND 'UCSc16oMxxlcJSb9SXkjwMjA' = ANY(subscriptions) AND 'Os9Rypn2rEQ' <> ALL (notifications);
+
# TODO: Update record on conflict
db.exec("INSERT INTO channel_videos VALUES (#{args})\
ON CONFLICT (id) DO NOTHING", video_array)
@@ -569,7 +573,7 @@ def get_user(sid, client, headers, db)
args = arg_array(user_array)
db.exec("INSERT INTO users VALUES (#{args}) \
- ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, subscriptions = $4", user_array)
+ ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, notifications = ARRAY[]::text[], subscriptions = $4", user_array)
end
else
user = fetch_user(sid, client, headers)
@@ -603,6 +607,6 @@ def fetch_user(sid, client, headers)
email = ""
end
- user = User.new(sid, Time.now, 0, channels, Time.now, email)
+ user = User.new(sid, Time.now, [] of String, channels, email)
return user
end