Merge pull request #13543 from annando/issue-13535

Issue 13535: Handle Firefish chat messages
pull/13547/head
Hypolite Petovan 2023-10-15 09:12:10 -04:00 committed by GitHub
commit c711208237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 29 deletions

View File

@ -1114,8 +1114,7 @@ class Processor
$item['contact-id'] = Contact::getIdForURL($activity['author']); $item['contact-id'] = Contact::getIdForURL($activity['author']);
} }
if (!empty($activity['directmessage'])) { if (!empty($activity['directmessage']) && self::postMail($item)) {
self::postMail($activity, $item);
continue; continue;
} }
@ -1347,18 +1346,22 @@ class Processor
/** /**
* Creates an mail post * Creates an mail post
* *
* @param array $activity Activity data * @param array $item item array
* @param array $item item array
* @return int|bool New mail table row id or false on error * @return int|bool New mail table row id or false on error
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
private static function postMail(array $activity, array $item) private static function postMail(array $item): bool
{ {
if (($item['gravity'] != Item::GRAVITY_PARENT) && !DBA::exists('mail', ['uri' => $item['thr-parent'], 'uid' => $item['uid']])) { if (($item['gravity'] != Item::GRAVITY_PARENT) && !DBA::exists('mail', ['uri' => $item['thr-parent'], 'uid' => $item['uid']])) {
Logger::info('Parent not found, mail will be discarded.', ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); Logger::info('Parent not found, mail will be discarded.', ['uid' => $item['uid'], 'uri' => $item['thr-parent']]);
return false; return false;
} }
if (!Contact::isFollower($item['contact-id'], $item['uid']) && !Contact::isSharing($item['contact-id'], $item['uid'])) {
Logger::info('Contact is not a sharer or follower, mail will be discarded.', ['item' => $item]);
return false;
}
Logger::info('Direct Message', $item); Logger::info('Direct Message', $item);
$msg = []; $msg = [];

View File

@ -429,6 +429,10 @@ class Receiver
$object_data['directmessage'] = true; $object_data['directmessage'] = true;
} else { } else {
$object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage'); $object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage');
if (!empty(JsonLD::fetchElement($activity['as:object'], 'misskey:_misskey_talk'))) {
$object_data = self::setChatData($object_data, $receivers);
}
} }
} elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Announce', 'as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) { } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Announce', 'as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) {
// Create a mostly empty array out of the activity data (instead of the object). // Create a mostly empty array out of the activity data (instead of the object).
@ -507,6 +511,26 @@ class Receiver
return $object_data; return $object_data;
} }
private static function setChatData(array $object_data, array $receivers): array
{
if (count($receivers) != 1) {
return $object_data;
}
$user = User::getById(array_key_first($receivers), ['language']);
$l10n = DI::l10n()->withLang($user['language']);
$object_data['name'] = $l10n->t('Chat');
$mail = DBA::selectFirst('mail', ['uri'], ['uid' => array_key_first($receivers), 'title' => $object_data['name']], ['order' => ['id' => true]]);
if (!empty($mail['uri'])) {
$object_data['reply-to-id'] = $mail['uri'];
}
$object_data['directmessage'] = true;
Logger::debug('Got Misskey Chat');
return $object_data;
}
/** /**
* Fetches the first user id from the receiver array * Fetches the first user id from the receiver array
* *

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2023.09-rc\n" "Project-Id-Version: 2023.09-rc\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-14 19:09+0000\n" "POT-Creation-Date: 2023-10-15 08:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -72,7 +72,7 @@ msgstr ""
#: src/Module/Settings/Delegation.php:90 src/Module/Settings/Display.php:90 #: src/Module/Settings/Delegation.php:90 src/Module/Settings/Display.php:90
#: src/Module/Settings/Display.php:193 #: src/Module/Settings/Display.php:193
#: src/Module/Settings/Profile/Photo/Crop.php:165 #: src/Module/Settings/Profile/Photo/Crop.php:165
#: src/Module/Settings/Profile/Photo/Index.php:111 #: src/Module/Settings/Profile/Photo/Index.php:112
#: src/Module/Settings/RemoveMe.php:119 src/Module/Settings/UserExport.php:80 #: src/Module/Settings/RemoveMe.php:119 src/Module/Settings/UserExport.php:80
#: src/Module/Settings/UserExport.php:114 #: src/Module/Settings/UserExport.php:114
#: src/Module/Settings/UserExport.php:215 #: src/Module/Settings/UserExport.php:215
@ -2189,8 +2189,8 @@ msgid ""
"<a href=\"%1$s\" target=\"_blank\" rel=\"noopener noreferrer\">%2$s</a> %3$s" "<a href=\"%1$s\" target=\"_blank\" rel=\"noopener noreferrer\">%2$s</a> %3$s"
msgstr "" msgstr ""
#: src/Content/Text/BBCode.php:994 src/Model/Item.php:3816 #: src/Content/Text/BBCode.php:994 src/Model/Item.php:3813
#: src/Model/Item.php:3822 src/Model/Item.php:3823 #: src/Model/Item.php:3819 src/Model/Item.php:3820
msgid "Link to source" msgid "Link to source"
msgstr "" msgstr ""
@ -3430,44 +3430,44 @@ msgstr ""
msgid "Content warning: %s" msgid "Content warning: %s"
msgstr "" msgstr ""
#: src/Model/Item.php:3723 #: src/Model/Item.php:3720
msgid "bytes" msgid "bytes"
msgstr "" msgstr ""
#: src/Model/Item.php:3754 #: src/Model/Item.php:3751
#, php-format #, php-format
msgid "%2$s (%3$d%%, %1$d vote)" msgid "%2$s (%3$d%%, %1$d vote)"
msgid_plural "%2$s (%3$d%%, %1$d votes)" msgid_plural "%2$s (%3$d%%, %1$d votes)"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Model/Item.php:3756 #: src/Model/Item.php:3753
#, php-format #, php-format
msgid "%2$s (%1$d vote)" msgid "%2$s (%1$d vote)"
msgid_plural "%2$s (%1$d votes)" msgid_plural "%2$s (%1$d votes)"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Model/Item.php:3761 #: src/Model/Item.php:3758
#, php-format #, php-format
msgid "%d voter. Poll end: %s" msgid "%d voter. Poll end: %s"
msgid_plural "%d voters. Poll end: %s" msgid_plural "%d voters. Poll end: %s"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Model/Item.php:3763 #: src/Model/Item.php:3760
#, php-format #, php-format
msgid "%d voter." msgid "%d voter."
msgid_plural "%d voters." msgid_plural "%d voters."
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: src/Model/Item.php:3765 #: src/Model/Item.php:3762
#, php-format #, php-format
msgid "Poll end: %s" msgid "Poll end: %s"
msgstr "" msgstr ""
#: src/Model/Item.php:3799 src/Model/Item.php:3800 #: src/Model/Item.php:3796 src/Model/Item.php:3797
msgid "View on separate page" msgid "View on separate page"
msgstr "" msgstr ""
@ -7503,7 +7503,7 @@ msgstr ""
#: src/Module/Media/Attachment/Browser.php:79 #: src/Module/Media/Attachment/Browser.php:79
#: src/Module/Media/Photo/Browser.php:90 #: src/Module/Media/Photo/Browser.php:90
#: src/Module/Settings/Profile/Photo/Index.php:128 #: src/Module/Settings/Profile/Photo/Index.php:129
msgid "Upload" msgid "Upload"
msgstr "" msgstr ""
@ -7526,12 +7526,12 @@ msgstr ""
#: src/Module/Media/Photo/Upload.php:152 src/Module/Media/Photo/Upload.php:153 #: src/Module/Media/Photo/Upload.php:152 src/Module/Media/Photo/Upload.php:153
#: src/Module/Profile/Photos.php:217 #: src/Module/Profile/Photos.php:217
#: src/Module/Settings/Profile/Photo/Index.php:68 #: src/Module/Settings/Profile/Photo/Index.php:69
msgid "Unable to process image." msgid "Unable to process image."
msgstr "" msgstr ""
#: src/Module/Media/Photo/Upload.php:178 src/Module/Profile/Photos.php:237 #: src/Module/Media/Photo/Upload.php:178 src/Module/Profile/Photos.php:237
#: src/Module/Settings/Profile/Photo/Index.php:95 #: src/Module/Settings/Profile/Photo/Index.php:96
msgid "Image upload failed." msgid "Image upload failed."
msgstr "" msgstr ""
@ -8810,7 +8810,7 @@ msgstr ""
#: src/Module/Profile/Photos.php:164 src/Module/Profile/Photos.php:167 #: src/Module/Profile/Photos.php:164 src/Module/Profile/Photos.php:167
#: src/Module/Profile/Photos.php:194 #: src/Module/Profile/Photos.php:194
#: src/Module/Settings/Profile/Photo/Index.php:59 #: src/Module/Settings/Profile/Photo/Index.php:60
#, php-format #, php-format
msgid "Image exceeds size limit of %s" msgid "Image exceeds size limit of %s"
msgstr "" msgstr ""
@ -10615,7 +10615,7 @@ msgstr ""
#: src/Module/Settings/Profile/Photo/Crop.php:107 #: src/Module/Settings/Profile/Photo/Crop.php:107
#: src/Module/Settings/Profile/Photo/Crop.php:125 #: src/Module/Settings/Profile/Photo/Crop.php:125
#: src/Module/Settings/Profile/Photo/Crop.php:143 #: src/Module/Settings/Profile/Photo/Crop.php:143
#: src/Module/Settings/Profile/Photo/Index.php:101 #: src/Module/Settings/Profile/Photo/Index.php:102
#, php-format #, php-format
msgid "Image size reduction [%s] failed." msgid "Image size reduction [%s] failed."
msgstr "" msgstr ""
@ -10651,35 +10651,35 @@ msgstr ""
msgid "Use Image As Is" msgid "Use Image As Is"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:45 #: src/Module/Settings/Profile/Photo/Index.php:46
msgid "Missing uploaded image." msgid "Missing uploaded image."
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:124 #: src/Module/Settings/Profile/Photo/Index.php:125
msgid "Profile Picture Settings" msgid "Profile Picture Settings"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:125 #: src/Module/Settings/Profile/Photo/Index.php:126
msgid "Current Profile Picture" msgid "Current Profile Picture"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:126 #: src/Module/Settings/Profile/Photo/Index.php:127
msgid "Upload Profile Picture" msgid "Upload Profile Picture"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:127 #: src/Module/Settings/Profile/Photo/Index.php:128
msgid "Upload Picture:" msgid "Upload Picture:"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:132 #: src/Module/Settings/Profile/Photo/Index.php:133
msgid "or" msgid "or"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:134 #: src/Module/Settings/Profile/Photo/Index.php:135
msgid "skip this step" msgid "skip this step"
msgstr "" msgstr ""
#: src/Module/Settings/Profile/Photo/Index.php:136 #: src/Module/Settings/Profile/Photo/Index.php:137
msgid "select a photo from your photo albums" msgid "select a photo from your photo albums"
msgstr "" msgstr ""
@ -12179,6 +12179,10 @@ msgstr ""
msgid "Reacted with %s by: %s" msgid "Reacted with %s by: %s"
msgstr "" msgstr ""
#: src/Protocol/ActivityPub/Receiver.php:522
msgid "Chat"
msgstr ""
#: src/Protocol/Delivery.php:547 #: src/Protocol/Delivery.php:547
msgid "(no subject)" msgid "(no subject)"
msgstr "" msgstr ""