Fix mark of forums and topic
This commit is contained in:
parent
49f7890a0b
commit
4efdcbdfde
3 changed files with 17 additions and 36 deletions
|
@ -52,7 +52,7 @@ class Forum extends Page
|
|||
if ($user->isGuest) {
|
||||
$sql = 'SELECT f.moderators, f.num_topics, f.sort_by, 0 AS is_subscribed FROM ::forums AS f WHERE f.id=?i:fid';
|
||||
} else {
|
||||
$sql = 'SELECT f.moderators, f.num_topics, f.sort_by, s.user_id AS is_subscribed, mof.mf_last_visit, mof.mf_mark_all_read FROM ::forums AS f LEFT JOIN ::forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id=?i:uid) LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND f.id=mof.fid) WHERE f.id=?i:fid';
|
||||
$sql = 'SELECT f.moderators, f.num_topics, f.sort_by, s.user_id AS is_subscribed, mof.mf_mark_all_read FROM ::forums AS f LEFT JOIN ::forum_subscriptions AS s ON (f.id=s.forum_id AND s.user_id=?i:uid) LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND f.id=mof.fid) WHERE f.id=?i:fid';
|
||||
}
|
||||
$curForum = $this->c->DB->query($sql, $vars)->fetch();
|
||||
|
||||
|
@ -131,7 +131,6 @@ class Forum extends Page
|
|||
}
|
||||
$topics = $this->c->DB->query($sql, $vars)->fetchAll();
|
||||
|
||||
$maxTime = 0;
|
||||
foreach ($topics as &$cur) {
|
||||
// цензура
|
||||
if ($this->config['o_censoring'] == '1') {
|
||||
|
@ -168,14 +167,13 @@ class Forum extends Page
|
|||
continue;
|
||||
}
|
||||
// новые сообщения
|
||||
if ($time > max($upper, $cur['mt_last_visit'])) {
|
||||
if ($time > max($upper, (int) $cur['mt_last_visit'])) {
|
||||
$cur['link_new'] = $this->c->Router->link('TopicGoToNew', ['id' => $cur['id']]);
|
||||
$maxTime = max($maxTime, $time);
|
||||
} else {
|
||||
$cur['link_new'] = null;
|
||||
}
|
||||
// не прочитанные сообщения
|
||||
if ($time > max($lower, $cur['mt_last_read'])) {
|
||||
if ($time > max($lower, (int) $cur['mt_last_read'])) {
|
||||
$cur['link_unread'] = $this->c->Router->link('TopicGoToUnread', ['id' => $cur['id']]);
|
||||
} else {
|
||||
$cur['link_unread'] = null;
|
||||
|
@ -184,20 +182,6 @@ class Forum extends Page
|
|||
$cur['dot'] = isset($dots[$cur['id']]);
|
||||
}
|
||||
unset($cur);
|
||||
|
||||
// изменение времени последнего посещения
|
||||
if ($maxTime > (int) $curForum['mf_last_visit']) {
|
||||
$vars = [
|
||||
':fid' => $args['id'],
|
||||
':uid' => $user->id,
|
||||
':tm' => $maxTime,
|
||||
];
|
||||
if (empty($curForum['mf_last_visit']) && empty($curForum['mf_mark_all_read'])) {
|
||||
$this->c->DB->exec('INSERT INTO ::mark_of_forum (uid, fid, mf_last_visit) SELECT ?i:uid, ?i:fid, ?i:tm FROM ::groups WHERE NOT EXISTS (SELECT 1 FROM ::mark_of_forum WHERE uid=?i:uid AND fid=?i:fid) LIMIT 1', $vars);
|
||||
} else {
|
||||
$this->c->DB->exec('UPDATE ::mark_of_forum SET mf_last_visit=?i:tm WHERE uid=?i:uid AND fid=?i:fid', $vars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$moders = empty($curForum['moderators']) ? [] : array_flip(unserialize($curForum['moderators']));
|
||||
|
|
|
@ -28,7 +28,7 @@ trait ForumsTrait
|
|||
if ($user->isGuest) {
|
||||
$stmt = $this->c->DB->query('SELECT id, forum_desc, moderators, num_topics, num_posts, last_post, last_post_id, last_poster, last_topic FROM ::forums WHERE id IN (?ai:forums)', $vars);
|
||||
} else {
|
||||
$stmt = $this->c->DB->query('SELECT f.id, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.last_topic, mof.mf_last_visit FROM ::forums AS f LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND f.id=mof.fid) WHERE f.id IN (?ai:forums)', $vars);
|
||||
$stmt = $this->c->DB->query('SELECT f.id, f.forum_desc, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster, f.last_topic, mof.mf_mark_all_read FROM ::forums AS f LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND f.id=mof.fid) WHERE f.id IN (?ai:forums)', $vars);
|
||||
}
|
||||
$forums = [];
|
||||
while ($cur = $stmt->fetch()) {
|
||||
|
@ -41,22 +41,22 @@ trait ForumsTrait
|
|||
// предварительная проверка разделов
|
||||
$max = max((int) $user->lastVisit, (int) $user->uMarkAllRead);
|
||||
foreach ($forums as $id => $cur) {
|
||||
$t = max($max, (int) $cur['mf_last_visit']);
|
||||
$t = max($max, (int) $cur['mf_mark_all_read']);
|
||||
if ($cur['last_post'] > $t) {
|
||||
$new[$id] = $t;
|
||||
}
|
||||
}
|
||||
// проверка по темам //???? возможно не нужна из-за mf_last_visit????
|
||||
// проверка по темам
|
||||
if (! empty($new)) {
|
||||
$vars = [
|
||||
':id' => $user->id,
|
||||
':forums' => array_keys($new),
|
||||
':max' => $max,
|
||||
];
|
||||
$stmt = $this->c->DB->query('SELECT t.forum_id, t.id, t.last_post FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:id AND mot.tid=t.id) WHERE t.forum_id IN(?ai:forums) AND t.last_post>?i:max AND t.moved_to IS NULL AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)', $vars);
|
||||
$stmt = $this->c->DB->query('SELECT t.forum_id, t.last_post FROM ::topics AS t LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:id AND mot.tid=t.id) WHERE t.forum_id IN(?ai:forums) AND t.last_post>?i:max AND t.moved_to IS NULL AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)', $vars);
|
||||
$tmp = [];
|
||||
while ($cur = $stmt->fetch()) {
|
||||
if ($cur['last_post']>$new[$cur['forum_id']]) {
|
||||
if ($cur['last_post'] > $new[$cur['forum_id']]) {
|
||||
$tmp[$cur['forum_id']] = true;
|
||||
}
|
||||
}
|
||||
|
@ -145,4 +145,4 @@ trait ForumsTrait
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -815,16 +815,14 @@ class Install extends Page
|
|||
// mark_of_forum
|
||||
$schema = [
|
||||
'FIELDS' => [
|
||||
'uid' => ['INT(10) UNSIGNED', true],
|
||||
'fid' => ['INT(10) UNSIGNED', true],
|
||||
'mf_last_visit' => ['INT(10) UNSIGNED', true],
|
||||
'mf_mark_all_read' => ['INT(10) UNSIGNED', true],
|
||||
'uid' => ['INT(10) UNSIGNED', false],
|
||||
'fid' => ['INT(10) UNSIGNED', false],
|
||||
'mf_mark_all_read' => ['INT(10) UNSIGNED', false, 0],
|
||||
],
|
||||
'UNIQUE KEYS' => [
|
||||
'uid_fid_idx' => ['uid', 'fid'],
|
||||
],
|
||||
'INDEXES' => [
|
||||
'mf_last_visit_idx' => ['mf_last_visit'],
|
||||
'mf_mark_all_read_idx' => ['mf_mark_all_read'],
|
||||
],
|
||||
'ENGINE' => $this->DBEngine,
|
||||
|
@ -833,14 +831,13 @@ class Install extends Page
|
|||
// mark_of_topic
|
||||
$schema = [
|
||||
'FIELDS' => [
|
||||
'uid' => ['INT(10) UNSIGNED', true],
|
||||
'fid' => ['INT(10) UNSIGNED', true], //????
|
||||
'tid' => ['INT(10) UNSIGNED', true],
|
||||
'mt_last_visit' => ['INT(10) UNSIGNED', true],
|
||||
'mt_last_read' => ['INT(10) UNSIGNED', true],
|
||||
'uid' => ['INT(10) UNSIGNED', false],
|
||||
'tid' => ['INT(10) UNSIGNED', false],
|
||||
'mt_last_visit' => ['INT(10) UNSIGNED', false, 0],
|
||||
'mt_last_read' => ['INT(10) UNSIGNED', false, 0],
|
||||
],
|
||||
'UNIQUE KEYS' => [
|
||||
'uid_fid_tid_idx' => ['uid', 'fid', 'tid'],
|
||||
'uid_tid_idx' => ['uid', 'tid'],
|
||||
],
|
||||
'INDEXES' => [
|
||||
'mt_last_visit_idx' => ['mt_last_visit'],
|
||||
|
|
Loading…
Reference in a new issue