Issue 13535: Handle Firefish chat messages
This commit is contained in:
parent
e99fcfddb5
commit
3f9783f288
2 changed files with 32 additions and 5 deletions
|
@ -1114,8 +1114,7 @@ class Processor
|
|||
$item['contact-id'] = Contact::getIdForURL($activity['author']);
|
||||
}
|
||||
|
||||
if (!empty($activity['directmessage'])) {
|
||||
self::postMail($activity, $item);
|
||||
if (!empty($activity['directmessage']) && self::postMail($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1347,18 +1346,22 @@ class Processor
|
|||
/**
|
||||
* 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
|
||||
* @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']])) {
|
||||
Logger::info('Parent not found, mail will be discarded.', ['uid' => $item['uid'], 'uri' => $item['thr-parent']]);
|
||||
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);
|
||||
|
||||
$msg = [];
|
||||
|
|
|
@ -429,6 +429,10 @@ class Receiver
|
|||
$object_data['directmessage'] = true;
|
||||
} else {
|
||||
$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)) {
|
||||
// Create a mostly empty array out of the activity data (instead of the object).
|
||||
|
@ -507,6 +511,26 @@ class Receiver
|
|||
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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue