public $autosubscribe; // tinyint(1)
public $subscribe_policy; // tinyint(1)
public $urlshorteningservice; // varchar(50) default_ur1.ca
- public $inboxed; // tinyint(1)
public $private_stream; // tinyint(1) default_0
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
'email' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for password recovery etc.'),
'incomingemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for post-by-email'),
'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
- 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of favorites'),
+ 'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of @-replies'),
'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
- 'inboxed' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'has an inbox been created for this user?'),
'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
);
}
- protected $_profile = null;
+ protected $_profile = array();
/**
* @return Profile
*/
public function getProfile()
{
- if (!($this->_profile instanceof Profile)) {
- $this->_profile = Profile::getKV('id', $this->id);
- if (!($this->_profile instanceof Profile)) {
+ if (!isset($this->_profile[$this->id])) {
+ $profile = Profile::getKV('id', $this->id);
+ if (!$profile instanceof Profile) {
throw new UserNoProfileException($this);
}
+ $this->_profile[$this->id] = $profile;
}
-
- return $this->_profile;
+ return $this->_profile[$this->id];
}
- function isSubscribed($other)
+ public function getUri()
{
- return $this->getProfile()->isSubscribed($other);
+ return $this->uri;
}
- function hasPendingSubscription($other)
+ public function getNickname()
{
- return $this->getProfile()->hasPendingSubscription($other);
+ return $this->getProfile()->getNickname();
}
- // 'update' won't write key columns, so we have to do it ourselves.
+ function isSubscribed(Profile $other)
+ {
+ return $this->getProfile()->isSubscribed($other);
+ }
- function updateKeys(&$orig)
+ function hasPendingSubscription(Profile $other)
{
- $this->_connect();
- $parts = array();
- foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail') as $k) {
- if (strcmp($this->$k, $orig->$k) != 0) {
- $parts[] = $k . ' = ' . $this->_quote($this->$k);
- }
- }
- if (count($parts) == 0) {
- // No changes
- return true;
- }
- $toupdate = implode(', ', $parts);
-
- $table = common_database_tablename($this->tableName());
- $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
- ' WHERE id = ' . $this->id;
- $orig->decache();
- $result = $this->query($qry);
- if ($result) {
- $this->encache();
- }
- return $result;
+ return $this->getProfile()->hasPendingSubscription($other);
}
/**
if (!empty($code)) {
$invite = Invitation::getKV($code);
- if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
+ if ($invite instanceof Invitation && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
$user->email = $invite->address;
}
}
$user->email = $email;
}
- // This flag is ignored but still set to 1
-
- $user->inboxed = 1;
-
// Set default-on options here, otherwise they'll be disabled
// initially for sites using caching, since the initial encache
// doesn't know about the defaults in the database.
$user->emailnotifysub = 1;
- $user->emailnotifyfav = 1;
$user->emailnotifynudge = 1;
$user->emailnotifymsg = 1;
$user->emailnotifyattn = 1;
return false;
}
- // Everyone gets an inbox
-
- $inbox = new Inbox();
-
- $inbox->user_id = $user->id;
- $inbox->notice_ids = '';
-
- $result = $inbox->insert();
-
- if (!$result) {
- common_log_db_error($inbox, 'INSERT', __FILE__);
- return false;
- }
-
// Everyone is subscribed to themself
$subscription = new Subscription();
}
}
- function hasFave($notice)
- {
- return $this->getProfile()->hasFave($notice);
- }
-
- function mutuallySubscribed($other)
+ function mutuallySubscribed(Profile $other)
{
return $this->getProfile()->mutuallySubscribed($other);
}
return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
}
- function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
- {
- return $this->getProfile()->favoriteNotices($own, $offset, $limit, $since_id, $max_id);
- }
-
- function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- $stream = new InboxNoticeStream($this);
- return $stream->getNotices($offset, $limit, $since_id, $before_id);
- }
-
- // DEPRECATED, use noticeInbox()
-
- function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->noticeInbox($offset, $limit, $since_id, $before_id);
- }
-
- // DEPRECATED, use noticeInbox()
-
- function noticesWithFriendsThreaded($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->noticeInbox($offset, $limit, $since_id, $before_id);
- }
-
- // DEPRECATED, use noticeInbox()
-
- function noticeInboxThreaded($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->noticeInbox($offset, $limit, $since_id, $before_id);
- }
-
- // DEPRECATED, use noticeInbox()
-
- function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- return $this->noticeInbox($offset, $limit, $since_id, $before_id);
- }
-
- // DEPRECATED, use noticeInbox()
-
- function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
- {
- $this->noticeInbox($offset, $limit, $since_id, $before_id);
- }
-
- function blowFavesCache()
- {
- $this->getProfile()->blowFavesCache();
- }
-
function getSelfTags()
{
return Profile_tag::getTagsArray($this->id, $this->id, $this->id);
return true;
}
- function isMember($group)
+ function isMember(User_group $group)
{
return $this->getProfile()->isMember($group);
}
- function isAdmin($group)
+ function isAdmin(User_group $group)
{
return $this->getProfile()->isAdmin($group);
}
return $this->getProfile()->hasRight($right);
}
- function delete()
+ function delete($useWhere=false)
{
if (empty($this->id)) {
common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
- return parent::delete();
+ return parent::delete($useWhere);
}
try {
common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
}
- $related = array('Fave',
+ $related = array(
'Confirm_address',
'Remember_me',
'Foreign_link',
$this->_deleteTags();
$this->_deleteBlocks();
- parent::delete();
+ return parent::delete($useWhere);
}
function _deleteTags()
return $this->getProfile()->isSilenced();
}
+ function receivesEmailNotifications()
+ {
+ // We could do this in one large if statement, but that's not as easy to read
+ // Don't send notifications if we don't know the user's email address or it is
+ // explicitly undesired by the user's own settings.
+ if (empty($this->email) || !$this->emailnotifyattn) {
+ return false;
+ }
+ // Don't send notifications to a user who is sandboxed or silenced
+ if ($this->isSandboxed() || $this->isSilenced()) {
+ return false;
+ }
+ return true;
+ }
+
function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
{
$stream = new RepeatedByMeNoticeStream($this);
return false;
}
- function conversationTree()
- {
- if (common_config('oldschool', 'enabled')) {
- $osp = Old_school_prefs::getKV('user_id', $this->id);
- if (!empty($osp)) {
- return $osp->conversation_tree;
- }
- }
-
- return false;
- }
-
function streamNicknames()
{
if (common_config('oldschool', 'enabled')) {
$act = new Activity();
- $act->actor = ActivityObject::fromProfile($profile);
+ $act->actor = $profile->asActivityObject();
$act->verb = ActivityVerb::JOIN;
$act->objects[] = $service;
$service->title);
return $act;
}
+
+ public function delPref($namespace, $topic)
+ {
+ return $this->getProfile()->delPref($namespace, $topic);
+ }
+
+ public function getPref($namespace, $topic, $default=null)
+ {
+ return $this->getProfile()->getPref($namespace, $topic, $default);
+ }
+
+ public function getConfigPref($namespace, $topic)
+ {
+ return $this->getProfile()->getConfigPref($namespace, $topic);
+ }
+
+ public function setPref($namespace, $topic, $data)
+ {
+ return $this->getProfile()->setPref($namespace, $topic, $data);
+ }
}