summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rwxr-xr-xclasses/Conversation.php78
-rw-r--r--classes/Notice.php35
-rw-r--r--classes/Profile.php42
-rw-r--r--classes/statusnet.ini10
4 files changed, 142 insertions, 23 deletions
diff --git a/classes/Conversation.php b/classes/Conversation.php
new file mode 100755
index 000000000..ea8bd87b5
--- /dev/null
+++ b/classes/Conversation.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Data class for Conversations
+ *
+ * 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 Data
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @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
+ 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
+
+ /**
+ * 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/Notice.php b/classes/Notice.php
index 73b22d58a..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,28 +1017,29 @@ 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',
- 'href' => $profile->getAcctUri()
+ 'href' => $profile->getUri()
)
);
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 8f578c95a..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();
@@ -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,40 @@ class Profile extends Memcached_DataObject
return $xs->getString();
}
- function getAcctUri()
+ /**
+ * Returns the best URI for a profile. Plugins may override.
+ *
+ * @return string $uri
+ */
+ function getUri()
{
- return $this->nickname . '@' . common_config('site', 'server');
+ $uri = null;
+
+ // check for a local user first
+ $user = User::staticGet('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;
}
}
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
index 5f8da7cf5..81c1b68b2 100644
--- a/classes/statusnet.ini
+++ b/classes/statusnet.ini
@@ -47,6 +47,16 @@ modified = 384
[consumer__keys]
consumer_key = K
+[conversation]
+id = 129
+uri = 2
+created = 142
+modified = 384
+
+[conversation__keys]
+id = N
+uri = U
+
[deleted_notice]
id = 129
profile_id = 129