Hi,

Being slightly annoyed by some conversations on identi.ca between a person I 
follow and a person I don't follow, I decided to write a patch hide replies 
targetted to people you are not following. This is reported as ticket 190 in 
the issue tracker.

I'm aware that this patch is possibly not perfect since I'm pretty new to the 
code. A couple of questions:

* Is 'filterreplies = 17' in laconica.ini correct? I bluntly copied it from 
the autosubscribe field wihout actually knowing what 17 is about. Wasn't able 
to find documentation on that either.
* So I understand there are two types of retrieving notices for a user: simply 
by querying the notices, or by using the inbox system. Will these both methods 
stay in the long run, or will the former method disappear?
I have adapted the querying for both methods, to be safe, although I'm unsure 
of the performance hit caused by the modifications I did in User.php.

Please review and comment, it would be great if this feature would make it 
into the mainline eventually.

Kind regards,

-- 
Bram Schoenmakers

What is mind? No matter. What is matter? Never mind.
(Punch, 1855)
diff --git a/actions/profilesettings.php b/actions/profilesettings.php
index fb84768..b077f0b 100644
--- a/actions/profilesettings.php
+++ b/actions/profilesettings.php
@@ -147,6 +147,12 @@ class ProfilesettingsAction extends AccountSettingsAction
                             ($this->arg('autosubscribe')) ?
                             $this->boolean('autosubscribe') : $user->autosubscribe);
             $this->elementEnd('li');
+            $this->elementStart('li');
+            $this->checkbox('filterreplies',
+                            _('Hide replies to people I don\'t follow'),
+                            ($this->arg('filterreplies')) ?
+                            $this->boolean('filterreplies') : $user->filterreplies);
+            $this->elementEnd('li');
         }
         $this->elementEnd('ul');
         $this->submit('save', _('Save'));
@@ -182,6 +188,7 @@ class ProfilesettingsAction extends AccountSettingsAction
             $bio = $this->trimmed('bio');
             $location = $this->trimmed('location');
             $autosubscribe = $this->boolean('autosubscribe');
+            $filterreplies = $this->boolean('filterreplies');
             $language = $this->trimmed('language');
             $timezone = $this->trimmed('timezone');
             $tagstring = $this->trimmed('tags');
@@ -281,6 +288,18 @@ class ProfilesettingsAction extends AccountSettingsAction
                 }
             }
 
+            if ($user->filterreplies ^ $filterreplies ) {
+                $original = clone($user);
+                $user->filterreplies = $filterreplies;
+                $result = $user->update($original);
+
+                if ( $result === false ) {
+                    common_log_db_error($user, 'UPDATE', __FILE__);
+                    $this->serverError(_('Couldn\'t update user for filterreplies.'));
+                    return;
+                }
+            }
+
             $profile = $user->getProfile();
 
             $orig_profile = clone($profile);
diff --git a/classes/Notice.php b/classes/Notice.php
index 19ae831..4ef8a22 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -705,6 +705,9 @@ class Notice extends Memcached_DataObject
         if ($enabled === true || $enabled === 'transitional') {
             $inbox = new Notice_inbox();
             $UT = common_config('db','type')=='pgsql'?'"user"':'user';
+
+            // The last AND clause hides replies to people which are not
+            // subscribed to.
             $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
               "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
               "FROM $UT JOIN subscription ON $UT.id = subscription.subscriber " .
@@ -712,7 +715,14 @@ class Notice extends Memcached_DataObject
               'AND NOT EXISTS (SELECT user_id, notice_id ' .
               'FROM notice_inbox ' .
               "WHERE user_id = $UT.id " .
-              'AND notice_id = ' . $this->id . ' )';
+              'AND notice_id = ' . $this->id . ' )' .
+              "AND ( $UT.filterreplies = 0" .
+                 'OR EXISTS ( SELECT subscription2.* ' .
+                          'FROM subscription AS subscription2 ' .
+                          'JOIN notice ON subscription2.subscribed = notice.profile_id ' .
+                          "WHERE subscription2.subscriber = $UT.id " .
+                          "AND notice.id = $this->reply_to" .
+                        ') )';
             if ($enabled === 'transitional') {
                 $qry .= " AND $UT.inboxed = 1";
             }
diff --git a/classes/User.php b/classes/User.php
index ce7ea14..06a2f63 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -60,6 +60,7 @@ class User extends Memcached_DataObject
     public $smsemail;                        // varchar(255)
     public $uri;                             // varchar(255)  unique_key
     public $autosubscribe;                   // tinyint(1)
+    public $filterreplies;                   // tinyint(1)
     public $urlshorteningservice;            // varchar(50)   default_ur1.ca
     public $inboxed;                         // tinyint(1)
     public $created;                         // datetime()   not_null
@@ -444,7 +445,21 @@ class User extends Memcached_DataObject
               'SELECT notice.* ' .
               'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
               'WHERE subscription.subscriber = %d ';
-            return Notice::getStream(sprintf($qry, $this->id),
+
+            if ( $this->filterreplies ) {
+                    // hide replies targetted at people which are not subscribed to.
+                    $qry .= 'AND (  notice.reply_to IS NULL' .
+                            'OR EXISTS ( SELECT notice.*' .
+                                        'FROM notice AS notice2' .
+                                        'JOIN subscription AS subscription2 ON notice2.profile_id = subscription2.subscribed' .
+                                        'WHERE notice2.id = notice.reply_to' .
+                                        'AND subscription2.subscriber = %d ) )';
+                 $qry = sprintf( $qry, $this->id, $this->id );
+            } else {
+                 $qry = sprintf( $qry, $this->id );
+            }
+
+            return Notice::getStream($qry,
                                      'user:notices_with_friends:' . $this->id,
                                      $offset, $limit, $since_id, $before_id,
                                      $order, $since);
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 5a905a4..c0569fe 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -352,6 +352,7 @@ smsreplies = 17
 smsemail = 2
 uri = 2
 autosubscribe = 17
+filterreplies = 17
 urlshorteningservice = 2
 inboxed = 17
 created = 142
diff --git a/db/laconica.sql b/db/laconica.sql
index d9e21a7..b8025e3 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -67,6 +67,7 @@ create table user (
     smsemail varchar(255) comment 'built from sms and carrier',
     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
+    filterreplies tinyint default 0 comment 'filter replies to people you dont follow'
     urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
     created datetime not null comment 'date this record was created',
diff --git a/db/laconica_pg.sql b/db/laconica_pg.sql
index f879d79..a4c109e 100644
--- a/db/laconica_pg.sql
+++ b/db/laconica_pg.sql
@@ -69,6 +69,7 @@ create table "user" (
     smsemail varchar(255) /* comment 'built from sms and carrier' */,
     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
     autosubscribe integer default 0 /* comment 'automatically subscribe to users who subscribe to us' */,
+    filterreplies integer default 0 /* filter replies to people you dont follow */,
     urlshorteningservice varchar(50) default 'ur1.ca' /* comment 'service to use for auto-shortening URLs' */,
     inboxed integer default 0 /* comment 'has an inbox been created for this user?' */, 
     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
_______________________________________________
Laconica-dev mailing list
[email protected]
http://mail.laconi.ca/mailman/listinfo/laconica-dev

Reply via email to