From ce46ab25730816c9de70b2a4dae1eb87fbeeced4 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Aug 2021 23:49:09 +0000 Subject: [PATCH] The Matrix and XMPP address is now transported via AP as well --- database.sql | 4 +++- doc/database/db_apcontact.md | 2 ++ src/Model/APContact.php | 12 ++++++++++++ src/Protocol/ActivityPub.php | 2 ++ src/Protocol/ActivityPub/Transmitter.php | 11 +++++++++++ static/dbstructure.config.php | 4 +++- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/database.sql b/database.sql index 3c2feb59f1..4d444cbe50 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2021.09-dev (Siberian Iris) --- DB_UPDATE_VERSION 1432 +-- DB_UPDATE_VERSION 1433 -- ------------------------------------------ @@ -332,6 +332,8 @@ CREATE TABLE IF NOT EXISTS `apcontact` ( `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '', `name` varchar(255) COMMENT '', `about` text COMMENT '', + `xmpp` varchar(255) COMMENT 'XMPP address', + `matrix` varchar(255) COMMENT 'Matrix address', `photo` varchar(255) COMMENT '', `header` varchar(255) COMMENT 'Header picture', `addr` varchar(255) COMMENT '', diff --git a/doc/database/db_apcontact.md b/doc/database/db_apcontact.md index 5abf60f10f..ee95d994f9 100644 --- a/doc/database/db_apcontact.md +++ b/doc/database/db_apcontact.md @@ -22,6 +22,8 @@ Fields | nick | | varchar(255) | NO | | | | | name | | varchar(255) | YES | | NULL | | | about | | text | YES | | NULL | | +| xmpp | XMPP address | varchar(255) | YES | | NULL | | +| matrix | Matrix address | varchar(255) | YES | | NULL | | | photo | | varchar(255) | YES | | NULL | | | header | Header picture | varchar(255) | YES | | NULL | | | addr | | varchar(255) | YES | | NULL | | diff --git a/src/Model/APContact.php b/src/Model/APContact.php index d0a0d0d3f6..13add7e658 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -239,6 +239,18 @@ class APContact $apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value')); + $ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage'); + if (!empty($ims)) { + foreach ($ims as $link) { + if (substr($link, 0, 5) == 'xmpp:') { + $apcontact['xmpp'] = substr($link, 5); + } + if (substr($link, 0, 7) == 'matrix:') { + $apcontact['matrix'] = substr($link, 7); + } + } + } + $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id'); if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) { $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id'); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 0f62ab5376..153ee54658 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -157,6 +157,8 @@ class ActivityPub // $profile['keywords'] // $profile['location'] $profile['about'] = $apcontact['about']; + $profile['xmpp'] = $apcontact['xmpp']; + $profile['matrix'] = $apcontact['matrix']; $profile['batch'] = $apcontact['sharedinbox']; $profile['notify'] = $apcontact['inbox']; $profile['poll'] = $apcontact['outbox']; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 2ca40259d5..ab23f81d84 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -352,6 +352,17 @@ class Transmitter $data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL); } + if (!empty($owner['xmpp']) || !empty($owner['matrix'])) { + $data['vcard:hasInstantMessage'] = []; + + if (!empty($owner['xmpp'])) { + $data['vcard:hasInstantMessage'][] = 'xmpp:' . $owner['xmpp']; + } + if (!empty($owner['matrix'])) { + $data['vcard:hasInstantMessage'][] = 'matrix:' . $owner['matrix']; + } + } + $data['url'] = $owner['url']; $data['manuallyApprovesFollowers'] = in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]); $data['discoverable'] = (bool)$owner['net-publish']; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 23b64860c3..f820401a19 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1432); + define('DB_UPDATE_VERSION', 1433); } return [ @@ -392,6 +392,8 @@ return [ "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "name" => ["type" => "varchar(255)", "comment" => ""], "about" => ["type" => "text", "comment" => ""], + "xmpp" => ["type" => "varchar(255)", "comment" => "XMPP address"], + "matrix" => ["type" => "varchar(255)", "comment" => "Matrix address"], "photo" => ["type" => "varchar(255)", "comment" => ""], "header" => ["type" => "varchar(255)", "comment" => "Header picture"], "addr" => ["type" => "varchar(255)", "comment" => ""],