forked from GNUsocial/gnu-social
low-level management of blocks
darcs-hash:20081208031008-5ed1f-c96006b5c05fa0e68f9adaacd0518016aedfee2a.gz
This commit is contained in:
parent
665a3325b3
commit
81a81baf83
@ -19,4 +19,9 @@ class Profile_block extends Memcached_DataObject
|
|||||||
|
|
||||||
/* the code above is auto generated do not remove the tag below */
|
/* the code above is auto generated do not remove the tag below */
|
||||||
###END_AUTOCODE
|
###END_AUTOCODE
|
||||||
|
|
||||||
|
static function get($blocker, $blocked) {
|
||||||
|
return Profile_block::pkeyGet(array('blocker' => $blocker,
|
||||||
|
'blocked' => $blocked));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,19 @@ class User extends Memcached_DataObject
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasBlocked($other) {
|
||||||
|
$block = Profile_block::get($this->id, $other->id);
|
||||||
|
|
||||||
|
if (is_null($block)) {
|
||||||
|
$result = false;
|
||||||
|
} else {
|
||||||
|
$result = true;
|
||||||
|
$block->free();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
static function register($fields) {
|
static function register($fields) {
|
||||||
|
|
||||||
# MAGICALLY put fields into current scope
|
# MAGICALLY put fields into current scope
|
||||||
@ -342,12 +355,14 @@ class User extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
|
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
|
||||||
$profile = $this->getProfile();
|
$qry =
|
||||||
if (!$profile) {
|
'SELECT * ' .
|
||||||
return NULL;
|
'FROM notice ' .
|
||||||
} else {
|
'WHERE profile_id = %d ';
|
||||||
return $profile->getNotices($offset, $limit, $since_id, $before_id);
|
|
||||||
}
|
return Notice::getStream(sprintf($qry, $this->id),
|
||||||
|
'user:notices:'.$this->id,
|
||||||
|
$offset, $limit, $since_id, $before_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE) {
|
function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE) {
|
||||||
|
19
lib/subs.php
19
lib/subs.php
@ -25,7 +25,7 @@ require_once('XMPPHP/XMPP.php');
|
|||||||
Returns true or an error message.
|
Returns true or an error message.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function subs_subscribe_user($user,$other_nickname) {
|
function subs_subscribe_user($user, $other_nickname) {
|
||||||
|
|
||||||
$other = User::staticGet('nickname', $other_nickname);
|
$other = User::staticGet('nickname', $other_nickname);
|
||||||
|
|
||||||
@ -36,12 +36,21 @@ function subs_subscribe_user($user,$other_nickname) {
|
|||||||
return subs_subscribe_to($user, $other);
|
return subs_subscribe_to($user, $other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Subscribe user $user to other user $other.
|
||||||
|
* Note: $other must be a local user, not a remote profile.
|
||||||
|
* Because the other way is quite a bit more complicated.
|
||||||
|
*/
|
||||||
|
|
||||||
function subs_subscribe_to($user, $other) {
|
function subs_subscribe_to($user, $other) {
|
||||||
|
|
||||||
if ($user->isSubscribed($other)) {
|
if ($user->isSubscribed($other)) {
|
||||||
return _('Already subscribed!.');
|
return _('Already subscribed!.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($other->hasBlocked($user)) {
|
||||||
|
return _('User has blocked you.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$user->subscribeTo($other)) {
|
if (!$user->subscribeTo($other)) {
|
||||||
return _('Could not subscribe.');
|
return _('Could not subscribe.');
|
||||||
return;
|
return;
|
||||||
@ -56,7 +65,7 @@ function subs_subscribe_to($user, $other) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($other->autosubscribe && !$other->isSubscribed($user)) {
|
if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) {
|
||||||
if (!$other->subscribeTo($user)) {
|
if (!$other->subscribeTo($user)) {
|
||||||
return _('Could not subscribe other to you.');
|
return _('Could not subscribe other to you.');
|
||||||
}
|
}
|
||||||
@ -87,6 +96,7 @@ function subs_notify_email($listenee, $listener) {
|
|||||||
/* Unsubscribe $user from nickname $other_nickname
|
/* Unsubscribe $user from nickname $other_nickname
|
||||||
Returns true or an error message.
|
Returns true or an error message.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function subs_unsubscribe_user($user, $other_nickname) {
|
function subs_unsubscribe_user($user, $other_nickname) {
|
||||||
|
|
||||||
$other = User::staticGet('nickname', $other_nickname);
|
$other = User::staticGet('nickname', $other_nickname);
|
||||||
@ -95,9 +105,12 @@ function subs_unsubscribe_user($user, $other_nickname) {
|
|||||||
return _('No such user.');
|
return _('No such user.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return subs_unsubscribe_to($user, $other);
|
return subs_unsubscribe_to($user, $other->getProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unsubscribe user $user from profile $other
|
||||||
|
* NB: other can be a remote user. */
|
||||||
|
|
||||||
function subs_unsubscribe_to($user, $other) {
|
function subs_unsubscribe_to($user, $other) {
|
||||||
|
|
||||||
if (!$user->isSubscribed($other))
|
if (!$user->isSubscribed($other))
|
||||||
|
Loading…
Reference in New Issue
Block a user