Browse Source

! A little rejig and we can show from the message index what topics are being watched - and also begin to introduce this terminology properly.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
0afa1dc33d

+ 1 - 1
Sources/Display.php

@@ -1178,7 +1178,7 @@ function Display()
 	$context['normal_buttons'] = array(
 		'reply' => array('test' => 'can_reply', 'text' => 'reply', 'image' => 'reply.png', 'lang' => true, 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true),
 		'add_poll' => array('test' => 'can_add_poll', 'text' => 'add_poll', 'image' => 'add_poll.png', 'lang' => true, 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']),
-		'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unnotify' : 'notify', 'image' => ($context['is_marked_notify'] ? 'un' : '') . 'notify.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
+		'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unwatch_topic' : 'watch_topic', 'image' => ($context['is_marked_notify'] ? 'un' : '') . 'notify.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');"', 'url' => $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
 		'mark_unread' => array('test' => 'can_mark_unread', 'text' => 'mark_unread', 'image' => 'markunread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
 		'unwatch' => array('test' => 'can_unwatch', 'text' => ($context['topic_unwatched'] ? '' : 'un') . 'watch', 'image' => ($context['topic_unwatched'] ? 'un' : '') . 'watch.png', 'lang' => true, 'url' => $scripturl . '?action=unwatchtopic;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['topic_unwatched'] ? 'off' : 'on') . ';' . $context['session_var'] . '=' . $context['session_id']),
 		'print' => array('test' => 'can_print', 'text' => 'print', 'image' => 'print.png', 'lang' => true, 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'),

+ 90 - 77
Sources/MessageIndex.php

@@ -45,6 +45,18 @@ function MessageIndex()
 	else
 		loadTemplate('MessageIndex');
 
+	if (!$user_info['is_guest'])
+	{
+		// We can't know they read it if we allow prefetches.
+		// But we'll actually mark it read later after we've done everything else.
+		if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
+		{
+			ob_end_clean();
+			header('HTTP/1.1 403 Prefetch Forbidden');
+			die;
+		}
+	}
+
 	$context['name'] = $board_info['name'];
 	$context['description'] = $board_info['description'];
 	if (!empty($board_info['description']))
@@ -139,82 +151,6 @@ function MessageIndex()
 	 	$context['linktree'][count($context['linktree']) - 1]['extra_after'] = '<span class="board_moderators">(' . (count($context['link_moderators']) == 1 ? $txt['moderator'] : $txt['moderators']) . ': ' . implode(', ', $context['link_moderators']) . ')</span>';
 	}
 
-	// Mark current and parent boards as seen.
-	if (!$user_info['is_guest'])
-	{
-		// We can't know they read it if we allow prefetches.
-		if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
-		{
-			ob_end_clean();
-			header('HTTP/1.1 403 Prefetch Forbidden');
-			die;
-		}
-
-		$smcFunc['db_insert']('replace',
-			'{db_prefix}log_boards',
-			array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
-			array($modSettings['maxMsgID'], $user_info['id'], $board),
-			array('id_member', 'id_board')
-		);
-
-		if (!empty($board_info['parent_boards']))
-		{
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}log_boards
-				SET id_msg = {int:id_msg}
-				WHERE id_member = {int:current_member}
-					AND id_board IN ({array_int:board_list})',
-				array(
-					'current_member' => $user_info['id'],
-					'board_list' => array_keys($board_info['parent_boards']),
-					'id_msg' => $modSettings['maxMsgID'],
-				)
-			);
-
-			// We've seen all these boards now!
-			foreach ($board_info['parent_boards'] as $k => $dummy)
-				if (isset($_SESSION['topicseen_cache'][$k]))
-					unset($_SESSION['topicseen_cache'][$k]);
-		}
-
-		if (isset($_SESSION['topicseen_cache'][$board]))
-			unset($_SESSION['topicseen_cache'][$board]);
-
-		$request = $smcFunc['db_query']('', '
-			SELECT sent
-			FROM {db_prefix}log_notify
-			WHERE id_board = {int:current_board}
-				AND id_member = {int:current_member}
-			LIMIT 1',
-			array(
-				'current_board' => $board,
-				'current_member' => $user_info['id'],
-			)
-		);
-		$context['is_marked_notify'] = $smcFunc['db_num_rows']($request) != 0;
-		if ($context['is_marked_notify'])
-		{
-			list ($sent) = $smcFunc['db_fetch_row']($request);
-			if (!empty($sent))
-			{
-				$smcFunc['db_query']('', '
-					UPDATE {db_prefix}log_notify
-					SET sent = {int:is_sent}
-					WHERE id_board = {int:current_board}
-						AND id_member = {int:current_member}',
-					array(
-						'current_board' => $board,
-						'current_member' => $user_info['id'],
-						'is_sent' => 0,
-					)
-				);
-			}
-		}
-		$smcFunc['db_free_result']($request);
-	}
-	else
-		$context['is_marked_notify'] = false;
-
 	// 'Print' the header and board info.
 	$context['page_title'] = strip_tags($board_info['name']);
 
@@ -549,6 +485,7 @@ function MessageIndex()
 				'is_redirect' => !empty($row['id_redirect_topic']),
 				'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
 				'is_posted_in' => false,
+				'is_watched' => false,
 				'icon' => $row['first_icon'],
 				'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png',
 				'subject' => $row['first_subject'],
@@ -658,6 +595,82 @@ function MessageIndex()
 		call_integration_hook('integrate_quick_mod_actions');
 	}
 
