diff --git a/classes/Profile.php b/classes/Profile.php index 4e0632ba0a..c93ba07c29 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -99,13 +99,37 @@ class Profile extends Managed_DataObject if ($this->_user === -1) { $this->_user = User::getKV('id', $this->id); } - if (!($this->_user instanceof User)) { + if (!$this->_user instanceof User) { throw new NoSuchUserException(array('id'=>$this->id)); } return $this->_user; } + protected $_group = -1; + + public function getGroup() + { + if ($this->_group === -1) { + $this->_group = User_group::getKV('profile_id', $this->id); + } + if (!$this->_group instanceof User_group) { + throw new NoSuchGroupException(array('profile_id'=>$this->id)); + } + + return $this->_group; + } + + public function isGroup() + { + try { + $this->getGroup(); + return true; + } catch (NoSuchGroupException $e) { + return false; + } + } + public function isLocal() { try { diff --git a/classes/User_group.php b/classes/User_group.php index 22b8d0bc04..590cc47bc7 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -62,6 +62,7 @@ class User_group extends Managed_DataObject 'primary key' => array('id'), 'unique keys' => array( 'user_group_uri_key' => array('uri'), +// when it's safe and everyone's run upgrade.php 'user_profile_id_key' => array('profile_id'), ), 'foreign keys' => array( 'user_group_id_fkey' => array('profile', array('profile_id' => 'id')), diff --git a/lib/nosuchgroupexception.php b/lib/nosuchgroupexception.php new file mode 100644 index 0000000000..fffd944e51 --- /dev/null +++ b/lib/nosuchgroupexception.php @@ -0,0 +1,67 @@ +. + * + * @category Exception + * @package GNUsocial + * @author Evan Prodromou + * @author Mikael Nordfeldth + * @copyright 2013 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * Class for an exception when a local user is not found by certain criteria + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @author Mikael Nordfeldth + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class NoSuchGroupException extends ServerException +{ + public $data = array(); + + /** + * constructor + * + * @param array $data User_group search criteria + */ + + public function __construct(array $data) + { + // filter on unique keys for User_group entries + foreach(array('id', 'profile_id') as $key) { + if (isset($data[$key]) && !empty($data[$key])) { + $this->data[$key] = $data[$key]; + } + } + + // Here we could log the failed lookup + + parent::__construct(_('No such user found.')); + } +} diff --git a/lib/nosuchuserexception.php b/lib/nosuchuserexception.php index 0fa1c8d3db..ade5d924a0 100644 --- a/lib/nosuchuserexception.php +++ b/lib/nosuchuserexception.php @@ -28,9 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class for an exception when a local user is not found by certain criteria diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 19d6674ae3..734342819d 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -241,15 +241,12 @@ class NoticeListItem extends Widget function showAddressees() { - $ga = $this->getGroupAddressees(); $pa = $this->getProfileAddressees(); - $a = array_merge($ga, $pa); - - if (!empty($a)) { + if (!empty($pa)) { $this->out->elementStart('span', 'addressees'); $first = true; - foreach ($a as $addr) { + foreach ($pa as $addr) { if (!$first) { // TRANS: Separator in profile addressees list. $this->out->text(_m('SEPARATOR',', ')); @@ -265,46 +262,22 @@ class NoticeListItem extends Widget } } - function getGroupAddressees() - { - $ga = array(); - - $groups = $this->getGroups(); - - $user = common_current_user(); - - $streamNicknames = !empty($user) && $user->streamNicknames(); - - foreach ($groups as $group) { - $ga[] = array('href' => $group->homeUrl(), - 'title' => $group->nickname, - 'class' => 'addressee group', - 'text' => ($streamNicknames) ? $group->nickname : $group->getBestName()); - } - - return $ga; - } - - function getGroups() - { - return $this->notice->getGroups(); - } - function getProfileAddressees() { $pa = array(); - $replies = $this->getReplyProfiles(); + $attentions = $this->getReplyProfiles(); $user = common_current_user(); $streamNicknames = !empty($user) && $user->streamNicknames(); - foreach ($replies as $reply) { - $pa[] = array('href' => $reply->profileurl, - 'title' => $reply->nickname, - 'class' => 'addressee account', - 'text' => ($streamNicknames) ? $reply->nickname : $reply->getBestName()); + foreach ($attentions as $attn) { + $class = $attn->isGroup() ? 'group' : 'account'; + $pa[] = array('href' => $attn->profileurl, + 'title' => $attn->nickname, + 'class' => "addressee {$class}", + 'text' => ($streamNicknames) ? $attn->nickname : $attn->getBestName()); } return $pa; diff --git a/plugins/Xmpp/README b/plugins/Xmpp/README index 3b1093c886..a8ec7da73a 100644 --- a/plugins/Xmpp/README +++ b/plugins/Xmpp/README @@ -17,7 +17,7 @@ Settings ======== user*: user part of the jid server*: server part of the jid -resource*: resource part of the jid +resource (gnusocial): resource part of the jid port (5222): port on which to connect to the server encryption (true): use encryption on the connection host (same as server): host to connect to. Usually, you won't set this.