mirror of
https://github.com/flarum/framework.git
synced 2025-03-15 00:05:12 +08:00
fixed more attributes to match beta 8
This commit is contained in:
parent
44f8cef62a
commit
f1e5c11e1f
@ -84,7 +84,7 @@ class CreatePostController extends AbstractCreateController
|
||||
}
|
||||
|
||||
$discussion = $post->discussion;
|
||||
$discussion->posts = $discussion->posts()->whereVisibleTo($actor)->orderBy('time')->pluck('id');
|
||||
$discussion->posts = $discussion->posts()->whereVisibleTo($actor)->orderBy('created_at')->pluck('id');
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class BasicPostSerializer extends AbstractSerializer
|
||||
$attributes = [
|
||||
'id' => (int) $post->id,
|
||||
'number' => (int) $post->number,
|
||||
'time' => $this->formatDate($post->time),
|
||||
'time' => $this->formatDate($post->created_at),
|
||||
'contentType' => $post->type
|
||||
];
|
||||
|
||||
|
@ -14,16 +14,17 @@ namespace Flarum\Api\Serializer;
|
||||
class CurrentUserSerializer extends UserSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param \Flarum\User\User $user
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultAttributes($user)
|
||||
{
|
||||
$attributes = parent::getDefaultAttributes($user);
|
||||
|
||||
$attributes += [
|
||||
'isActivated' => (bool) $user->is_activated,
|
||||
'isActivated' => (bool) $user->is_email_confirmed,
|
||||
'email' => $user->email,
|
||||
'readTime' => $this->formatDate($user->read_time),
|
||||
'readTime' => $this->formatDate($user->read_notifications_at),
|
||||
'unreadNotificationsCount' => (int) $user->getUnreadNotificationsCount(),
|
||||
'newNotificationsCount' => (int) $user->getNewNotificationsCount(),
|
||||
'preferences' => (array) $user->preferences
|
||||
|
@ -57,8 +57,8 @@ class DiscussionSerializer extends BasicDiscussionSerializer
|
||||
|
||||
if ($state = $discussion->state) {
|
||||
$attributes += [
|
||||
'readTime' => $this->formatDate($state->read_time),
|
||||
'readNumber' => (int) $state->read_number
|
||||
'readTime' => $this->formatDate($state->last_read_at),
|
||||
'readNumber' => (int) $state->last_read_post_number
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -47,12 +47,13 @@ class NotificationSerializer extends AbstractSerializer
|
||||
'id' => (int) $notification->id,
|
||||
'contentType' => $notification->type,
|
||||
'content' => $notification->data,
|
||||
'time' => $this->formatDate($notification->time),
|
||||
'isRead' => (bool) $notification->is_read
|
||||
'time' => $this->formatDate($notification->created_at),
|
||||
'isRead' => (bool) $notification->read_at
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Notification $notification
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function user($notification)
|
||||
@ -61,6 +62,7 @@ class NotificationSerializer extends AbstractSerializer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Notification $notification
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function sender($notification)
|
||||
@ -69,6 +71,7 @@ class NotificationSerializer extends AbstractSerializer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Notification $notification
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function subject($notification)
|
||||
|
@ -55,13 +55,13 @@ class PostSerializer extends BasicPostSerializer
|
||||
$attributes['content'] = $post->content;
|
||||
}
|
||||
|
||||
if ($post->edit_time) {
|
||||
$attributes['editTime'] = $this->formatDate($post->edit_time);
|
||||
if ($post->edited_at) {
|
||||
$attributes['editTime'] = $this->formatDate($post->edited_at);
|
||||
}
|
||||
|
||||
if ($post->hide_time) {
|
||||
if ($post->hidden_at) {
|
||||
$attributes['isHidden'] = true;
|
||||
$attributes['hideTime'] = $this->formatDate($post->hide_time);
|
||||
$attributes['hideTime'] = $this->formatDate($post->hidden_at);
|
||||
}
|
||||
|
||||
$attributes += [
|
||||
|
@ -29,7 +29,8 @@ class UserSerializer extends BasicUserSerializer
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param \Flarum\User\User $user
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultAttributes($user)
|
||||
{
|
||||
@ -40,22 +41,22 @@ class UserSerializer extends BasicUserSerializer
|
||||
$canEdit = $gate->allows('edit', $user);
|
||||
|
||||
$attributes += [
|
||||
'joinTime' => $this->formatDate($user->join_time),
|
||||
'discussionsCount' => (int) $user->discussions_count,
|
||||
'commentsCount' => (int) $user->comments_count,
|
||||
'joinTime' => $this->formatDate($user->joined_at),
|
||||
'discussionsCount' => (int) $user->discussion_count,
|
||||
'commentsCount' => (int) $user->comment_count,
|
||||
'canEdit' => $canEdit,
|
||||
'canDelete' => $gate->allows('delete', $user),
|
||||
];
|
||||
|
||||
if ($user->getPreference('discloseOnline')) {
|
||||
$attributes += [
|
||||
'lastSeenTime' => $this->formatDate($user->last_seen_time)
|
||||
'lastSeenTime' => $this->formatDate($user->last_seen_at)
|
||||
];
|
||||
}
|
||||
|
||||
if ($canEdit || $this->actor->id === $user->id) {
|
||||
$attributes += [
|
||||
'isActivated' => (bool) $user->is_activated,
|
||||
'isActivated' => (bool) $user->is_email_confirmed,
|
||||
'email' => $user->email
|
||||
];
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class Discussion extends AbstractModel
|
||||
public function hide(User $actor = null)
|
||||
{
|
||||
if (! $this->hidden_at) {
|
||||
$this->hidden_at = time();
|
||||
$this->hidden_at = Carbon::now();
|
||||
$this->hidden_user_id = $actor ? $actor->id : null;
|
||||
|
||||
$this->raise(new Hidden($this));
|
||||
|
@ -92,7 +92,7 @@ class DiscussionPolicy extends AbstractPolicy
|
||||
// user, or the current user has permission to view hidden discussions.
|
||||
if (! $actor->hasPermission('discussion.hide')) {
|
||||
$query->where(function ($query) use ($actor) {
|
||||
$query->whereNull('discussions.hide_time')
|
||||
$query->whereNull('discussions.hidden_at')
|
||||
->orWhere('user_id', $actor->id)
|
||||
->orWhere(function ($query) use ($actor) {
|
||||
$this->events->fire(
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Discussion;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Discussion\Event\UserRead;
|
||||
use Flarum\Foundation\EventGeneratorTrait;
|
||||
@ -56,7 +57,7 @@ class UserState extends AbstractModel
|
||||
{
|
||||
if ($number > $this->last_read_at) {
|
||||
$this->last_read_at = $number;
|
||||
$this->last_read_at = time();
|
||||
$this->last_read_at = Carbon::now();
|
||||
|
||||
$this->raise(new UserRead($this));
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Http;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
|
||||
/**
|
||||
@ -47,7 +48,7 @@ class AccessToken extends AbstractModel
|
||||
|
||||
$token->id = str_random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->last_activity = time();
|
||||
$token->last_activity = Carbon::now();
|
||||
$token->lifetime = $lifetime;
|
||||
|
||||
return $token;
|
||||
@ -55,7 +56,7 @@ class AccessToken extends AbstractModel
|
||||
|
||||
public function touch()
|
||||
{
|
||||
$this->last_activity = time();
|
||||
$this->last_activity = Carbon::now();
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Http;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Dflydev\FigCookies\SetCookie;
|
||||
use Flarum\Foundation\Application;
|
||||
|
||||
@ -79,7 +80,7 @@ class CookieFactory
|
||||
if ($maxAge) {
|
||||
$cookie = $cookie
|
||||
->withMaxAge($maxAge)
|
||||
->withExpires(time() + $maxAge);
|
||||
->withExpires(Carbon::now()->timestamp + $maxAge);
|
||||
}
|
||||
|
||||
if ($this->domain != null) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Http\Middleware;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Http\AccessToken;
|
||||
use Flarum\User\AuthToken;
|
||||
use Flarum\User\EmailToken;
|
||||
@ -54,9 +55,11 @@ class CollectGarbage implements MiddlewareInterface
|
||||
return;
|
||||
}
|
||||
|
||||
AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete();
|
||||
$time = Carbon::now()->timestamp;
|
||||
|
||||
$earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60);
|
||||
AccessToken::whereRaw('last_activity <= ? - lifetime', [$time])->delete();
|
||||
|
||||
$earliestToKeep = date('Y-m-d H:i:s', $time - 24 * 60 * 60);
|
||||
|
||||
EmailToken::where('created_at', '<=', $earliestToKeep)->delete();
|
||||
PasswordToken::where('created_at', '<=', $earliestToKeep)->delete();
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Notification;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\User\User;
|
||||
|
||||
@ -70,7 +71,7 @@ class Notification extends AbstractModel
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$this->read_at = time();
|
||||
$this->read_at = Carbon::now();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Notification;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\User\User;
|
||||
|
||||
class NotificationRepository
|
||||
@ -53,6 +54,6 @@ class NotificationRepository
|
||||
*/
|
||||
public function markAllAsRead(User $user)
|
||||
{
|
||||
Notification::where('user_id', $user->id)->update(['read_at' => time()]);
|
||||
Notification::where('user_id', $user->id)->update(['read_at' => Carbon::now()]);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Flarum\Post\Command;
|
||||
|
||||
use DateTime;
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Discussion\DiscussionRepository;
|
||||
use Flarum\Foundation\DispatchEventsTrait;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
@ -77,7 +77,7 @@ class PostReplyHandler
|
||||
|
||||
// If this is the first post in the discussion, it's technically not a
|
||||
// "reply", so we won't check for that permission.
|
||||
if ($discussion->number_index > 0) {
|
||||
if ($discussion->post_number_index > 0) {
|
||||
$this->assertCan($actor, 'reply', $discussion);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ class PostReplyHandler
|
||||
);
|
||||
|
||||
if ($actor->isAdmin() && ($time = array_get($command->data, 'attributes.time'))) {
|
||||
$post->time = new DateTime($time);
|
||||
$post->created_at = new Carbon($time);
|
||||
}
|
||||
|
||||
$this->events->dispatch(
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Post;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Formatter\Formatter;
|
||||
use Flarum\Post\Event\Hidden;
|
||||
use Flarum\Post\Event\Posted;
|
||||
@ -51,7 +52,7 @@ class CommentPost extends Post
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
$post->created_at = time();
|
||||
$post->created_at = Carbon::now();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
$post->type = static::$type;
|
||||
@ -77,7 +78,7 @@ class CommentPost extends Post
|
||||
if ($this->content !== $content) {
|
||||
$this->content = $content;
|
||||
|
||||
$this->edited_at = time();
|
||||
$this->edited_at = Carbon::now();
|
||||
$this->edited_user_id = $actor->id;
|
||||
|
||||
$this->raise(new Revised($this));
|
||||
@ -95,7 +96,7 @@ class CommentPost extends Post
|
||||
public function hide(User $actor = null)
|
||||
{
|
||||
if (! $this->hidden_at) {
|
||||
$this->hidden_at = time();
|
||||
$this->hidden_at = Carbon::now();
|
||||
$this->hidden_user_id = $actor ? $actor->id : null;
|
||||
|
||||
$this->raise(new Hidden($this));
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Flarum\Post;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* A post which indicates that a discussion's title was changed.
|
||||
*
|
||||
@ -64,7 +66,7 @@ class DiscussionRenamedPost extends AbstractEventPost implements MergeableInterf
|
||||
$post = new static;
|
||||
|
||||
$post->content = static::buildContent($oldTitle, $newTitle);
|
||||
$post->time = time();
|
||||
$post->created_at = Carbon::now();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
|
||||
|
@ -57,7 +57,7 @@ class AuthToken extends AbstractModel
|
||||
|
||||
$token->token = str_random(40);
|
||||
$token->payload = $payload;
|
||||
$token->created_at = time();
|
||||
$token->created_at = Carbon::now();
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\User;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
||||
@ -55,7 +56,7 @@ class EmailToken extends AbstractModel
|
||||
$token->token = str_random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->email = $email;
|
||||
$token->created_at = time();
|
||||
$token->created_at = Carbon::now();
|
||||
|
||||
return $token;
|
||||
}
|
||||
@ -80,9 +81,10 @@ class EmailToken extends AbstractModel
|
||||
*/
|
||||
public function scopeValidOrFail($query, $id)
|
||||
{
|
||||
/** @var EmailToken $token */
|
||||
$token = $query->find($id);
|
||||
|
||||
if (! $token || $token->created_at < new DateTime('-1 day')) {
|
||||
if (! $token || $token->created_at->diffInDays() >= 1) {
|
||||
throw new InvalidConfirmationTokenException;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\User;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
|
||||
/**
|
||||
@ -54,7 +55,7 @@ class PasswordToken extends AbstractModel
|
||||
|
||||
$token->token = str_random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->created_at = time();
|
||||
$token->created_at = Carbon::now();
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\User;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DomainException;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Database\ScopeVisibilityTrait;
|
||||
@ -166,7 +167,7 @@ class User extends AbstractModel
|
||||
$user->username = $username;
|
||||
$user->email = $email;
|
||||
$user->password = $password;
|
||||
$user->joined_at = time();
|
||||
$user->joined_at = Carbon::now();
|
||||
|
||||
$user->raise(new Registered($user));
|
||||
|
||||
@ -270,7 +271,7 @@ class User extends AbstractModel
|
||||
*/
|
||||
public function markAllAsRead()
|
||||
{
|
||||
$this->marked_all_as_read_at = time();
|
||||
$this->marked_all_as_read_at = Carbon::now();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -282,7 +283,7 @@ class User extends AbstractModel
|
||||
*/
|
||||
public function markNotificationsAsRead()
|
||||
{
|
||||
$this->read_notifications_at = time();
|
||||
$this->read_notifications_at = Carbon::now();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -469,7 +470,7 @@ class User extends AbstractModel
|
||||
public function getNewNotificationsCount()
|
||||
{
|
||||
return $this->getUnreadNotifications()->filter(function ($notification) {
|
||||
return $notification->time > $this->read_notifications_at ?: 0;
|
||||
return $notification->created_at > $this->read_notifications_at ?: 0;
|
||||
})->count();
|
||||
}
|
||||
|
||||
@ -568,7 +569,7 @@ class User extends AbstractModel
|
||||
*/
|
||||
public function updateLastSeen()
|
||||
{
|
||||
$this->last_seen_at = time();
|
||||
$this->last_seen_at = Carbon::now();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user