Merge pull request #13660 from annando/issue-13627-a
Issue 13627: DMs now work bidirectional again
This commit is contained in:
commit
6fa7b45294
3 changed files with 65 additions and 16 deletions
|
@ -1111,6 +1111,10 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($activity['directmessage']) && self::postMail($item)) {
|
if (!empty($activity['directmessage']) && self::postMail($item)) {
|
||||||
|
if (!empty($item['source']) && DI::config()->get('debug', 'store_source')) {
|
||||||
|
Post\Activity::insert($item['uri-id'], $item['source']);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -436,15 +436,11 @@ class Receiver
|
||||||
|
|
||||||
$object_data['object_id'] = $object_id;
|
$object_data['object_id'] = $object_id;
|
||||||
|
|
||||||
// Test if it is an answer to a mail
|
// Test if it is a direct message
|
||||||
if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
|
if (self::checkForDirectMessage($object_data, $activity)) {
|
||||||
$object_data['directmessage'] = true;
|
$object_data['directmessage'] = true;
|
||||||
} else {
|
} elseif (!empty(JsonLD::fetchElement($activity['as:object'], 'misskey:_misskey_talk'))) {
|
||||||
$object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage');
|
$object_data = self::setChatData($object_data, $receivers);
|
||||||
|
|
||||||
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).
|
||||||
|
@ -523,6 +519,57 @@ class Receiver
|
||||||
return $object_data;
|
return $object_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the received message is a direct message
|
||||||
|
*
|
||||||
|
* @param array $object_data
|
||||||
|
* @param array $activity
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private static function checkForDirectMessage(array $object_data, array $activity): bool
|
||||||
|
{
|
||||||
|
if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($object_data['id'] != $object_data['reply-to-id']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (JsonLD::fetchElement($activity, 'litepub:directMessage')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($object_data['attachments'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($object_data['receiver_urls']['as:cc']) || empty($object_data['receiver_urls']['as:to'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((count($object_data['receiver_urls']['as:to']) != 1) || !User::getIdForURL($object_data['receiver_urls']['as:to'][0])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mentions = 0;
|
||||||
|
foreach ($object_data['tags'] as $mention) {
|
||||||
|
if ($mention['type'] != 'Mention') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!User::getIdForURL($mention['href'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++$mentions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($mentions > 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static function setChatData(array $object_data, array $receivers): array
|
private static function setChatData(array $object_data, array $receivers): array
|
||||||
{
|
{
|
||||||
if (count($receivers) != 1) {
|
if (count($receivers) != 1) {
|
||||||
|
@ -682,7 +729,7 @@ class Receiver
|
||||||
self::addArrivedId($object_data['object_id']);
|
self::addArrivedId($object_data['object_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$decouple = DI::config()->get('system', 'decoupled_receiver') && !in_array($completion, [self::COMPLETION_MANUAL, self::COMPLETION_ANNOUNCE]);
|
$decouple = DI::config()->get('system', 'decoupled_receiver') && !in_array($completion, [self::COMPLETION_MANUAL, self::COMPLETION_ANNOUNCE]) && empty($object_data['directmessage']);
|
||||||
|
|
||||||
if ($decouple && ($trust_source || DI::config()->get('debug', 'ap_inbox_store_untrusted'))) {
|
if ($decouple && ($trust_source || DI::config()->get('debug', 'ap_inbox_store_untrusted'))) {
|
||||||
$object_data = Queue::add($object_data, $type, $uid, $http_signer, $push, $trust_source);
|
$object_data = Queue::add($object_data, $type, $uid, $http_signer, $push, $trust_source);
|
||||||
|
|
|
@ -1121,19 +1121,17 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
public static function fetchTargetInboxesFromMail(int $mail_id): array
|
public static function fetchTargetInboxesFromMail(int $mail_id): array
|
||||||
{
|
{
|
||||||
$mail = DBA::selectFirst('mail', ['uid', 'parent-uri', 'from-url'], ['id' => $mail_id]);
|
$mail = DBA::selectFirst('mail', ['contact-id'], ['id' => $mail_id]);
|
||||||
if (!DBA::isResult($mail)) {
|
if (!DBA::isResult($mail)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$reply = DBA::selectFirst('mail', ['from-url'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
|
$account = DBA::selectFirst('account-user-view', ['ap-inbox'], ['id' => $mail['contact-id']]);
|
||||||
if (!DBA::isResult($reply)) {
|
if (empty($account['ap-inbox'])) {
|
||||||
$reply = $mail;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$apcontact = APContact::getByURL($reply['from-url'], false);
|
return [$account['ap-inbox'] => [$mail['contact-id']]];
|
||||||
|
|
||||||
return [$apcontact['inbox'] => [Contact::getIdForURL($reply['from-url'])]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue