NoticeListItem attentions showed double for User_group

...because they each have their own Profile now! Whiie!
This commit is contained in:
Mikael Nordfeldth 2013-10-30 12:56:17 +01:00
parent e45edd6ae2
commit 09ef1fff69
6 changed files with 104 additions and 41 deletions

View File

@ -99,13 +99,37 @@ class Profile extends Managed_DataObject
if ($this->_user === -1) { if ($this->_user === -1) {
$this->_user = User::getKV('id', $this->id); $this->_user = User::getKV('id', $this->id);
} }
if (!($this->_user instanceof User)) { if (!$this->_user instanceof User) {
throw new NoSuchUserException(array('id'=>$this->id)); throw new NoSuchUserException(array('id'=>$this->id));
} }
return $this->_user; 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() public function isLocal()
{ {
try { try {

View File

@ -62,6 +62,7 @@ class User_group extends Managed_DataObject
'primary key' => array('id'), 'primary key' => array('id'),
'unique keys' => array( 'unique keys' => array(
'user_group_uri_key' => array('uri'), '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( 'foreign keys' => array(
'user_group_id_fkey' => array('profile', array('profile_id' => 'id')), 'user_group_id_fkey' => array('profile', array('profile_id' => 'id')),

View File

@ -0,0 +1,67 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* class for an exception when a User_group is not found by certain criteria
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Exception
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @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 <evan@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @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.'));
}
}

View File

@ -28,9 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Class for an exception when a local user is not found by certain criteria * Class for an exception when a local user is not found by certain criteria

View File

@ -241,15 +241,12 @@ class NoticeListItem extends Widget
function showAddressees() function showAddressees()
{ {
$ga = $this->getGroupAddressees();
$pa = $this->getProfileAddressees(); $pa = $this->getProfileAddressees();
$a = array_merge($ga, $pa); if (!empty($pa)) {
if (!empty($a)) {
$this->out->elementStart('span', 'addressees'); $this->out->elementStart('span', 'addressees');
$first = true; $first = true;
foreach ($a as $addr) { foreach ($pa as $addr) {
if (!$first) { if (!$first) {
// TRANS: Separator in profile addressees list. // TRANS: Separator in profile addressees list.
$this->out->text(_m('SEPARATOR',', ')); $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() function getProfileAddressees()
{ {
$pa = array(); $pa = array();
$replies = $this->getReplyProfiles(); $attentions = $this->getReplyProfiles();
$user = common_current_user(); $user = common_current_user();
$streamNicknames = !empty($user) && $user->streamNicknames(); $streamNicknames = !empty($user) && $user->streamNicknames();
foreach ($replies as $reply) { foreach ($attentions as $attn) {
$pa[] = array('href' => $reply->profileurl, $class = $attn->isGroup() ? 'group' : 'account';
'title' => $reply->nickname, $pa[] = array('href' => $attn->profileurl,
'class' => 'addressee account', 'title' => $attn->nickname,
'text' => ($streamNicknames) ? $reply->nickname : $reply->getBestName()); 'class' => "addressee {$class}",
'text' => ($streamNicknames) ? $attn->nickname : $attn->getBestName());
} }
return $pa; return $pa;

View File

@ -17,7 +17,7 @@ Settings
======== ========
user*: user part of the jid user*: user part of the jid
server*: server 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 port (5222): port on which to connect to the server
encryption (true): use encryption on the connection encryption (true): use encryption on the connection
host (same as server): host to connect to. Usually, you won't set this. host (same as server): host to connect to. Usually, you won't set this.