From a5cfda850537e5e55d61f381cfac7d5100aa3bea Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 26 Feb 2010 17:47:39 -0500 Subject: blow cache on known replies --- classes/Notice.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index ac4640534..2d02a9a19 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -944,6 +944,8 @@ class Notice extends Memcached_DataObject $reply->profile_id = $user->id; $id = $reply->insert(); + + self::blow('reply:stream:%d', $user->id); } } -- cgit v1.2.3-54-g00ecf From 4d9daf21493e75354190667e5c1ab3140b46dee1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 27 Feb 2010 16:06:46 -0500 Subject: Use notice for context when deciding who @nickname refers to In a federated system, "@nickname" is insufficient to uniquely identify a user. However, it's a very convenient idiom. We need to guess from context who 'nickname' refers to. Previously, we were using the sender's profile (or what we knew about them) as the only context. So, we assumed that they'd be mentioning to someone they followed, or someone who followed them, or someone on their own server. Now, we include the notice information for context. We check to see if the notice is a reply to another notice, and if the author of the original notice has the nickname 'nickname', then the mention is probably for them. Alternately, if the original notice mentions someone with nickname 'nickname', then this notice is probably referring to _them_. Doing this kind of context sleuthing means we have to render the content very late in the notice-saving process. --- classes/Notice.php | 12 ++++++------ lib/util.php | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 2d02a9a19..6614f3d55 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -282,12 +282,6 @@ class Notice extends Memcached_DataObject $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; @@ -315,6 +309,12 @@ class Notice extends Memcached_DataObject $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 diff --git a/lib/util.php b/lib/util.php index 32061ec04..d12a7920d 100644 --- a/lib/util.php +++ b/lib/util.php @@ -426,14 +426,14 @@ function common_render_content($text, $notice) { $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 @@ -487,11 +487,11 @@ function common_linkify_mention($mention) 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; @@ -499,6 +499,30 @@ function common_find_mentions($profile_id, $text) 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, @@ -514,7 +538,22 @@ function common_find_mentions($profile_id, $text) 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)) { -- cgit v1.2.3-54-g00ecf From 04c4facba9230f40726c5891dcac21d928fbb2ab Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 27 Feb 2010 16:30:38 -0500 Subject: fix call of common_find_mentions() in Notice::saveReplies() --- classes/Notice.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 6614f3d55..3702dbcfa 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -973,7 +973,10 @@ class Notice extends Memcached_DataObject $sender = Profile::staticGet($this->profile_id); - $mentions = common_find_mentions($this->profile_id, $this->content); + // @todo ideally this parser information would only + // be calculated once. + + $mentions = common_find_mentions($this->content, $this); $replied = array(); -- cgit v1.2.3-54-g00ecf