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 */
|
||||
###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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
# 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) {
|
||||
$profile = $this->getProfile();
|
||||
if (!$profile) {
|
||||
return NULL;
|
||||
} else {
|
||||
return $profile->getNotices($offset, $limit, $since_id, $before_id);
|
||||
}
|
||||
$qry =
|
||||
'SELECT * ' .
|
||||
'FROM notice ' .
|
||||
'WHERE profile_id = %d ';
|
||||
|
||||
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) {
|
||||
|
17
lib/subs.php
17
lib/subs.php
@ -36,12 +36,21 @@ function subs_subscribe_user($user,$other_nickname) {
|
||||
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) {
|
||||
|
||||
if ($user->isSubscribed($other)) {
|
||||
return _('Already subscribed!.');
|
||||
}
|
||||
|
||||
if ($other->hasBlocked($user)) {
|
||||
return _('User has blocked you.');
|
||||
}
|
||||
|
||||
if (!$user->subscribeTo($other)) {
|
||||
return _('Could not subscribe.');
|
||||
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)) {
|
||||
return _('Could not subscribe other to you.');
|
||||
}
|
||||
@ -87,6 +96,7 @@ function subs_notify_email($listenee, $listener) {
|
||||
/* Unsubscribe $user from nickname $other_nickname
|
||||
Returns true or an error message.
|
||||
*/
|
||||
|
||||
function subs_unsubscribe_user($user, $other_nickname) {
|
||||
|
||||
$other = User::staticGet('nickname', $other_nickname);
|
||||
@ -95,9 +105,12 @@ function subs_unsubscribe_user($user, $other_nickname) {
|
||||
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) {
|
||||
|
||||
if (!$user->isSubscribed($other))
|
||||
|
Loading…
Reference in New Issue
Block a user