$notice->content = $final;
- if (!empty($rendered)) {
- $notice->rendered = $rendered;
- } else {
- $notice->rendered = common_render_content($final, $notice);
- }
-
$notice->source = $source;
$notice->uri = $uri;
$notice->url = $url;
$notice->location_ns = $location_ns;
}
+ if (!empty($rendered)) {
+ $notice->rendered = $rendered;
+ } else {
+ $notice->rendered = common_render_content($final, $notice);
+ }
+
if (Event::handle('StartNoticeSave', array(&$notice))) {
// XXX: some of these functions write to the DB
{
$r = common_render_text($text);
$id = $notice->profile_id;
- $r = common_linkify_mentions($id, $r);
+ $r = common_linkify_mentions($r, $notice);
$r = preg_replace('/(^|[\s\.\,\:\;]+)!([A-Za-z0-9]{1,64})/e', "'\\1!'.common_group_link($id, '\\2')", $r);
return $r;
}
-function common_linkify_mentions($profile_id, $text)
+function common_linkify_mentions($text, $notice)
{
- $mentions = common_find_mentions($profile_id, $text);
+ $mentions = common_find_mentions($text, $notice);
// We need to go through in reverse order by position,
// so our positions stay valid despite our fudging with the
return $output;
}
-function common_find_mentions($profile_id, $text)
+function common_find_mentions($text, $notice)
{
$mentions = array();
- $sender = Profile::staticGet('id', $profile_id);
+ $sender = Profile::staticGet('id', $notice->profile_id);
if (empty($sender)) {
return $mentions;
if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) {
+ // Get the context of the original notice, if any
+
+ $originalAuthor = null;
+ $originalNotice = null;
+ $originalMentions = array();
+
+ // Is it a reply?
+
+ if (!empty($notice) && !empty($notice->reply_to)) {
+ $originalNotice = Notice::staticGet('id', $notice->reply_to);
+ if (!empty($originalNotice)) {
+ $originalAuthor = Profile::staticGet('id', $originalNotice->profile_id);
+
+ $ids = $originalNotice->getReplies();
+
+ foreach ($ids as $id) {
+ $repliedTo = Profile::staticGet('id', $id);
+ if (!empty($repliedTo)) {
+ $originalMentions[$repliedTo->nickname] = $repliedTo;
+ }
+ }
+ }
+ }
+
preg_match_all('/^T ([A-Z0-9]{1,64}) /',
$text,
$tmatches,
foreach ($matches as $match) {
$nickname = common_canonical_nickname($match[0]);
- $mentioned = common_relative_profile($sender, $nickname);
+
+ // Try to get a profile for this nickname.
+ // Start with conversation context, then go to
+ // sender context.
+
+ if (!empty($originalAuthor) && $originalAuthor->nickname == $nickname) {
+
+ $mentioned = $originalAuthor;
+
+ } else if (!empty($originalMentions) &&
+ array_key_exists($nickname, $originalMentions)) {
+
+ $mention = $originalMentions[$nickname];
+ } else {
+ $mentioned = common_relative_profile($sender, $nickname);
+ }
if (!empty($mentioned)) {