initial work on topic watch feature: users can stop watching it, but there's no way to start watching unwatched topic

This commit is contained in:
Aleksei Miheev
2012-06-01 03:16:48 +04:00
parent b0ca07531a
commit 808df9462d
4 changed files with 52 additions and 2 deletions

View File

@@ -1346,6 +1346,8 @@ function Post2()
$topic = db_insert_id();
if ($topic > 0)
{
// Start watching topic
db_query("INSERT IGNORE {$db_prefix}watch_topics(ID_MEMBER,ID_TOPIC) VALUES($ID_MEMBER,$topic);", __FILE__, __LINE__);
// Fix the message with the topic.
db_query("
UPDATE {$db_prefix}messages
@@ -1390,6 +1392,10 @@ function Post2()
'$user_info[ip]', " . (isset($_POST['ns']) ? '0' : '1') . ", '$_POST[message]', '$_POST[icon]')", __FILE__, __LINE__);
$ID_MSG = db_insert_id();
// If this is the first time user replies in this topic,
// he'll start watching it.
db_query("INSERT IGNORE {$db_prefix}watch_topics(ID_MEMBER,ID_TOPIC) VALUES($ID_MEMBER,$topic);", __FILE__, __LINE__);
if ($ID_MSG > 0)
{
// If attachments were added, update the table now we know the message ID.

View File

@@ -128,7 +128,48 @@ function getLastPosts($showlatestcount)
return $posts;
}
// Watch topic updates
function WatchTopic()
{
global $txt, $scripturl, $db_prefix, $user_info, $context, $ID_MEMBER, $modSettings, $sourcedir;
if ( ! (isset ($_GET['id_topic']) AND ctype_digit($_GET['id_topic']))) {
redirectexit('');
}
$r = db_query("SELECT * FROM {$db_prefix}topics WHERE ID_TOPIC={$_GET['id_topic']}", __FILE__, __LINE__);
// somebody uncool passed non-existent topic ID
if (mysql_num_rows($r) != 1) {
redirectexit('');
}
// Okay, the topic exists, start watching it
db_query("REPLACE INTO {$db_prefix}watch_topics VALUES('$ID_MEMBER','{$_GET['id_topic']}',1);", __FILE__, __LINE__);
$return = isset($_GET['return']) ? urldecode($_GET['return']) : '';
redirectexit($return);
}
// Stop watching topic updates
function UnwatchTopic()
{
global $txt, $scripturl, $db_prefix, $user_info, $context, $ID_MEMBER, $modSettings, $sourcedir;
if ( ! (isset ($_GET['id_topic']) AND ctype_digit($_GET['id_topic']))) {
redirectexit('');
}
$r = db_query("SELECT * FROM {$db_prefix}topics WHERE ID_TOPIC={$_GET['id_topic']}", __FILE__, __LINE__);
// somebody uncool passed non-existent topic ID
if (mysql_num_rows($r) != 1) {
redirectexit('');
}
// Okay, the topic exists, remove topic from watch list
db_query("REPLACE INTO {$db_prefix}watch_topics VALUES('$ID_MEMBER','{$_GET['id_topic']}',0);", __FILE__, __LINE__);
$return = isset($_GET['return']) ? urldecode($_GET['return']) : '';
redirectexit($return);
}
// Find the ten most recent posts.
function RecentPosts()
{
@@ -455,10 +496,11 @@ function UnreadTopics()
$request = db_query("
SELECT DISTINCT t.ID_TOPIC
FROM ({$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ml, {$db_prefix}messages AS m)
FROM ({$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ml, {$db_prefix}messages AS m, {$db_prefix}watch_topics as w)
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)
WHERE ml.ID_MEMBER != $ID_MEMBER
AND w.ID_TOPIC=t.ID_TOPIC AND w.ID_MEMBER=$ID_MEMBER AND w.watch=1
AND m.ID_TOPIC = t.ID_TOPIC
AND m.ID_MEMBER = $ID_MEMBER
AND ml.ID_MSG = t.ID_LAST_MSG

View File

@@ -228,7 +228,7 @@ function template_replies()
<img src="' . $settings['images_url'] . '/post/' . $topic['first_post']['icon'] . '.gif" alt="" border="0" align="middle" /></td>
<td class="windowbg" valign="middle" width="48%">
' . $topic['first_post']['link'] . ' <a href="' . $scripturl . '?topic=' . $topic['id'] . '.from' . $topic['newtime'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a> <span class="smalltext">' . $topic['pages'] . '</span>
<div class="smalltext"><i>' . $txt['smf88'] . ' ' . $topic['board']['link'] . '</i></div></td>
<div class="smalltext"><i>' . $txt['smf88'] . ' ' . $topic['board']['link'] . '</i><div style="float: right;"><a style="color: gray;" href="'.$scripturl.'?action=unwatch;id_topic='.$topic['id'].';return='.urlencode($_SERVER['QUERY_STRING']).'">Не следить</a></div></div></td>
<td class="windowbg" valign="middle" width="4%" align="center">
' . $topic['replies']. '</td>
<td class="windowbg2" valign="middle" width="22%">';

View File

@@ -330,6 +330,8 @@ function smf_main()
'warnlist2' => array('VisualWarning.php', 'ListWarnings2'),
'warnpmman' => array('VisualWarning.php', 'Manager'),
'warnpmman2' => array('VisualWarning.php', 'Manager2'),
'watch' => array('Recent.php', 'WatchTopic'),
'unwatch' => array('Recent.php', 'UnwatchTopic'),
'who' => array('Who.php', 'Who'),
'.kml' => array('GoogleMap.php', 'ShowKML'),
'.xml' => array('News.php', 'ShowXmlFeed'),