diff --git a/Sources/Post.php b/Sources/Post.php
index 7c6867c..55b3954 100644
--- a/Sources/Post.php
+++ b/Sources/Post.php
@@ -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.
diff --git a/Sources/Recent.php b/Sources/Recent.php
index b869efd..1ef859d 100644
--- a/Sources/Recent.php
+++ b/Sources/Recent.php
@@ -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
diff --git a/Themes/default/Recent.template.php b/Themes/default/Recent.template.php
index 91302f6..03263a9 100644
--- a/Themes/default/Recent.template.php
+++ b/Themes/default/Recent.template.php
@@ -228,7 +228,7 @@ function template_replies()
' . $topic['pages'] . '
-