]> git.mxchange.org Git - friendica-addons.git/commitdiff
[twitter] Add custom handling for foreign reshares
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Oct 2018 05:15:15 +0000 (01:15 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Oct 2018 05:15:15 +0000 (01:15 -0400)
twitter/twitter.php

index b17d9ad197284c16f8cca4658a79514ac2231051..1cb7162598f72d83cd2e7c09fd8bc79ffb31afcb 100644 (file)
@@ -554,6 +554,14 @@ function twitter_post_hook(App $a, array &$b)
 
                $max_char = 280;
 
+               // Handling non-native reshares
+               $b['body'] = Friendica\Content\Text\BBCode::convertShare(
+                       $b['body'],
+                       function (array $attributes, array $author_contact, $content) {
+                               return twitter_convert_share($attributes, $author_contact, $content);
+                       }
+               );
+
                $b['body'] = twitter_update_mentions($b['body']);
 
                $msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 8);
@@ -1882,3 +1890,14 @@ function twitter_update_mentions($body)
 
        return $return;
 }
+
+function twitter_convert_share(array $attributes, array $author_contact, $content)
+{
+       if ($author_contact['network'] == Protocol::TWITTER) {
+               $mention = '@' . $author_contact['nickname'];
+       } else {
+               $mention = Protocol::formatMention($attributes['profile'], $attributes['author']);
+       }
+
+       return 'RT ' . $mention . ': ' . $content;
+}