From 8323d2a72be93a9f27239e582845afb1e82ef8f8 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 10 Feb 2015 17:48:58 +1030 Subject: [PATCH] API for marking all as read --- framework/core/src/Flarum/Api/Serializers/UserSerializer.php | 1 + .../core/src/Flarum/Core/Users/Commands/EditUserCommand.php | 2 ++ .../src/Flarum/Core/Users/Commands/EditUserCommandHandler.php | 4 ++++ framework/core/src/Flarum/Core/Users/User.php | 2 +- .../src/migrations/2014_01_14_231404_create_users_table.php | 1 + framework/core/src/routes.php | 2 +- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Flarum/Api/Serializers/UserSerializer.php b/framework/core/src/Flarum/Api/Serializers/UserSerializer.php index f98601e0a..49c871fcd 100644 --- a/framework/core/src/Flarum/Api/Serializers/UserSerializer.php +++ b/framework/core/src/Flarum/Api/Serializers/UserSerializer.php @@ -29,6 +29,7 @@ class UserSerializer extends UserBasicSerializer $attributes += [ 'joinTime' => $user->join_time ? $user->join_time->toRFC3339String() : null, 'lastSeenTime' => $user->last_seen_time ? $user->last_seen_time->toRFC3339String() : null, + 'readTime' => $user->read_time ? $user->read_time->toRFC3339String() : null, 'discussionsCount' => (int) $user->discussions_count, 'postsCount' => (int) $user->posts_count, 'canEdit' => $user->permission('edit'), diff --git a/framework/core/src/Flarum/Core/Users/Commands/EditUserCommand.php b/framework/core/src/Flarum/Core/Users/Commands/EditUserCommand.php index 7592fb016..64d260dad 100644 --- a/framework/core/src/Flarum/Core/Users/Commands/EditUserCommand.php +++ b/framework/core/src/Flarum/Core/Users/Commands/EditUserCommand.php @@ -12,6 +12,8 @@ class EditUserCommand public $password; + public $readTime; + public function __construct($userId, $user) { $this->userId = $userId; diff --git a/framework/core/src/Flarum/Core/Users/Commands/EditUserCommandHandler.php b/framework/core/src/Flarum/Core/Users/Commands/EditUserCommandHandler.php index 17dc3d74c..498408ae2 100644 --- a/framework/core/src/Flarum/Core/Users/Commands/EditUserCommandHandler.php +++ b/framework/core/src/Flarum/Core/Users/Commands/EditUserCommandHandler.php @@ -36,6 +36,10 @@ class EditUserCommandHandler implements CommandHandler $userToEdit->password = $command->password; } + if (! empty($command->readTime)) { + $userToEdit->read_time = time(); + } + Event::fire('Flarum.Core.Users.Commands.EditUser.UserWillBeSaved', [$userToEdit, $command]); $this->userRepo->save($userToEdit); diff --git a/framework/core/src/Flarum/Core/Users/User.php b/framework/core/src/Flarum/Core/Users/User.php index 3c60a1c97..2ad7cf893 100755 --- a/framework/core/src/Flarum/Core/Users/User.php +++ b/framework/core/src/Flarum/Core/Users/User.php @@ -93,7 +93,7 @@ class User extends Entity implements UserInterface, RemindableInterface public function getDates() { - return ['join_time', 'last_seen_time']; + return ['join_time', 'last_seen_time', 'read_time']; } public function getAvatarUrlAttribute() diff --git a/framework/core/src/migrations/2014_01_14_231404_create_users_table.php b/framework/core/src/migrations/2014_01_14_231404_create_users_table.php index 6ebfb562e..9d7d7e42a 100644 --- a/framework/core/src/migrations/2014_01_14_231404_create_users_table.php +++ b/framework/core/src/migrations/2014_01_14_231404_create_users_table.php @@ -22,6 +22,7 @@ class CreateUsersTable extends Migration { $table->dateTime('join_time'); $table->string('time_zone'); $table->dateTime('last_seen_time')->nullable(); + $table->dateTime('read_time')->nullable(); $table->integer('discussions_count')->unsigned()->default(0); $table->integer('posts_count')->unsigned()->default(0); }); diff --git a/framework/core/src/routes.php b/framework/core/src/routes.php index 9700caccf..76042fd64 100755 --- a/framework/core/src/routes.php +++ b/framework/core/src/routes.php @@ -4,4 +4,4 @@ Route::get('/', function() { return View::make('flarum.web::index') ->with('title', Config::get('flarum::forum_title', 'Flarum Demo Forum')); -}); \ No newline at end of file +});