Merge branch 'nightly' of git.gnu.io:gnu/gnu-social into mmn_fixes

This commit is contained in:
Mikael Nordfeldth 2016-01-27 22:43:37 +01:00
commit 34093388a7
2 changed files with 25 additions and 11 deletions

View File

@ -771,9 +771,15 @@ class ApiAction extends Action
function showJsonObjects($objects) function showJsonObjects($objects)
{ {
print(json_encode($objects)); $json_objects = json_encode($objects);
if($json_objects === false) {
$this->clientError(_('JSON encoding failed. Error: ').json_last_error_msg());
} else {
print $json_objects;
}
} }
function showSingleXmlStatus($notice) function showSingleXmlStatus($notice)
{ {
$this->initDocument('xml'); $this->initDocument('xml');

View File

@ -725,14 +725,13 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) { if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) {
// Get the context of the original notice, if any // Get the context of the original notice, if any
$origMentions = array(); $origMentions = array();
// Does it have a parent notice for context? // Does it have a parent notice for context?
if ($parent instanceof Notice) { if ($parent instanceof Notice) {
foreach ($parent->getAttentionProfiles() as $repliedTo) { foreach ($parent->getAttentionProfiles() as $repliedTo) {
if (!$repliedTo->isPerson()) { if (!$repliedTo->isPerson()) {
continue; continue;
} }
$origMentions[$repliedTo->getNickname()] = $repliedTo; $origMentions[$repliedTo->id] = $repliedTo;
} }
} }
@ -746,15 +745,24 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
continue; continue;
} }
// Try to get a profile for this nickname. // primarily mention the profiles mentioned in the parent
// Start with conversation context, then go to $mention_found_in_origMentions = false;
// sender context. foreach($origMentions as $origMentionsId=>$origMention) {
if($origMention->getNickname() == $nickname) {
$mention_found_in_origMentions = $origMention;
// don't mention same twice! the parent might have mentioned
// two users with same nickname on different instances
unset($origMentions[$origMentionsId]);
break;
}
}
if ($parent instanceof Notice && $parent->getProfile()->getNickname() === $nickname) { // Try to get a profile for this nickname.
// Start with parents mentions, then go to parents sender context
if ($mention_found_in_origMentions) {
$mentioned = $mention_found_in_origMentions;
} else if ($parent instanceof Notice && $parent->getProfile()->getNickname() === $nickname) {
$mentioned = $parent->getProfile(); $mentioned = $parent->getProfile();
} else if (!empty($origMentions) &&
array_key_exists($nickname, $origMentions)) {
$mentioned = $origMentions[$nickname];
} else { } else {
// sets to null if no match // sets to null if no match
$mentioned = common_relative_profile($sender, $nickname); $mentioned = common_relative_profile($sender, $nickname);