]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
correct mentions if parent mention multiple users with same nickname (don't use first...
authorhannes <h@nnesmannerhe.im>
Tue, 19 Jan 2016 13:41:25 +0000 (13:41 +0000)
committerhannes <h@nnesmannerhe.im>
Tue, 19 Jan 2016 13:41:25 +0000 (13:41 +0000)
lib/util.php

index 20306635afd53e4e44614d5cae0e205b28c42687..91c273714e803e7cdd9d468cbfd7861dba95a197 100644 (file)
@@ -725,14 +725,13 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
     if (Event::handle('StartFindMentions', array($sender, $text, &$mentions))) {
         // Get the context of the original notice, if any
         $origMentions = array();
-
         // Does it have a parent notice for context?
         if ($parent instanceof Notice) {
             foreach ($parent->getAttentionProfiles() as $repliedTo) {
                 if (!$repliedTo->isPerson()) {
                     continue;
                 }
-                $origMentions[$repliedTo->getNickname()] = $repliedTo;
+                $origMentions[$repliedTo->id] = $repliedTo;
             }
         }
 
@@ -746,15 +745,24 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
                 continue;
             }
 
-            // Try to get a profile for this nickname.
-            // Start with conversation context, then go to
-            // sender context.
+                       // primarily mention the profiles mentioned in the parent
+            $mention_found_in_origMentions = false;
+            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();
-            } else if (!empty($origMentions) &&
-                       array_key_exists($nickname, $origMentions)) {
-                $mentioned = $origMentions[$nickname];
             } else {
                 // sets to null if no match
                 $mentioned = common_relative_profile($sender, $nickname);
@@ -2462,4 +2470,4 @@ function html_sprintf()
 function _ve($var)
 {
     return var_export($var, true);
-}
+}
\ No newline at end of file