-
Notifications
You must be signed in to change notification settings - Fork 8
Wyciszenie powiadomień w obrębie wątku #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qwercik
wants to merge
1
commit into
master
Choose a base branch
from
feature/6/thread-muting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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);"' | ||
| ); | ||
| } | ||
|
|
||
| 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);"' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| /* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ); | ||
| } |
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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ć.
There was a problem hiding this comment.
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 😄