Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/248905
Change subject: [WIP] Track what wikis a user has unread notifications on
......................................................................
[WIP] Track what wikis a user has unread notifications on
TODO:
* Decide whether we split alerts/messages in db table?
* Caching layer?
* Unseen or unread?
* API?
* ...
Change-Id: Id1498bdeb5811d6848dc66781ffca03e726eab90
---
A db_patches/echo_unseen_wikis.sql
M includes/NotifUser.php
A includes/UnseenWikis.php
3 files changed, 101 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/05/248905/1
diff --git a/db_patches/echo_unseen_wikis.sql b/db_patches/echo_unseen_wikis.sql
new file mode 100644
index 0000000..6e1c7b9
--- /dev/null
+++ b/db_patches/echo_unseen_wikis.sql
@@ -0,0 +1,13 @@
+CREATE TABLE /*_*/echo_unseen_wikis (
+ # Primary key
+ esw_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ # Global user id
+ esw_user INT UNSIGNED NOT NULL,
+ # Name of wiki
+ esw_wiki VARCHAR(30) NOT NULL,
+ # Unseen count on that wiki
+ esw_count INT UNSIGNED NOT NULL
+) /*$wgDBTableOptions*/;
+
+CREATE UNIQUE INDEX /*i*/echo_unseen_wikis_user_wiki ON /*_*/echo_unseen_wikis
(esw_user,esw_wiki);
+CREATE INDEX /*i*/echo_unseen_wikis_user ON /*_*/echo_unseen_wikis (esw_user);
diff --git a/includes/NotifUser.php b/includes/NotifUser.php
index 0b88336..87bbec2 100644
--- a/includes/NotifUser.php
+++ b/includes/NotifUser.php
@@ -412,7 +412,8 @@
*/
public function resetNotificationCount( $dbSource = DB_SLAVE ) {
// Reset notification count for all sections as well
- $this->getNotificationCount( false, $dbSource,
EchoAttributeManager::ALL );
+ $unreadCount = $this->getNotificationCount( false, $dbSource,
EchoAttributeManager::ALL );
+ EchoUnseenWikis::newFromUser( $this->mUser )->updateCount(
wfWikiID(), $unreadCount );
$this->getNotificationCount( false, $dbSource,
EchoAttributeManager::ALERT );
$this->getNotificationCount( false, $dbSource,
EchoAttributeManager::MESSAGE );
// when notification count needs to be updated, last
notification may have
diff --git a/includes/UnseenWikis.php b/includes/UnseenWikis.php
new file mode 100644
index 0000000..5e633fa
--- /dev/null
+++ b/includes/UnseenWikis.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * Manages what wikis a user has unread notifications on
+ *
+ */
+class EchoUnseenWikis {
+
+ /**
+ * @var int
+ */
+ private $id;
+
+ /**
+ * @param int $id Central user id
+ */
+ public function __construct( $id ) {
+ $this->id = $id;
+ }
+
+ public static function newFromUser( User $user ) {
+ if ( class_exists( 'CentralAuth' ) ) {
+ // @todo don't be CA specific
+ $caUser = CentralAuthUser::getInstance( $user );
+ if ( $caUser->isAttached() ) {
+ return new self( $caUser->getId() );
+ }
+ }
+
+ return new self( $user->getId() );
+ }
+
+ private function getDB( $index ) {
+ // @todo support wikishared
+ return wfGetDB( $index );
+ }
+
+ /**
+ * @return array
+ */
+ public function getUnseenCounts() {
+ $dbr = $this->getDB( DB_SLAVE );
+ $rows = $dbr->select(
+ 'echo_unseen_wikis',
+ array( 'esw_wiki', 'esw_count' ),
+ array( 'esw_user' => $this->id ),
+ __METHOD__
+ );
+ $wikis = array();
+ foreach ( $rows as $row ) {
+ $wikis[$row->esw_wiki] = $row->esw_count;
+ }
+
+ return $wikis;
+ }
+
+ /**
+ * @param string $wiki
+ * @param int $newCount
+ */
+ public function updateCount( $wiki, $newCount ) {
+ $dbw = $this->getDB( DB_MASTER );
+ if ( $newCount === 0 ) {
+ $dbw->delete(
+ 'echo_unseen_wikis',
+ array( 'esw_user' => $this->id ),
+ __METHOD__
+ );
+ } else {
+ $dbw->upsert(
+ 'echo_unseen_wikis',
+ array(
+ 'esw_user' => $this->id,
+ 'esw_wiki' => $wiki,
+ 'esw_count' => $newCount
+ ),
+ array( 'esw_user', 'esw_wiki' ),
+ array(
+ 'esw_count' => $newCount
+ ),
+ __METHOD__
+ );
+
+ }
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/248905
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1498bdeb5811d6848dc66781ffca03e726eab90
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits