Add watch history

This commit is contained in:
Omar Roth 2018-07-28 20:40:59 -05:00
parent 44eef9654a
commit b5c92c1a2f
4 changed files with 103 additions and 20 deletions

View file

@ -29,6 +29,7 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({
"max_results" => 40,
"sort" => "published",
"latest_only" => false,
"unseen_only" => false,
}.to_json)
class Config
@ -147,6 +148,10 @@ class User
},
password: String?,
token: String,
watched: {
type: Array(String),
default: ["N/A"],
},
})
end
@ -177,6 +182,7 @@ class Preferences
max_results: Int32,
sort: String,
latest_only: Bool,
unseen_only: Bool,
})
end
@ -817,7 +823,12 @@ def get_user(sid, client, headers, db, refresh = true)
if refresh && Time.now - user.updated > 1.minute
user = fetch_user(sid, client, headers, db)
user_array = user.to_a
if user.watched = ["N/A"]
user_array = user.to_a[0..-2]
else
user_array = user.to_a
end
user_array[5] = user_array[5].to_json
args = arg_array(user_array)
@ -826,7 +837,12 @@ def get_user(sid, client, headers, db, refresh = true)
end
else
user = fetch_user(sid, client, headers, db)
user_array = user.to_a
if user.watched = ["N/A"]
user_array = user.to_a[0..-2]
else
user_array = user.to_a
end
user_array[5] = user_array[5].to_json
args = arg_array(user.to_a)
@ -864,7 +880,7 @@ def fetch_user(sid, client, headers, db)
token = Base64.encode(Random::Secure.random_bytes(32))
user = User.new(sid, Time.now, [] of String, channels, email, DEFAULT_USER_PREFERENCES, nil, token)
user = User.new(sid, Time.now, [] of String, channels, email, DEFAULT_USER_PREFERENCES, nil, token, [] of String)
return user
end
@ -872,7 +888,7 @@ def create_user(sid, email, password)
password = Crypto::Bcrypt::Password.create(password, cost: 10)
token = Base64.encode(Random::Secure.random_bytes(32))
user = User.new(sid, Time.now, [] of String, [] of String, email, DEFAULT_USER_PREFERENCES, password.to_s, token)
user = User.new(sid, Time.now, [] of String, [] of String, email, DEFAULT_USER_PREFERENCES, password.to_s, token, [] of String)
return user
end

View file

@ -88,10 +88,22 @@ function update_value(element) {
</div>
<div class="pure-control-group">
<label for="latest_only">Only show latest video from channel: </label>
<label for="latest_only">Only show latest <% if user.preferences.unseen_only %>unseen<% end %> video from channel: </label>
<input name="latest_only" id="latest_only" type="checkbox" <% if user.preferences.latest_only %>checked<% end %>>
</div>
<div class="pure-control-group">
<label for="unseen_only">Only show unseen: </label>
<input name="unseen_only" id="unseen_only" type="checkbox" <% if user.preferences.unseen_only %>checked<% end %>>
</div>
<legend>Data preferences</legend>
<div class="pure-control-group">
<label>
<a href="/clear_watch_history">Clear watch history</a>
</labe>
</div>
<div class="pure-controls">
<button type="submit" class="pure-button pure-button-primary">Save preferences</button>
</div>