From 0049e0d6081c2a6f527cbc4576e020f44932dc9c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 24 Aug 2018 20:53:28 +0930 Subject: [PATCH] Rename discussion.readNumber --- framework/core/js/src/common/models/Discussion.js | 4 ++-- .../core/js/src/forum/components/DiscussionListItem.js | 4 ++-- framework/core/js/src/forum/components/DiscussionPage.js | 4 ++-- .../src/Api/Controller/UpdateDiscussionController.php | 2 +- .../core/src/Api/Serializer/DiscussionSerializer.php | 2 +- framework/core/src/Discussion/Command/ReadDiscussion.php | 8 ++++---- .../core/src/Discussion/Command/ReadDiscussionHandler.php | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/framework/core/js/src/common/models/Discussion.js b/framework/core/js/src/common/models/Discussion.js index 9c12ee1ed..6b8f4a8f2 100644 --- a/framework/core/js/src/common/models/Discussion.js +++ b/framework/core/js/src/common/models/Discussion.js @@ -24,7 +24,7 @@ Object.assign(Discussion.prototype, { mostRelevantPost: Model.hasOne('mostRelevantPost'), lastReadAt: Model.attribute('lastReadAt', Model.transformDate), - readNumber: Model.attribute('readNumber'), + lastReadPostNumber: Model.attribute('lastReadPostNumber'), isUnread: computed('unreadCount', unreadCount => !!unreadCount), isRead: computed('unreadCount', unreadCount => app.session.user && !unreadCount), @@ -68,7 +68,7 @@ Object.assign(Discussion.prototype, { const user = app.session.user; if (user && user.readTime() < this.lastPostedAt()) { - return Math.max(0, this.lastPostNumber() - (this.readNumber() || 0)); + return Math.max(0, this.lastPostNumber() - (this.lastReadPostNumber() || 0)); } return 0; diff --git a/framework/core/js/src/forum/components/DiscussionListItem.js b/framework/core/js/src/forum/components/DiscussionListItem.js index 84ce4cf37..849eedd45 100644 --- a/framework/core/js/src/forum/components/DiscussionListItem.js +++ b/framework/core/js/src/forum/components/DiscussionListItem.js @@ -75,7 +75,7 @@ export default class DiscussionListItem extends Component { const phrase = this.props.params.q; this.highlightRegExp = new RegExp(phrase+'|'+phrase.trim().replace(/\s+/g, '|'), 'gi'); } else { - jumpTo = Math.min(discussion.lastPostNumber(), (discussion.readNumber() || 0) + 1); + jumpTo = Math.min(discussion.lastPostNumber(), (discussion.lastReadPostNumber() || 0) + 1); } return ( @@ -177,7 +177,7 @@ export default class DiscussionListItem extends Component { const discussion = this.props.discussion; if (discussion.isUnread()) { - discussion.save({readNumber: discussion.lastPostNumber()}); + discussion.save({lastReadPostNumber: discussion.lastPostNumber()}); m.redraw(); } } diff --git a/framework/core/js/src/forum/components/DiscussionPage.js b/framework/core/js/src/forum/components/DiscussionPage.js index b03b87a74..edfda8523 100644 --- a/framework/core/js/src/forum/components/DiscussionPage.js +++ b/framework/core/js/src/forum/components/DiscussionPage.js @@ -288,8 +288,8 @@ export default class DiscussionPage extends Page { // If the user hasn't read past here before, then we'll update their read // state and redraw. - if (app.session.user && endNumber > (discussion.readNumber() || 0)) { - discussion.save({readNumber: endNumber}); + if (app.session.user && endNumber > (discussion.lastReadPostNumber() || 0)) { + discussion.save({lastReadPostNumber: endNumber}); m.redraw(); } } diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 68e196e21..5cf67a5d5 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -54,7 +54,7 @@ class UpdateDiscussionController extends AbstractShowController // TODO: Refactor the ReadDiscussion (state) command into EditDiscussion? // That's what extensions will do anyway. - if ($readNumber = array_get($data, 'attributes.readNumber')) { + if ($readNumber = array_get($data, 'attributes.lastReadPostNumber')) { $state = $this->bus->dispatch( new ReadDiscussion($discussionId, $actor, $readNumber) ); diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 238ba572a..09e8b1256 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -58,7 +58,7 @@ class DiscussionSerializer extends BasicDiscussionSerializer if ($state = $discussion->state) { $attributes += [ 'lastReadAt' => $this->formatDate($state->last_read_at), - 'readNumber' => (int) $state->last_read_post_number + 'lastReadPostNumber' => (int) $state->last_read_post_number ]; } diff --git a/framework/core/src/Discussion/Command/ReadDiscussion.php b/framework/core/src/Discussion/Command/ReadDiscussion.php index c6a8826e3..27a2fce9a 100644 --- a/framework/core/src/Discussion/Command/ReadDiscussion.php +++ b/framework/core/src/Discussion/Command/ReadDiscussion.php @@ -34,17 +34,17 @@ class ReadDiscussion * * @var int */ - public $readNumber; + public $lastReadPostNumber; /** * @param int $discussionId The ID of the discussion to mark as read. * @param User $actor The user to mark the discussion as read for. - * @param int $readNumber The number of the post to mark as read. + * @param int $lastReadPostNumber The number of the post to mark as read. */ - public function __construct($discussionId, User $actor, $readNumber) + public function __construct($discussionId, User $actor, $lastReadPostNumber) { $this->discussionId = $discussionId; $this->actor = $actor; - $this->readNumber = $readNumber; + $this->lastReadPostNumber = $lastReadPostNumber; } } diff --git a/framework/core/src/Discussion/Command/ReadDiscussionHandler.php b/framework/core/src/Discussion/Command/ReadDiscussionHandler.php index d29529b1e..9aad6ab92 100644 --- a/framework/core/src/Discussion/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/ReadDiscussionHandler.php @@ -51,7 +51,7 @@ class ReadDiscussionHandler $discussion = $this->discussions->findOrFail($command->discussionId, $actor); $state = $discussion->stateFor($actor); - $state->read($command->readNumber); + $state->read($command->lastReadPostNumber); $this->events->dispatch( new UserDataSaving($state)