mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 06:24:53 +08:00
Rename discussion.readNumber
This commit is contained in:
parent
d031fc76bd
commit
0049e0d608
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
|
@ -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
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user