mirror of
https://github.com/friendica/friendica
synced 2024-11-09 16:22:56 +00:00
New field to show the day of the last activity
This commit is contained in:
parent
fbcc56d42d
commit
f905220923
8 changed files with 50 additions and 4 deletions
|
@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `user` (
|
|||
`language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
|
||||
`register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
|
||||
`login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
|
||||
`last-activity` date COMMENT 'Day of the last activity',
|
||||
`default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
|
||||
`allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
|
||||
`theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
|
||||
|
|
|
@ -21,6 +21,7 @@ Fields
|
|||
| language | default language | varchar(32) | NO | | en | |
|
||||
| register_date | timestamp of registration | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||
| login_date | timestamp of last login | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||
| last-activity | Day of the last activity | date | YES | | NULL | |
|
||||
| default-location | Default for item.location | varchar(255) | NO | | | |
|
||||
| allow_location | 1 allows to display the location | boolean | NO | | 0 | |
|
||||
| theme | user theme preference | varchar(255) | NO | | | |
|
||||
|
|
|
@ -260,6 +260,17 @@ class Relation
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the cached suggestion is outdated
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return boolean
|
||||
*/
|
||||
static public function areSuggestionsOutdated(int $uid): bool
|
||||
{
|
||||
return DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 < time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update contact suggestions for a given user
|
||||
*
|
||||
|
@ -268,7 +279,7 @@ class Relation
|
|||
*/
|
||||
static public function updateCachedSuggestions(int $uid)
|
||||
{
|
||||
if (DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 > time()) {
|
||||
if (!self::areSuggestionsOutdated($uid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -665,6 +665,22 @@ class User
|
|||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the day of the last activity of the given user
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return void
|
||||
*/
|
||||
public static function updateLastActivity(int $uid)
|
||||
{
|
||||
$user = User::getById($uid, ['last-activity']);
|
||||
$current_day = date('Y-m-d');
|
||||
|
||||
if ($user['last-activity'] != $current_day) {
|
||||
User::update(['last-activity' => $current_day], $uid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a human-readable random password
|
||||
*
|
||||
|
|
|
@ -39,6 +39,7 @@ use Friendica\Util\Network;
|
|||
use LightOpenID;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Contact;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
@ -358,8 +359,12 @@ class Authentication
|
|||
$this->dba->update('user', ['login_date' => DateTimeFormat::utcNow()],
|
||||
['parent-uid' => $user_record['uid'], 'account_removed' => false]);
|
||||
|
||||
// Update suggestions upon login
|
||||
Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $user_record['uid']);
|
||||
User::updateLastActivity($user_record['uid']);
|
||||
|
||||
// Regularly update suggestions
|
||||
if (Contact\Relation::areSuggestionsOutdated($user_record['uid'])) {
|
||||
Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $user_record['uid']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($login_initial) {
|
||||
|
|
|
@ -22,8 +22,11 @@
|
|||
namespace Friendica\Security;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
|
@ -100,6 +103,14 @@ class OAuth
|
|||
return [];
|
||||
}
|
||||
Logger::debug('Token found', $token);
|
||||
|
||||
User::updateLastActivity($token['uid']);
|
||||
|
||||
// Regularly update suggestions
|
||||
if (Contact\Relation::areSuggestionsOutdated($token['uid'])) {
|
||||
Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $token['uid']);
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class UpdateAllSuggestions
|
|||
{
|
||||
public static function execute()
|
||||
{
|
||||
$users = DBA::select('user', ['uid'], ["`login_date` > ?", DateTimeFormat::utc('now - 7 days')]);
|
||||
$users = DBA::select('user', ['uid'], ["`last-activity` > ?", DateTimeFormat::utc('now - 3 days', 'Y-m-d')]);
|
||||
while ($user = DBA::fetch($users)) {
|
||||
Contact\Relation::updateCachedSuggestions($user['uid']);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ return [
|
|||
"language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"],
|
||||
"register_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of registration"],
|
||||
"login_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last login"],
|
||||
"last-activity" => ["type" => "date", "comment" => "Day of the last activity"],
|
||||
"default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"],
|
||||
"allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"],
|
||||
"theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"],
|
||||
|
|
Loading…
Reference in a new issue