+	// Mark current and parent boards as seen.
+	if (!$user_info['is_guest'])
+	{
+		$smcFunc['db_insert']('replace',
+			'{db_prefix}log_boards',
+			array('id_msg' => 'int', 'id_member' => 'int', 'id_board' => 'int'),
+			array($modSettings['maxMsgID'], $user_info['id'], $board),
+			array('id_member', 'id_board')
+		);
+
+		if (!empty($board_info['parent_boards']))
+		{
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}log_boards
+				SET id_msg = {int:id_msg}
+				WHERE id_member = {int:current_member}
+					AND id_board IN ({array_int:board_list})',
+				array(
+					'current_member' => $user_info['id'],
+					'board_list' => array_keys($board_info['parent_boards']),
+					'id_msg' => $modSettings['maxMsgID'],
+				)
+			);
+
+			// We've seen all these boards now!
+			foreach ($board_info['parent_boards'] as $k => $dummy)
+				if (isset($_SESSION['topicseen_cache'][$k]))
+					unset($_SESSION['topicseen_cache'][$k]);
+		}
+
+		if (isset($_SESSION['topicseen_cache'][$board]))
+			unset($_SESSION['topicseen_cache'][$board]);
+
+		$request = $smcFunc['db_query']('', '
+			SELECT id_topic, id_board, sent
+			FROM {db_prefix}log_notify
+			WHERE id_member = {int:current_member}
+				AND (' . (!empty($context['topics']) ? 'id_topic IN ({array_int:topics}) OR ' : '') . 'id_board = {int:current_board})',
+			array(
+				'current_board' => $board,
+				'topics' => !empty($context['topics']) ? array_keys($context['topics']) : array(),
+				'current_member' => $user_info['id'],
+			)
+		);
+		$context['is_marked_notify'] = false; // this is for the *board* only
+		$notify = array();
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+		{
+			if (!empty($row['id_board']))
+			{
+				$context['is_marked_notify'] = true;
+				$board_sent = $row['sent'];
+			}
+			if (!empty($row['id_topic']))
+				$context['topics'][$row['id_topic']]['is_watched'] = true;
+		}
+		$smcFunc['db_free_result']($request);
+
+		if ($context['is_marked_notify'] && !empty($board_sent))
+		{
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}log_notify
+				SET sent = {int:is_sent}
+				WHERE id_member = {int:current_member}
+					AND id_board = {int:current_board}',
+				array(
+					'current_board' => $board,
+					'current_member' => $user_info['id'],
+					'is_sent' => 0,
+				)
+			);
+		}
+	}
+	else
+		$context['is_marked_notify'] = false;
+
 	// If there are children, but no topics and no ability to post topics...
 	$context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new'];
 
@@ -665,7 +678,7 @@ function MessageIndex()
 	$context['normal_buttons'] = array(
 		'new_topic' => array('test' => 'can_post_new', 'text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true),
 		'post_poll' => array('test' => 'can_post_poll', 'text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'),
-		'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unnotify' : 'notify', 'image' => ($context['is_marked_notify'] ? 'un' : ''). 'notify.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']) . '\');"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
+		'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unwatch_board' : 'watch_board', 'image' => ($context['is_marked_notify'] ? 'un' : ''). 'notify.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']) . '\');"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
 		'markread' => array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_mark_read'] . '\');"', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']),
 	);
 

+ 3 - 0
Themes/default/MessageIndex.template.php

@@ -250,6 +250,9 @@ function template_main()
 			// Now we handle the icons
 			echo '
 							<div class="icons">';
+			if ($topic['is_watched'])
+				echo '
+								<span class="generic_icons watch floatright" title="', $txt['watching_this_topic'], '"></span>';
 			if ($topic['is_locked'])
 				echo '
 								<span class="generic_icons lock floatright"></span>';

+ 6 - 0
Themes/default/css/index.css

@@ -3101,6 +3101,12 @@ tr.windowbg td, tr.windowbg2 td, tr.highlight2 td {
 .generic_icons.split_sel {
 	background-position: -112px -64px;
 }
+.generic_icons.watch {
+	background-position: 0px -80px;
+}
+.generic_icons.filter {
+	background-position: -16px -80px;
+}
 
 /* Styles for (fatal) errors.
 ------------------------------------------------- */

BIN
Themes/default/images/generic_icons.png


+ 5 - 0
Themes/default/languages/index.english.php

@@ -123,6 +123,11 @@ $txt['admin_login'] = 'Administration Login';
 $txt['topic'] = 'Topic';
 $txt['help'] = 'Help';
 $txt['terms_and_rules'] = 'Terms and Rules';
+$txt['watch_board'] = 'Watch this Board';
+$txt['unwatch_board'] = 'Stop Watching Board';
+$txt['watch_topic'] = 'Watch this Topic';
+$txt['unwatch_topic'] = 'Stop Watching Topic';
+$txt['watching_this_topic'] = 'You are watching this topic, and will receive notifications about it.';
 $txt['notify'] = 'Notify';
 $txt['unnotify'] = 'Unnotify';
 $txt['notify_request'] = 'Do you want a notification email if someone replies to this topic?';