From c5271d677035a5c71b00e9ccdaf858a07a21f79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Sat, 24 Dec 2022 11:59:08 +0100 Subject: [PATCH] PEP based avatars now have preference over vcard-temp based ones --- CHANGELOG.md | 1 + app/Contact.php | 8 +++++-- app/PresenceBuffer.php | 1 + ...2134_add_avatar_type_to_contacts_table.php | 21 +++++++++++++++++++ lib/moxl/src/Xec/Action/Avatar/Set.php | 6 +++++- lib/moxl/src/Xec/Payload/Avatar.php | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 database/migrations/20221224102134_add_avatar_type_to_contacts_table.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c77514046..19f1625f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ v0.21 (trunk) * Implement PSR-16: Common Interface for Caching Libraries for the Movim Session * Fix multi-line fallback bodies in outgoing message replies have incorrect offsets (#1113) * Cleanup Push Notification subscriptions after a month of inactivity + * PEP based avatars now have preference over vcard-temp based ones v0.20 --------------------------- diff --git a/app/Contact.php b/app/Contact.php index d5d491dc5..d29992468 100644 --- a/app/Contact.php +++ b/app/Contact.php @@ -94,13 +94,17 @@ class Contact extends Model $this->adrcountry = (string)$vcard->vCard->ADR->CTRY; } - if (filter_var((string)$vcard->vCard->PHOTO, FILTER_VALIDATE_URL)) { + if (filter_var((string)$vcard->vCard->PHOTO, FILTER_VALIDATE_URL) + && in_array($this->avatartype, ['vcard-temp', null])) { $this->photobin = base64_encode( requestURL((string)$vcard->vCard->PHOTO, 1) ); - } elseif ($vcard->vCard->PHOTO) { + $this->avatartype = 'vcard-temp'; + } elseif ($vcard->vCard->PHOTO + && in_array($this->avatartype, ['vcard-temp', null])) { $this->photobin = (string)$vcard->vCard->PHOTO->BINVAL; $this->avatarhash = sha1(base64_decode($this->photobin)); + $this->avatartype = 'vcard-temp'; } if ($vcard->vCard->DESC) { diff --git a/app/PresenceBuffer.php b/app/PresenceBuffer.php index fc2352334..04034781b 100644 --- a/app/PresenceBuffer.php +++ b/app/PresenceBuffer.php @@ -113,6 +113,7 @@ class PresenceBuffer if ($avatarHashes->count() > 0) { $contacts = Contact::whereIn('avatarhash', $avatarHashes->keys()) + ->orWhere('avatartype', 'urn:xmpp:avatar:metadata') ->get(); // Remove the existing Contacts diff --git a/database/migrations/20221224102134_add_avatar_type_to_contacts_table.php b/database/migrations/20221224102134_add_avatar_type_to_contacts_table.php new file mode 100644 index 000000000..a8d01fc80 --- /dev/null +++ b/database/migrations/20221224102134_add_avatar_type_to_contacts_table.php @@ -0,0 +1,21 @@ +schema->table('contacts', function (Blueprint $table) { + $table->string('avatartype', 128)->nullable(); + }); + } + + public function down() + { + $this->schema->table('contacts', function (Blueprint $table) { + $table->dropColumn('avatartype'); + }); + } +} diff --git a/lib/moxl/src/Xec/Action/Avatar/Set.php b/lib/moxl/src/Xec/Action/Avatar/Set.php index 4bdce0fb0..9f71d30c3 100644 --- a/lib/moxl/src/Xec/Action/Avatar/Set.php +++ b/lib/moxl/src/Xec/Action/Avatar/Set.php @@ -41,7 +41,11 @@ class Set extends Action public function handle($stanza, $parent = false) { if ($this->_to == false && $this->_node == false) { - $this->pack(\App\User::me()->contact); + $me = \App\User::me()->contact; + $me->avatartype = 'urn:xmpp:avatar:metadata'; + $me->save(); + + $this->pack($me); $this->deliver(); } else { $this->method('pubsub'); diff --git a/lib/moxl/src/Xec/Payload/Avatar.php b/lib/moxl/src/Xec/Payload/Avatar.php index a7f742a2c..48e780995 100644 --- a/lib/moxl/src/Xec/Payload/Avatar.php +++ b/lib/moxl/src/Xec/Payload/Avatar.php @@ -17,6 +17,7 @@ class Avatar extends Payload if ($info->id != $c->avatarhash) { $c->avatarhash = $info->id; + $c->avatartype = 'urn:xmpp:avatar:metadata'; $c->save(); $g = new Get;