From 71ecd689019a8086570c677af47ead4e02227fb3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 16 Feb 2010 12:45:00 -0500 Subject: add a FIXME to Profile --- classes/Profile.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index ab05bb854..c79b1d893 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -807,6 +807,8 @@ class Profile extends Memcached_DataObject null, 'http://activitystrea.ms/schema/1.0/person' ); + // FIXME: this presupposes a local user -- not necessarily the case + // instead use User::uri or Remote_profile::uri or Ostatus_profile::homeuri $xs->element( 'id', null, -- cgit v1.2.3-54-g00ecf From eea52c708b4688c9b39f24d3931edc9da2cf1b07 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Feb 2010 11:32:10 -0800 Subject: Add rel="avatar" to img links in stanzas --- classes/Profile.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Profile.php b/classes/Profile.php index c79b1d893..8f578c95a 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -807,8 +807,6 @@ class Profile extends Memcached_DataObject null, 'http://activitystrea.ms/schema/1.0/person' ); - // FIXME: this presupposes a local user -- not necessarily the case - // instead use User::uri or Remote_profile::uri or Ostatus_profile::homeuri $xs->element( 'id', null, @@ -824,6 +822,7 @@ class Profile extends Memcached_DataObject $xs->element( 'link', array( 'type' => empty($avatar) ? 'image/png' : $avatar->mediatype, + 'rel' => 'avatar', 'href' => empty($avatar) ? Avatar::defaultImage(AVATAR_PROFILE_SIZE) : $avatar->displayUrl() -- cgit v1.2.3-54-g00ecf From c892726c80b4e466b2bbad0f7b396cf0c7a137d9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Feb 2010 16:22:58 -0800 Subject: Take remote profiles into account when looking up canonical profile URIs --- EVENTS.txt | 5 ++++- classes/Notice.php | 2 +- classes/Profile.php | 21 +++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'classes') diff --git a/EVENTS.txt b/EVENTS.txt index 69fe2ddcc..f333c5442 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1,4 +1,4 @@ -\InitializePlugin: a chance to initialize a plugin in a complete environment +InitializePlugin: a chance to initialize a plugin in a complete environment CleanupPlugin: a chance to cleanup a plugin at the end of a program @@ -722,3 +722,6 @@ StartRobotsTxt: Before outputting the robots.txt page EndRobotsTxt: After the default robots.txt page (good place for customization) - &$action: RobotstxtAction being shown +GetProfileUri: When determining the canonical URI for a given profile +- &$profile: the current profile + diff --git a/classes/Notice.php b/classes/Notice.php index 73b22d58a..f184b9c52 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1036,7 +1036,7 @@ class Notice extends Memcached_DataObject $xs->element( 'link', array( 'rel' => 'ostatus:attention', - 'href' => $profile->getAcctUri() + 'href' => $profile->getUri() ) ); } diff --git a/classes/Profile.php b/classes/Profile.php index 8f578c95a..5a86619fd 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -810,10 +810,7 @@ class Profile extends Memcached_DataObject $xs->element( 'id', null, - common_local_url( - 'userbyid', - array('id' => $this->id) - ) + $this->getUri() ); $xs->element('title', null, $this->getBestName()); @@ -835,9 +832,21 @@ class Profile extends Memcached_DataObject return $xs->getString(); } - function getAcctUri() + function getUri() { - return $this->nickname . '@' . common_config('site', 'server'); + if (Event::handle('GetProfileUri', array($this))) { + + $remote = Remote_profile::staticGet('id', $this->id); + + if (!empty($remote)) { + return $remote->uri; + } else { + return common_local_url( + 'userbyid', + array('id' => $this->id) + ); + } + } } } -- cgit v1.2.3-54-g00ecf From 2cb243808c2c1540f2690bff5a2d9932fa428923 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Feb 2010 20:13:39 -0800 Subject: More sensical profile::getUri() --- EVENTS.txt | 8 ++++++-- classes/Profile.php | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) (limited to 'classes') diff --git a/EVENTS.txt b/EVENTS.txt index f333c5442..90242fa13 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -722,6 +722,10 @@ StartRobotsTxt: Before outputting the robots.txt page EndRobotsTxt: After the default robots.txt page (good place for customization) - &$action: RobotstxtAction being shown -GetProfileUri: When determining the canonical URI for a given profile -- &$profile: the current profile +StartGetProfileUri: When determining the canonical URI for a given profile +- $profile: the current profile +- &$uri: the URI +EndGetProfileUri: After determining the canonical URI for a given profile +- $profile: the current profile +- &$uri: the URI diff --git a/classes/Profile.php b/classes/Profile.php index 5a86619fd..494c697e4 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -769,7 +769,7 @@ class Profile extends Memcached_DataObject $xs->elementStart('author'); $xs->element('name', null, $this->nickname); - $xs->element('uri', null, $this->profileurl); + $xs->element('uri', null, $this->getUri()); $xs->elementEnd('author'); return $xs->getString(); @@ -832,21 +832,40 @@ class Profile extends Memcached_DataObject return $xs->getString(); } + /** + * Returns the best URI for a profile. Plugins may override. + * + * @return string $uri + */ function getUri() { - if (Event::handle('GetProfileUri', array($this))) { + $uri = null; - $remote = Remote_profile::staticGet('id', $this->id); + // check for a local user first + $user = User::staticGet('id', $this->id); - if (!empty($remote)) { - return $remote->uri; - } else { - return common_local_url( - 'userbyid', - array('id' => $this->id) - ); + if (!empty($user)) { + $uri = common_local_url( + 'userbyid', + array('id' => $user->id) + ); + } else { + + // give plugins a chance to set the URI + if (Event::handle('StartGetProfileUri', array($this, &$uri))) { + + // return OMB profile if any + $remote = Remote_profile::staticGet('id', $this->id); + + if (!empty($remote)) { + $uri = $remote->uri; + } + + Event::handle('EndGetProfileUri', array($this, &$uri)); } } + + return $uri; } } -- cgit v1.2.3-54-g00ecf From a2f8c5da171d23790811677affd7ca5301a995a5 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 16 Feb 2010 23:30:08 -0800 Subject: New Conversation DO to handle remote notices as conversation roots --- classes/Conversation.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ classes/statusnet.ini | 9 +++++++++ db/statusnet.sql | 8 ++++++++ 3 files changed, 66 insertions(+) create mode 100755 classes/Conversation.php (limited to 'classes') diff --git a/classes/Conversation.php b/classes/Conversation.php new file mode 100755 index 000000000..929b06c14 --- /dev/null +++ b/classes/Conversation.php @@ -0,0 +1,49 @@ +. + * + * @category Data + * @package StatusNet + * @author Zach Copley + * @copyright 2010 StatusNet Inc. + * @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'; + +class Conversation extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'conversation'; // table name + public $id; // int(4) primary_key not_null + public $uri; // varchar(225) unique_key not_null + public $created; // datetime not_null + public $modified; // timestamp not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Session',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} + diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 5f8da7cf5..7a9ae07e7 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -47,6 +47,15 @@ modified = 384 [consumer__keys] consumer_key = K +[conversation] +id = 129 +uri = 130 +created = 142 +modified = 384 + +[conversation__keys] +id = N + [deleted_notice] id = 129 profile_id = 129 diff --git a/db/statusnet.sql b/db/statusnet.sql index 343464801..74e5b6954 100644 --- a/db/statusnet.sql +++ b/db/statusnet.sql @@ -633,3 +633,11 @@ create table inbox ( constraint primary key (user_id) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table conversation ( + id integer auto_increment primary key comment 'unique identifier', + uri varchar(225) not null unique comment 'URI of the conversation', + created datetime not null comment 'date this record was created', + modified timestamp comment 'date this record was modified' +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + -- cgit v1.2.3-54-g00ecf From ed46a38ecfea0a87e01aacfcde181087d5e0f19f Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Feb 2010 01:11:14 -0800 Subject: - conversation.uri needs to be nullable - factory method for creating new local conversations --- classes/Conversation.php | 33 +++++++++++++++++++++++++++++++-- classes/statusnet.ini | 3 ++- db/statusnet.sql | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'classes') diff --git a/classes/Conversation.php b/classes/Conversation.php index 929b06c14..ea8bd87b5 100755 --- a/classes/Conversation.php +++ b/classes/Conversation.php @@ -36,14 +36,43 @@ class Conversation extends Memcached_DataObject public $__table = 'conversation'; // table name public $id; // int(4) primary_key not_null - public $uri; // varchar(225) unique_key not_null + public $uri; // varchar(225) 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('Session',$k,$v); } + 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 + + /** + * Factory method for creating a new conversation + * + * @return Conversation the new conversation DO + */ + static function create() + { + $conv = new Conversation(); + $conv->created = common_sql_now(); + $id = $conv->insert(); + + if (empty($id)) { + common_log_db_error($conv, 'INSERT', __FILE__); + return null; + } + + $orig = clone($conv); + $orig->uri = common_local_url('conversation', array('id' => $id)); + $result = $orig->update($conv); + + if (empty($result)) { + common_log_db_error($conv, 'UPDATE', __FILE__); + return null; + } + + return $conv; + } + } diff --git a/classes/statusnet.ini b/classes/statusnet.ini index 7a9ae07e7..81c1b68b2 100644 --- a/classes/statusnet.ini +++ b/classes/statusnet.ini @@ -49,12 +49,13 @@ consumer_key = K [conversation] id = 129 -uri = 130 +uri = 2 created = 142 modified = 384 [conversation__keys] id = N +uri = U [deleted_notice] id = 129 diff --git a/db/statusnet.sql b/db/statusnet.sql index 74e5b6954..97117c80a 100644 --- a/db/statusnet.sql +++ b/db/statusnet.sql @@ -636,7 +636,7 @@ create table inbox ( create table conversation ( id integer auto_increment primary key comment 'unique identifier', - uri varchar(225) not null unique comment 'URI of the conversation', + uri varchar(225) unique comment 'URI of the conversation', created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified' ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; -- cgit v1.2.3-54-g00ecf From 198c046c896c2a1c4dc9037fa538c14179e827ce Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Feb 2010 01:12:13 -0800 Subject: - Set the root of a new local conversation to a new conversation.id - Output conversation URIs from conversation.uri --- classes/Notice.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index f184b9c52..b0edb6de6 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -309,7 +309,8 @@ class Notice extends Memcached_DataObject // the beginning of a new conversation. if (empty($notice->conversation)) { - $notice->conversation = $notice->id; + $conv = Conversation::create(); + $notice->conversation = $conv->id; $changed = true; } @@ -331,14 +332,15 @@ class Notice extends Memcached_DataObject return $notice; } - function blowOnInsert() + function blowOnInsert($conversation = false) { self::blow('profile:notice_ids:%d', $this->profile_id); self::blow('public'); - if ($this->conversation != $this->id) { - self::blow('notice:conversation_ids:%d', $this->conversation); - } + // XXX: Before we were blowing the casche only if the notice id + // was not the root of the conversation. What to do now? + + self::blow('notice:conversation_ids:%d', $this->conversation); if (!empty($this->repeat_of)) { self::blow('notice:repeats:%d', $this->repeat_of); @@ -1015,24 +1017,25 @@ class Notice extends Memcached_DataObject } } - if (!empty($this->conversation) - && $this->conversation != $this->id) { - $xs->element( - 'link', array( - 'rel' => 'ostatus:conversation', - 'href' => common_local_url( - 'conversation', - array('id' => $this->conversation) - ) + if (!empty($this->conversation)) { + + $conv = Conversation::staticGet('id', $this->conversation); + + if (!empty($conv)) { + $xs->element( + 'link', array( + 'rel' => 'ostatus:conversation', + 'href' => $conv->uri ) ); + } } $reply_ids = $this->getReplies(); foreach ($reply_ids as $id) { $profile = Profile::staticGet('id', $id); - if (!empty($profile)) { + if (!empty($profile)) { $xs->element( 'link', array( 'rel' => 'ostatus:attention', -- cgit v1.2.3-54-g00ecf