summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php55
1 files changed, 51 insertions, 4 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index bca4b22c4..78786b27d 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -46,6 +46,7 @@ class Notice extends Memcached_DataObject
public $reply_to; // int(4)
public $is_local; // tinyint(1)
public $source; // varchar(32)
+ public $conversation; // int(4)
/* Static get */
function staticGet($k,$v=NULL) {
@@ -119,7 +120,8 @@ class Notice extends Memcached_DataObject
}
}
- static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
+ static function saveNew($profile_id, $content, $source=null,
+ $is_local=1, $reply_to=null, $uri=null, $created=null) {
$profile = Profile::staticGet($profile_id);
@@ -170,12 +172,24 @@ class Notice extends Memcached_DataObject
$notice->query('BEGIN');
$notice->reply_to = $reply_to;
- $notice->created = common_sql_now();
+ if (!empty($created)) {
+ $notice->created = $created;
+ } else {
+ $notice->created = common_sql_now();
+ }
$notice->content = $final;
$notice->rendered = common_render_content($final, $notice);
$notice->source = $source;
$notice->uri = $uri;
+ if (!empty($reply_to)) {
+ $reply_notice = Notice::staticGet('id', $reply_to);
+ if (!empty($reply_notice)) {
+ $notice->reply_to = $reply_to;
+ $notice->conversation = $reply_notice->conversation;
+ }
+ }
+
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
@@ -265,6 +279,30 @@ class Notice extends Memcached_DataObject
return true;
}
+ function getUploadedAttachment() {
+ $post = clone $this;
+ $query = 'select file.url as up, file.id as i from file join file_to_post on file.id = file_id where post_id=' . $post->escape($post->id) . ' and url like "%/notice/%/file"';
+ $post->query($query);
+ $post->fetch();
+ if (empty($post->up) || empty($post->i)) {
+ $ret = false;
+ } else {
+ $ret = array($post->up, $post->i);
+ }
+ $post->free();
+ return $ret;
+ }
+
+ function hasAttachments() {
+ $post = clone $this;
+ $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id);
+ $post->query($query);
+ $post->fetch();
+ $n_attachments = intval($post->n_attachments);
+ $post->free();
+ return $n_attachments;
+ }
+
function blowCaches($blowLast=false)
{
$this->blowSubsCache($blowLast);
@@ -804,6 +842,7 @@ class Notice extends Memcached_DataObject
if ($recipient_notice) {
$orig = clone($this);
$this->reply_to = $recipient_notice->id;
+ $this->conversation = $recipient_notice->conversation;
$this->update($orig);
}
}
@@ -853,6 +892,14 @@ class Notice extends Memcached_DataObject
}
}
+ // If it's not a reply, make it the root of a new conversation
+
+ if (empty($this->conversation)) {
+ $orig = clone($this);
+ $this->conversation = $this->id;
+ $this->update($orig);
+ }
+
foreach (array_keys($replied) as $recipient) {
$user = User::staticGet('id', $recipient);
if ($user) {
@@ -983,7 +1030,7 @@ class Notice extends Memcached_DataObject
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- $last_id, 0, null)));
+ $last_id, 0, null, $tag)));
$new_window = array_merge($new_ids, $window);
@@ -998,7 +1045,7 @@ class Notice extends Memcached_DataObject
}
$window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- 0, 0, null)));
+ 0, 0, null, $tag)));
$windowstr = implode(',', $window);