Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverside hidden activities #112

Merged
merged 11 commits into from
May 28, 2024
Prev Previous commit
Next Next commit
fix: clean up quality:tm: code
raikasdev committed Mar 12, 2024
commit 0190fe09ddaee2b110de9e947cb7c5b2fa9655a5
2 changes: 1 addition & 1 deletion src/database/activity.rs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@
let mut activities = query.load::<CodingActivity>(&mut conn).await?;

// Change hidden entries project name
if is_self == false {
if !is_self {
for act in &mut activities {
if act.hidden {
// Empty string instead of None() to make sure we don't make everything into "undefined" :D
@@ -118,21 +118,21 @@
all_time: self
.get_user_coding_time_since(
uid,
chrono::NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),

Check warning on line 121 in src/database/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check failure on line 121 in src/database/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead
)
.await
.unwrap_or(0),
past_month: self
.get_user_coding_time_since(
uid,
chrono::Local::now().naive_local() - chrono::Duration::days(30),

Check warning on line 128 in src/database/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead

Check failure on line 128 in src/database/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead
)
.await
.unwrap_or(0),
past_week: self
.get_user_coding_time_since(
uid,
chrono::Local::now().naive_local() - chrono::Duration::days(7),

Check warning on line 135 in src/database/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead

Check failure on line 135 in src/database/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead
)
.await
.unwrap_or(0),

Unchanged files with check annotations Beta

drop(activity);
let curtime = Local::now().naive_local();
if heartbeat.eq(&current_heartbeat) {
if curtime.signed_duration_since(start + duration) > Duration::seconds(900) {

Check warning on line 71 in src/api/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

Check failure on line 71 in src/api/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
// If the user sends a heartbeat but maximum activity duration has been exceeded,
// end session and start new
db.add_activity(user.id, current_heartbeat, start, duration)
(
heartbeat.into_inner(),
Local::now().naive_local(),
Duration::seconds(0),

Check warning on line 83 in src/api/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

Check failure on line 83 in src/api/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
),
);
Ok(HttpResponse::Ok().body(0i32.to_string()))
}
} else {
// Flush current session and start new session if heartbeat changes
if curtime.signed_duration_since(start + duration) < Duration::seconds(30) {

Check warning on line 101 in src/api/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

Check failure on line 101 in src/api/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
duration = curtime.signed_duration_since(start);
}
(
heartbeat.into_inner(),
Local::now().naive_local(),
Duration::seconds(0),

Check warning on line 114 in src/api/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

Check failure on line 114 in src/api/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
),
);
Ok(HttpResponse::Ok().body(0i32.to_string()))
(
heartbeat.into_inner(),
Local::now().naive_local(),
Duration::seconds(0),

Check warning on line 127 in src/api/activity.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

Check failure on line 127 in src/api/activity.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
),
);
Ok(HttpResponse::Ok().body(0.to_string()))
if chrono::Local::now()
.naive_local()
.signed_duration_since(*res)
< chrono::Duration::days(1)

Check warning on line 182 in src/api/auth.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead

Check failure on line 182 in src/api/auth.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead
{
return Err(TimeError::TooManyRegisters);
}
.iter()
.map(|a| {
if a.start_time
>= chrono::Local::now().naive_local() - chrono::Duration::days(30)

Check warning on line 97 in src/database/friends.rs

GitHub Actions / Check

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead

Check failure on line 97 in src/database/friends.rs

GitHub Actions / Clippy

use of deprecated associated function `chrono::TimeDelta::days`: Use `TimeDelta::try_days` instead
{
a.duration
} else {