Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions forum/qa-include/lang/qa-lang-question.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
'flag_button' => 'flag',
'flag_c_popup' => 'Flag this comment as spam or inappropriate',
'flag_hide_button' => 'flag and hide',

'mute_button' => 'Mute thread',
'mute_popup' => 'Mute this thread to not receive any further notifications',
'unmute_button' => 'Unmute thread',
'unmute_popup' => 'Unmute this thread to receive notifications again',

'flag_limit' => 'Too many posts flagged - please try again in an hour',
'flag_must_confirm' => 'Please ^5confirm your email address^6 to flag posts.',
'flag_must_login' => 'Please ^1log in^2 or ^3register^4 to flag posts.',
Expand Down
23 changes: 23 additions & 0 deletions forum/qa-include/pages/question-submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function qa_page_q_single_click_q($question, $answers, $commentsfollows, $closep
{
require_once QA_INCLUDE_DIR.'app/post-update.php';
require_once QA_INCLUDE_DIR.'app/limits.php';
require_once QA_PLUGIN_DIR.'/q2apro-on-site-notifications/utils.php';

$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
Expand All @@ -49,6 +50,16 @@ function qa_page_q_single_click_q($question, $answers, $commentsfollows, $closep
return true;
}

if (qa_clicked('q_domute') && qa_page_q_click_check_form_code($question, $error)) {
mute_thread($userid, $question['postid']);
return true;
}

if (qa_clicked('q_dounmute') && qa_page_q_click_check_form_code($question, $error)) {
unmute_thread($userid, $question['postid']);
return true;
}

if ( (qa_clicked('q_dohide') && $question['hideable']) || (qa_clicked('q_doreject') && $question['moderatable']) )
if (qa_page_q_click_check_form_code($question, $error)) {
qa_question_set_hidden($question, true, $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost);
Expand Down Expand Up @@ -123,6 +134,8 @@ function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows
If there is an error to display, it will be passed out in $error.
*/
{
require_once QA_PLUGIN_DIR.'/q2apro-on-site-notifications/utils.php';

$userid=qa_get_logged_in_userid();
$handle=qa_get_logged_in_handle();
$cookieid=qa_cookie_get();
Expand All @@ -141,6 +154,16 @@ function qa_page_q_single_click_a($answer, $question, $answers, $commentsfollows
return true;
}

if (qa_clicked($prefix . 'domute') && qa_page_q_click_check_form_code($answer, $error)) {
mute_thread($userid, $answer['postid']);
return true;
}

if (qa_clicked($prefix . 'dounmute') && qa_page_q_click_check_form_code($answer, $error)) {
unmute_thread($userid, $answer['postid']);
return true;
}

if ( (qa_clicked($prefix.'dohide') && $answer['hideable']) || (qa_clicked($prefix.'doreject') && $answer['moderatable']) )
if (qa_page_q_click_check_form_code($answer, $error)) {
qa_answer_set_hidden($answer, true, $userid, $handle, $cookieid, $question, $commentsfollows);
Expand Down
6 changes: 6 additions & 0 deletions forum/qa-lang/pl/qa-lang-question.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
'flag_button' => 'zgłoś',
'flag_c_popup' => 'Zgłoś ten komentarz jako spam lub niezgodny z regulaminem',
'flag_hide_button' => 'zgłoś i ukryj',

'mute_button' => 'Wycisz wątek',
'mute_popup' => 'Wycisz ten wątek, aby nie otrzymywać dalszych powiadomień',
'unmute_button' => 'Subskrybuj wątek',
'unmute_popup' => 'Subskrybuj wątek, aby ponownie otrzymywać powiadomienia',

'flag_limit' => 'Zbyt wiele zgłoszeń. Spróbuj ponownie za godzinę',
'flag_must_confirm' => '^5Potwierdź swój adres email^6, aby móc zgłaszać treść.',
'flag_must_login' => '^1Zaloguj^2 lub ^3zarejestruj się^4, aby móc zgłaszać treść.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,26 @@
* Link to plugin file: https://github.com/NoahY/q2a-history/blob/master/qa-history-check.php
*/

require_once __DIR__ . '/utils.php';

class q2apro_history_check
{
public function init_queries($tableslc)
{
$queries = [];

if (!in_array(qa_db_add_table_prefix('muted_threads'), $tableslc)) {
$queries[] = 'CREATE TABLE IF NOT EXISTS ^muted_threads (
postid bigint(20) unsigned NOT NULL,
userid bigint(20) unsigned NOT NULL,
KEY postid (postid),
KEY userid (userid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8';
}

return $queries;
}

function process_event($event, $userid, $handle, $cookieid, $params)
{
if (!qa_opt('event_logger_to_database')) {
Expand Down Expand Up @@ -139,11 +157,12 @@ private function handle_comments_thread($cookieId, $params)
$commentsQuery = qa_db_query_sub('SELECT DISTINCT userid FROM `^posts` WHERE `parentid` = #
AND `type` = "C" AND `userid` IS NOT NULL', $params['parentid']);

$muteChecker = new ThreadMuteChecker($params['parentid']);
while (($comment = qa_db_read_one_assoc($commentsQuery, true)) !== null) {
$commentUserId = $comment['userid'];

// don't inform user that comments, and don't inform user that comments on his own question/answer
if ($commentUserId != $postUserId && $commentUserId != $parentUserId) {
if ($commentUserId != $postUserId && $commentUserId != $parentUserId && !$muteChecker->hasUserMutedThread($commentUserId)) {
$commentUserHandle = qa_userid_to_handle($commentUserId);

qa_db_query_sub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,60 @@ function doctype() {
qa_html_theme_base::doctype();
}

public function a_item_buttons($a_item)
{
if (!empty($a_item['form'])) {
$answerId = $a_item['raw']['postid'];
$questionId = $a_item['raw']['parentid'];

$this->addCustomButtons(
$a_item,
'a' . $a_item['raw']['postid'],
' onclick="return qa_answer_click('.qa_js($answerId).', '.qa_js($questionId).', this);"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Czy możemy obsłużyć klik z poziomu JS, zamiast HTML? Skrypt /qa-plugin/q2apro-on-site-notifications/script.js powinien się do tego nadać.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wszystko możemy 😃 Wrzuciłem na razie rozwiązanie na szybko, ale jak najbardziej w wolnej chwili chętnie poprawię, dzięki 😄

);
}

return parent::a_item_buttons($a_item);
}

public function q_view_buttons($q_view)
{
if (!empty($q_view['form'])) {
$this->addCustomButtons(
$q_view,
'q',
' onclick="qa_show_waiting_after(this, false);"'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jak wyżej.

);
}

return parent::q_view_buttons($q_view);
}

protected function addCustomButtons(&$view, $prefix, $clicksuffix)
{
require_once __DIR__ . '/../qa-plugin/q2apro-on-site-notifications/utils.php';

$current_user_id = qa_get_logged_in_userid();
if ($current_user_id === null) {
return;
}

$postId = $view['raw']['postid'];
$participantsObtainer = new ThreadParticipantsObtainer($postId);
if (!$participantsObtainer->isParticipant($current_user_id)) {
return;
}

$muteChecker = new ThreadMuteChecker($postId);
$muted = $muteChecker->hasUserMutedThread($current_user_id);
$action = $muted ? 'unmute' : 'mute';
$view['form']['buttons'][$action]=array(
'tags' => "name=\"{$prefix}_do{$action}\"" . $clicksuffix,
'label' => qa_lang_html("question/{$action}_button"),
'popup' => qa_lang_html("question/{$action}_popup"),
);
}

} // end qa_html_theme_layer

/*
Expand Down
75 changes: 75 additions & 0 deletions forum/qa-plugin/q2apro-on-site-notifications/utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

class ThreadMuteChecker
{
private $muted_users;
private $cache = [];

public function __construct(int $postid)
{
$this->muted_users = $this->getUsersWhoMutedThread($postid);
}

public function hasUserMutedThread(int $userid)
{
if (!isset($this->cache[$userid])) {
$this->cache[$userid] = in_array($userid, $this->muted_users);
}

return $this->cache[$userid];
}

protected function getUsersWhoMutedThread(int $postid)
{
return qa_db_read_all_values(
qa_db_query_sub('SELECT userid FROM ^muted_threads
WHERE postid = #
', $postid),
);
}
}

class ThreadParticipantsObtainer
{
public $participants;

public function __construct(int $postid)
{
$this->participants = $this->getThreadParticipants($postid);
}

public function isParticipant(int $userid)
{
return in_array("$userid", $this->participants);
}

protected function getThreadParticipants(int $postid)
{
$query = implode(' UNION ', [
'SELECT userid FROM ^posts WHERE postid = #',
'SELECT DISTINCT userid FROM ^posts WHERE parentid = #',
]);

return qa_db_read_all_values(
qa_db_query_sub($query, $postid, $postid),
);
}
}

function mute_thread(int $userid, int $postid)
{
qa_db_query_sub(
"INSERT INTO ^muted_threads (userid, postid) VALUES (#, #)",
$userid,
$postid
);
}

function unmute_thread(int $userid, int $postid)
{
qa_db_query_sub(
"DELETE FROM ^muted_threads WHERE userid = # AND postid = #",
$userid,
$postid
);
}
Binary file added forum/qa-theme/SnowFlat/images/icons/mute-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added forum/qa-theme/SnowFlat/images/icons/mute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added forum/qa-theme/SnowFlat/images/icons/unmute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions forum/qa-theme/SnowFlat/qa-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,12 @@ input[type="submit"], button {
.qa-form-light-button-unflag, .qa-form-light-button-clearflags {
background-image: url('images/icons/un-flag-white.png');
}
.qa-form-light-button-mute {
background-image: url('images/icons/mute-white.png');
}
.qa-form-light-button-unmute {
background-image: url('images/icons/unmute-white.png');
}
.qa-form-light-button-hide {
background-image: url('images/icons/hide-white.png');
}
Expand Down Expand Up @@ -2856,6 +2862,12 @@ input[type="submit"], button {
.qa-c-list-item .qa-form-light-button-unflag, .qa-c-list-item .qa-form-light-button-clearflags {
background-image: url('images/icons/un-flag.png');
}
.qa-c-list-item .qa-form-light-button-mute {
background-image: url('images/icons/mute.png');
}
.qa-c-list-item .qa-form-light-button-unmute {
background-image: url('images/icons/unmute.png');
}
.qa-c-list-item .qa-form-light-button-hide {
background-image: url('images/icons/hide.png');
}
Expand Down