summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/block.php32
-rw-r--r--actions/twitapiblocks.php33
-rw-r--r--actions/unblock.php14
3 files changed, 34 insertions, 45 deletions
diff --git a/actions/block.php b/actions/block.php
index fb553da6e..e6d2b7e49 100644
--- a/actions/block.php
+++ b/actions/block.php
@@ -118,41 +118,13 @@ class BlockAction extends Action {
return;
}
- # Add a new block record
-
- $block = new Profile_block();
-
- # Begin a transaction
-
- $block->query('BEGIN');
-
- $block->blocker = $cur->id;
- $block->blocked = $this->profile->id;
-
- $result = $block->insert();
+ $result = $cur->block($this->profile);
if (!$result) {
- common_log_db_error($block, 'INSERT', __FILE__);
- $this->server_error(_('Could not save new block record.'));
+ $this->server_error(_('Failed to save block information.'));
return;
}
- # Cancel their subscription, if it exists
-
- $sub = Subscription::pkeyGet(array('subscriber' => $this->profile->id,
- 'subscribed' => $cur->id));
-
- if ($sub) {
- $result = $sub->delete();
- if (!$result) {
- common_log_db_error($sub, 'DELETE', __FILE__);
- $this->server_error(_('Could not delete subscription.'));
- return;
- }
- }
-
- $block->query('COMMIT');
-
# Now, gotta figure where we go back to
foreach ($this->args as $k => $v) {
diff --git a/actions/twitapiblocks.php b/actions/twitapiblocks.php
index 21d620dd3..6bfdec0d0 100644
--- a/actions/twitapiblocks.php
+++ b/actions/twitapiblocks.php
@@ -24,13 +24,40 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiblocksAction extends TwitterapiAction {
function create($args, $apidata) {
+
parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
+
+ $blockee = $this->get_user($apidata['api_arg'], $apidata);
+
+ if (!$blockee) {
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+
+ $user = $apidata['user'];
+
+ if ($user->hasBlocked($blockee) || $user->block($blockee)) {
+ $this->show_profile($blockee, $apidata['content-type']);
+ } else {
+ common_server_error(_('Block user failed.'));
+ }
}
function destroy($args, $apidata) {
parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ $blockee = $this->get_user($apidata['api_arg'], $apidata);
+
+ if (!$blockee) {
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+ $user = $apidata['user'];
+
+ if (!$user->hasBlocked($blockee) || $user->unblock($blockee)) {
+ $this->show_profile($blockee, $apidata['content-type']);
+ } else {
+ common_server_error(_('Unblock user failed.'));
+ }
+ }
} \ No newline at end of file
diff --git a/actions/unblock.php b/actions/unblock.php
index 192beaab5..d60cc7088 100644
--- a/actions/unblock.php
+++ b/actions/unblock.php
@@ -67,20 +67,10 @@ class UnblockAction extends Action {
$cur = common_current_user();
- # Get the block record
-
- $block = Profile_block::get($cur->id, $this->profile->id);
-
- if (!$block) {
- $this->client_error(_('That user is not blocked!'));
- return;
- }
-
- $result = $block->delete();
+ $result = $cur->unblock($this->profile);
if (!$result) {
- common_log_db_error($block, 'DELETE', __FILE__);
- $this->server_error(_('Could not delete block record.'));
+ $this->server_error(_('Error removing the block.'));
return;
}