X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FConversation.php;h=56f61c63ab2c1453ebd8250c6c17b721bd358bcc;hb=dd61ae8fbeee64c85f8186672292335592be1ff5;hp=4bad474c7334207ef2ab6e8d8040050c7b093b31;hpb=f79aec36feaa4760201a7e88d5b31513a3c458ba;p=quix0rs-gnu-social.git diff --git a/classes/Conversation.php b/classes/Conversation.php old mode 100755 new mode 100644 index 4bad474c73..56f61c63ab --- a/classes/Conversation.php +++ b/classes/Conversation.php @@ -22,36 +22,29 @@ * @category Data * @package StatusNet * @author Zach Copley + * @author Mikael Nordfeldth * @copyright 2010 StatusNet Inc. + * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; +if (!defined('GNUSOCIAL')) { exit(1); } class Conversation extends Managed_DataObject { - ###START_AUTOCODE - /* the code below is auto generated do not remove the above tag */ - - public $__table = 'conversation'; // table name + public $__table = 'conversation'; // table name public $id; // int(4) primary_key not_null - public $uri; // varchar(225) unique_key + public $uri; // varchar(255) unique_key public $created; // datetime not_null public $modified; // timestamp not_null default_CURRENT_TIMESTAMP - /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('conversation',$k,$v); } - - /* the code above is auto generated do not remove the tag below */ - ###END_AUTOCODE - public static function schemaDef() { return array( 'fields' => array( - 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'), - 'uri' => array('type' => 'varchar', 'length' => 225, 'description' => 'URI of the conversation'), + 'id' => array('type' => 'int', 'not null' => true, 'description' => 'should be set from root notice id (since 2014-03-01 commit)'), + 'uri' => array('type' => 'varchar', 'not null'=>true, 'length' => 255, 'description' => 'URI of the conversation'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), ), @@ -63,29 +56,31 @@ class Conversation extends Managed_DataObject } /** - * Factory method for creating a new conversation + * Factory method for creating a new conversation. + * + * Use this for locally initiated conversations. Remote notices should + * preferrably supply their own conversation URIs in the OStatus feed. * * @return Conversation the new conversation DO */ - static function create() + static function create(Notice $notice, $uri=null) { + if (empty($notice->id)) { + throw new ServerException(_('Tried to create conversation for not yet inserted notice')); + } $conv = new Conversation(); $conv->created = common_sql_now(); - $id = $conv->insert(); - - if (empty($id)) { + $conv->id = $notice->id; + $conv->uri = $uri ?: sprintf('%s%s=%d:%s=%s:%s=%x', + TagURI::mint(), + 'noticeId', $notice->id, + 'objectType', 'thread', + 'crc32', crc32($notice->content)); + $result = $conv->insert(); + + if ($result === false) { common_log_db_error($conv, 'INSERT', __FILE__); - return null; - } - - $orig = clone($conv); - $orig->uri = common_local_url('conversation', array('id' => $id), - null, null, false); - $result = $orig->update($conv); - - if (empty($result)) { - common_log_db_error($conv, 'UPDATE', __FILE__); - return null; + throw new ServerException(_('Failed to create conversation for notice')); } return $conv; @@ -103,10 +98,40 @@ class Conversation extends Managed_DataObject $notice = new Notice(); $notice->conversation = $id; + $notice->whereAddIn('verb', array(ActivityVerb::POST, ActivityUtils::resolveUri(ActivityVerb::POST, true)), $notice->columnType('verb')); $cnt = $notice->count(); self::cacheSet($keypart, $cnt); return $cnt; } + + static public function getUrlFromNotice(Notice $notice, $anchor=true) + { + $conv = self::getKV('id', $notice->conversation); + return $conv->getUrl($anchor ? $notice->id : null); + } + + public function getUri() + { + return $this->uri; + } + + public function getUrl($noticeId=null) + { + // FIXME: the URL router should take notice-id as an argument... + return common_local_url('conversation', array('id' => $this->id)) . + ($noticeId===null ? '' : "#notice-{$noticeId}"); + } + + // FIXME: ...will 500 ever be too low? Taken from ConversationAction::MAX_NOTICES + public function getNotices($offset=0, $limit=500, Profile $scoped=null) + { + if ($scoped === null) { + $scoped = Profile::current(); + } + $stream = new ConversationNoticeStream($this->id, $scoped); + $notices = $stream->getNotices($offset, $limit); + return $notices; + } }