Simplify "last-activity" handling

This commit is contained in:
Michael 2022-12-04 07:17:26 +00:00
parent 1d8c9276f3
commit e5a531d3b5
5 changed files with 12 additions and 15 deletions

View File

@ -2693,7 +2693,7 @@ CREATE VIEW `owner-view` AS SELECT
`user`.`language` AS `language`,
`user`.`register_date` AS `register_date`,
`user`.`login_date` AS `login_date`,
IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`) AS `last-activity`,
`user`.`last-activity` AS `last-activity`,
`user`.`default-location` AS `default-location`,
`user`.`allow_location` AS `allow_location`,
`user`.`theme` AS `theme`,

View File

@ -94,18 +94,9 @@ class NoScrape extends BaseModule
}
// We display the last activity (post or login), reduced to year and week number
$last_active = 0;
$condition = ['uid' => $owner['uid'], 'self' => true];
$contact = DBA::selectFirst('contact', ['last-item'], $condition);
if (DBA::isResult($contact)) {
$last_active = strtotime($contact['last-item']);
}
$user = User::getOwnerDataById($owner['uid']);
if (DBA::isResult($user)) {
if ($last_active < strtotime($user['last-activity'])) {
$last_active = strtotime($user['last-activity']);
}
$last_active = strtotime($owner['last-item']);
if ($last_active < strtotime($owner['last-activity'])) {
$last_active = strtotime($owner['last-activity']);
}
$json_info['last-activity'] = date('o-W', $last_active);

View File

@ -45,7 +45,7 @@ class PollContacts
if (!empty($abandon_days)) {
$condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `owner-view` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
} else {
$condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`)", 0]);

View File

@ -889,7 +889,7 @@
"language" => ["user", "language"],
"register_date" => ["user", "register_date"],
"login_date" => ["user", "login_date"],
"last-activity" => "IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`)",
"last-activity" => ["user", "last-activity"],
"default-location" => ["user", "default-location"],
"allow_location" => ["user", "allow_location"],
"theme" => ["user", "theme"],

View File

@ -1126,4 +1126,10 @@ function update_1491()
{
DBA::update('contact', ['remote_self' => Contact::MIRROR_OWN_POST], ['remote_self' => Contact::MIRROR_FORWARDED]);
return Update::SUCCESS;
}
function update_1497()
{
DBA::e("UPDATE `user` SET `last-activity` = DATE(`login_date`) WHERE `last-activity` IS NULL");
return Update::SUCCESS;
}