Merge branch 'takeshitakenji/gnu-social-twitter-repeat-config' into mmn_fixes

This commit is contained in:
Mikael Nordfeldth 2017-07-11 22:09:12 +02:00
commit 457d32e273
5 changed files with 25 additions and 4 deletions

View File

@ -89,7 +89,7 @@ class Foreign_link extends Managed_DataObject
return $flink; return $flink;
} }
function set_flags($noticesend, $noticerecv, $replysync, $friendsync) function set_flags($noticesend, $noticerecv, $replysync, $repeatsync, $friendsync)
{ {
if ($noticesend) { if ($noticesend) {
$this->noticesync |= FOREIGN_NOTICE_SEND; $this->noticesync |= FOREIGN_NOTICE_SEND;
@ -109,6 +109,12 @@ class Foreign_link extends Managed_DataObject
$this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY; $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
} }
if ($repeatsync) {
$this->noticesync |= FOREIGN_NOTICE_SEND_REPEAT;
} else {
$this->noticesync &= ~FOREIGN_NOTICE_SEND_REPEAT;
}
if ($friendsync) { if ($friendsync) {
$this->friendsync |= FOREIGN_FRIEND_RECV; $this->friendsync |= FOREIGN_FRIEND_RECV;
} else { } else {

View File

@ -46,6 +46,7 @@ define('PROFILES_PER_MINILIST', 8);
define('FOREIGN_NOTICE_SEND', 1); define('FOREIGN_NOTICE_SEND', 1);
define('FOREIGN_NOTICE_RECV', 2); define('FOREIGN_NOTICE_RECV', 2);
define('FOREIGN_NOTICE_SEND_REPLY', 4); define('FOREIGN_NOTICE_SEND_REPLY', 4);
define('FOREIGN_NOTICE_SEND_REPEAT', 8);
define('FOREIGN_FRIEND_SEND', 1); define('FOREIGN_FRIEND_SEND', 1);
define('FOREIGN_FRIEND_RECV', 2); define('FOREIGN_FRIEND_RECV', 2);

View File

@ -237,7 +237,7 @@ class TwitterauthorizationAction extends FormAction
// Defaults: noticesync on, everything else off // Defaults: noticesync on, everything else off
$flink->set_flags(true, false, false, false); $flink->set_flags(true, false, false, false, false);
$flink_id = $flink->insert(); $flink_id = $flink->insert();

View File

@ -161,6 +161,12 @@ class TwittersettingsAction extends ProfileSettingsAction
$this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY); $this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY);
$this->elementEnd('li'); $this->elementEnd('li');
$this->elementStart('li'); $this->elementStart('li');
$this->checkbox('repeatsync',
// TRANS: Checkbox label.
_m('Send local repeats to Twitter.'),
$this->flink->noticesync & FOREIGN_NOTICE_SEND_REPEAT);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('friendsync', $this->checkbox('friendsync',
// TRANS: Checkbox label. // TRANS: Checkbox label.
_m('Subscribe to my Twitter friends here.'), _m('Subscribe to my Twitter friends here.'),
@ -265,6 +271,7 @@ class TwittersettingsAction extends ProfileSettingsAction
$noticerecv = $this->boolean('noticerecv'); $noticerecv = $this->boolean('noticerecv');
$friendsync = $this->boolean('friendsync'); $friendsync = $this->boolean('friendsync');
$replysync = $this->boolean('replysync'); $replysync = $this->boolean('replysync');
$repeatsync = $this->boolean('repeatsync');
if (!$this->flink instanceof Foreign_link) { if (!$this->flink instanceof Foreign_link) {
common_log_db_error($this->flink, 'SELECT', __FILE__); common_log_db_error($this->flink, 'SELECT', __FILE__);
@ -274,7 +281,7 @@ class TwittersettingsAction extends ProfileSettingsAction
$original = clone($this->flink); $original = clone($this->flink);
$wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV); $wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
$this->flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync); $this->flink->set_flags($noticesend, $noticerecv, $replysync, $repeatsync, $friendsync);
$result = $this->flink->update($original); $result = $this->flink->update($original);
if ($result === false) { if ($result === false) {

View File

@ -111,7 +111,14 @@ function is_twitter_bound($notice, $flink) {
return false; return false;
} }
$allowedVerbs = array(ActivityVerb::POST, ActivityVerb::SHARE); $allowedVerbs = array(ActivityVerb::POST);
// Default behavior: always send repeats
if (empty($flink))
array_push($allowedVerbs, ActivityVerb::SHARE);
// Otherwise, check to see if repeats are allowed
else if (($flink->noticesync & FOREIGN_NOTICE_SEND_REPEAT) == FOREIGN_NOTICE_SEND_REPEAT)
array_push($allowedVerbs, ActivityVerb::SHARE);
// Don't send things that aren't posts or repeats (at least for now) // Don't send things that aren't posts or repeats (at least for now)
if (!in_array($notice->verb, $allowedVerbs)) { if (!in_array($notice->verb, $allowedVerbs)) {