Browse Source

Add bannerhash column to Contacts table to set the current banner id (and prevent refreshing)

pull/1112/head
Timothée Jaussoin 3 years ago
parent
commit
e89327f9bd
  1. 21
      database/migrations/20221114210820_add_banner_hash_to_contacts_table.php
  2. 17
      lib/moxl/src/Xec/Payload/BannerMetadata.php

21
database/migrations/20221114210820_add_banner_hash_to_contacts_table.php

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

17
lib/moxl/src/Xec/Payload/BannerMetadata.php

@ -10,13 +10,22 @@ class BannerMetadata extends Payload
{
$jid = baseJid((string)$parent->attributes()->from);
$c = \App\Contact::firstOrNew(['id' => $jid]);
if (isset($stanza->items->item->metadata->info)
&& isset($stanza->items->item->metadata->info->attributes()->url)) {
$p = new Image;
$info = $stanza->items->item->metadata->info->attributes();
if ($info->id != $c->bannerhash) {
$c->bannerhash = $info->id;
$c->save();
$p = new Image;
if ($p->fromURL((string)$stanza->items->item->metadata->info->attributes()->url)) {
$p->setKey($jid . '_banner');
$p->save();
if ($p->fromURL((string)$info->url)) {
$p->setKey($jid . '_banner');
$p->save();
}
}
}
}

Loading…
Cancel
Save