'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'who made the update'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'),
- 'content' => array('type' => 'text', 'description' => 'update content', 'collate' => 'utf8_general_ci'),
+ 'content' => array('type' => 'text', 'description' => 'update content', 'collate' => 'utf8mb4_general_ci'),
'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
'url' => array('type' => 'varchar', 'length' => 191, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
$stored->insert(); // throws exception on error
$orig = clone($stored); // for updating later in this try clause
+ $object = null;
+ Event::handle('StoreActivityObject', array($act, $stored, $options, &$object));
+ if (empty($object)) {
+ throw new ServerException('Unsuccessful call to StoreActivityObject '.$stored->uri . ': '.$act->asString());
+ }
+
// If it's not part of a conversation, it's
// the beginning of a new conversation.
if (empty($stored->conversation)) {
$stored->conversation = $conv->id;
}
- $object = null;
- Event::handle('StoreActivityObject', array($act, $stored, $options, &$object));
- if (empty($object)) {
- throw new ServerException('No object from StoreActivityObject '.$stored->uri . ': '.$act->asString());
- }
- $stored->object_type = ActivityUtils::resolveUri($object->getObjectType(), true);
$stored->update($orig);
} catch (Exception $e) {
if (empty($stored->id)) {
*/
function saveUrls() {
if (common_config('attachments', 'process_links')) {
- common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id);
+ common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this);
}
}
if (common_config('attachments', 'process_links')) {
// @fixme validation?
foreach (array_unique($urls) as $url) {
- try {
- File::processNew($url, $this->id);
- } catch (ServerException $e) {
- // Could not save URL. Log it?
- }
+ $this->saveUrl($url, $this);
}
}
}
/**
* @private callback
*/
- function saveUrl($url, $notice_id) {
+ function saveUrl($url, Notice $notice) {
try {
- File::processNew($url, $notice_id);
+ File::processNew($url, $notice);
} catch (ServerException $e) {
// Could not save URL. Log it?
}
$last = $parent;
continue;
}
- } catch (Exception $e) {
+ } catch (NoParentNoticeException $e) {
// Latest notice has no parent
}
// No parent, or parent out of scope
$this->saveReply($parentauthor->id);
$replied[$parentauthor->id] = 1;
self::blow('reply:stream:%d', $parentauthor->id);
- } catch (Exception $e) {
+ } catch (NoParentNoticeException $e) {
// Not a reply, since it has no parent!
}
foreach ($mention['mentioned'] as $mentioned) {
// skip if they're already covered
-
- if (!empty($replied[$mentioned->id])) {
+ if (array_key_exists($mentioned->id, $replied)) {
continue;
}
$act->verb = $this->verb;
- if ($this->repeat_of) {
- $repeated = Notice::getKV('id', $this->repeat_of);
- if ($repeated instanceof Notice) {
- // TRANS: A repeat activity's title. %1$s is repeater's nickname
- // and %2$s is the repeated user's nickname.
- $act->title = sprintf(_('%1$s repeated a notice by %2$s'),
- $this->getProfile()->getNickname(),
- $repeated->getProfile()->getNickname());
- $act->objects[] = $repeated->asActivity($scoped);
- }
- } else {
+ if (!$this->repeat_of) {
$act->objects[] = $this->asActivityObject();
}
$attachments = $this->attachments();
foreach ($attachments as $attachment) {
- // Save local attachments
+ // Include local attachments in Activity
if (!empty($attachment->filename)) {
- $act->attachments[] = ActivityObject::fromFile($attachment);
+ $act->enclosures[] = $attachment->getEnclosure();
}
}
try {
$reply = $this->getParent();
$ctx->replyToID = $reply->getUri();
- $ctx->replyToUrl = $reply->getUrl();
- } catch (Exception $e) {
+ $ctx->replyToUrl = $reply->getUrl(true); // true for fallback to local URL, less messy
+ } catch (NoParentNoticeException $e) {
// This is not a reply to something
}
public function getParent()
{
- $parent = Notice::getKV('id', $this->reply_to);
-
- if (!$parent instanceof Notice) {
- throw new ServerException('Notice has no parent');
+ if (empty($this->reply_to)) {
+ throw new NoParentNoticeException($this);
}
-
- return $parent;
+ return self::getByID($this->reply_to);
}
/**
$notice->_setReplies($ids);
}
}
-
- protected $_repeats = array();
-
- function getRepeats()
- {
- if (isset($this->_repeats[$this->id])) {
- return $this->_repeats[$this->id];
- }
- $repeatMap = Notice::listGet('repeat_of', array($this->id));
- $this->_repeats[$this->id] = $repeatMap[$this->id];
- return $this->_repeats[$this->id];
- }
-
- function _setRepeats($repeats)
- {
- $this->_repeats[$this->id] = $repeats;
- }
-
- static function fillRepeats(&$notices)
- {
- $ids = self::_idsOf($notices);
- $repeatMap = Notice::listGet('repeat_of', $ids);
- foreach ($notices as $notice) {
- $repeats = $repeatMap[$notice->id];
- $notice->_setRepeats($repeats);
- }
- }
}