Browse Source

PEP based avatars now have preference over vcard-temp based ones

pull/1127/head
Timothée Jaussoin 3 years ago
parent
commit
c5271d6770
  1. 1
      CHANGELOG.md
  2. 8
      app/Contact.php
  3. 1
      app/PresenceBuffer.php
  4. 21
      database/migrations/20221224102134_add_avatar_type_to_contacts_table.php
  5. 6
      lib/moxl/src/Xec/Action/Avatar/Set.php
  6. 1
      lib/moxl/src/Xec/Payload/Avatar.php

1
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
---------------------------

8
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) {

1
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

21
database/migrations/20221224102134_add_avatar_type_to_contacts_table.php

@ -0,0 +1,21 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddAvatarTypeToContactsTable extends Migration
{
public function up()
{
$this->schema->table('contacts', function (Blueprint $table) {
$table->string('avatartype', 128)->nullable();
});
}
public function down()
{
$this->schema->table('contacts', function (Blueprint $table) {
$table->dropColumn('avatartype');
});
}
}

6
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');

1
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;

Loading…
Cancel
Save