mirror of
https://github.com/flarum/core.git
synced 2025-07-17 06:41:21 +02:00
Rename discussion.readNumber
This commit is contained in:
@@ -24,7 +24,7 @@ Object.assign(Discussion.prototype, {
|
|||||||
mostRelevantPost: Model.hasOne('mostRelevantPost'),
|
mostRelevantPost: Model.hasOne('mostRelevantPost'),
|
||||||
|
|
||||||
lastReadAt: Model.attribute('lastReadAt', Model.transformDate),
|
lastReadAt: Model.attribute('lastReadAt', Model.transformDate),
|
||||||
readNumber: Model.attribute('readNumber'),
|
lastReadPostNumber: Model.attribute('lastReadPostNumber'),
|
||||||
isUnread: computed('unreadCount', unreadCount => !!unreadCount),
|
isUnread: computed('unreadCount', unreadCount => !!unreadCount),
|
||||||
isRead: computed('unreadCount', unreadCount => app.session.user && !unreadCount),
|
isRead: computed('unreadCount', unreadCount => app.session.user && !unreadCount),
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ Object.assign(Discussion.prototype, {
|
|||||||
const user = app.session.user;
|
const user = app.session.user;
|
||||||
|
|
||||||
if (user && user.readTime() < this.lastPostedAt()) {
|
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;
|
return 0;
|
||||||
|
@@ -75,7 +75,7 @@ export default class DiscussionListItem extends Component {
|
|||||||
const phrase = this.props.params.q;
|
const phrase = this.props.params.q;
|
||||||
this.highlightRegExp = new RegExp(phrase+'|'+phrase.trim().replace(/\s+/g, '|'), 'gi');
|
this.highlightRegExp = new RegExp(phrase+'|'+phrase.trim().replace(/\s+/g, '|'), 'gi');
|
||||||
} else {
|
} else {
|
||||||
jumpTo = Math.min(discussion.lastPostNumber(), (discussion.readNumber() || 0) + 1);
|
jumpTo = Math.min(discussion.lastPostNumber(), (discussion.lastReadPostNumber() || 0) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -177,7 +177,7 @@ export default class DiscussionListItem extends Component {
|
|||||||
const discussion = this.props.discussion;
|
const discussion = this.props.discussion;
|
||||||
|
|
||||||
if (discussion.isUnread()) {
|
if (discussion.isUnread()) {
|
||||||
discussion.save({readNumber: discussion.lastPostNumber()});
|
discussion.save({lastReadPostNumber: discussion.lastPostNumber()});
|
||||||
m.redraw();
|
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
|
// If the user hasn't read past here before, then we'll update their read
|
||||||
// state and redraw.
|
// state and redraw.
|
||||||
if (app.session.user && endNumber > (discussion.readNumber() || 0)) {
|
if (app.session.user && endNumber > (discussion.lastReadPostNumber() || 0)) {
|
||||||
discussion.save({readNumber: endNumber});
|
discussion.save({lastReadPostNumber: endNumber});
|
||||||
m.redraw();
|
m.redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ class UpdateDiscussionController extends AbstractShowController
|
|||||||
|
|
||||||
// TODO: Refactor the ReadDiscussion (state) command into EditDiscussion?
|
// TODO: Refactor the ReadDiscussion (state) command into EditDiscussion?
|
||||||
// That's what extensions will do anyway.
|
// 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(
|
$state = $this->bus->dispatch(
|
||||||
new ReadDiscussion($discussionId, $actor, $readNumber)
|
new ReadDiscussion($discussionId, $actor, $readNumber)
|
||||||
);
|
);
|
||||||
|
@@ -58,7 +58,7 @@ class DiscussionSerializer extends BasicDiscussionSerializer
|
|||||||
if ($state = $discussion->state) {
|
if ($state = $discussion->state) {
|
||||||
$attributes += [
|
$attributes += [
|
||||||
'lastReadAt' => $this->formatDate($state->last_read_at),
|
'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
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $readNumber;
|
public $lastReadPostNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $discussionId The ID of the discussion to mark as read.
|
* @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 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->discussionId = $discussionId;
|
||||||
$this->actor = $actor;
|
$this->actor = $actor;
|
||||||
$this->readNumber = $readNumber;
|
$this->lastReadPostNumber = $lastReadPostNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ class ReadDiscussionHandler
|
|||||||
$discussion = $this->discussions->findOrFail($command->discussionId, $actor);
|
$discussion = $this->discussions->findOrFail($command->discussionId, $actor);
|
||||||
|
|
||||||
$state = $discussion->stateFor($actor);
|
$state = $discussion->stateFor($actor);
|
||||||
$state->read($command->readNumber);
|
$state->read($command->lastReadPostNumber);
|
||||||
|
|
||||||
$this->events->dispatch(
|
$this->events->dispatch(
|
||||||
new UserDataSaving($state)
|
new UserDataSaving($state)
|
||||||
|
Reference in New Issue
Block a user