Browse Source

Save the Pubsub affiliations in the database, allow Communities owners to edit the articles

Code refactoring and cleanup
pull/1185/merge
Timothée Jaussoin 2 years ago
parent
commit
4557214d30
  1. 1
      CHANGELOG.md
  2. 11
      app/Affiliation.php
  3. 3
      app/Info.php
  4. 15
      app/Post.php
  5. 1
      app/Presence.php
  6. 5
      app/User.php
  7. 86
      app/widgets/CommunityAffiliations/CommunityAffiliations.php
  8. 14
      app/widgets/CommunityAffiliations/_communityaffiliations.tpl
  9. 46
      app/widgets/CommunityAffiliations/_communityaffiliations_config_content.tpl
  10. 2
      app/widgets/CommunityPosts/CommunityPosts.php
  11. 8
      app/widgets/CommunityPosts/_communityposts.tpl
  12. 19
      app/widgets/Post/Post.php
  13. 13
      app/widgets/Post/_post.tpl
  14. 27
      app/widgets/Post/_post_card.tpl
  15. 6
      app/widgets/Post/_post_ticket.tpl
  16. 3
      composer.json
  17. 132
      composer.lock
  18. 26
      database/migrations/20231014161444_create_affiliations_table.php
  19. 2
      src/Movim/Model.php
  20. 29
      src/Moxl/Xec/Action/Disco/Request.php
  21. 19
      src/Moxl/Xec/Action/Pubsub/GetAffiliations.php

1
CHANGELOG.md

@ -8,6 +8,7 @@ v0.22.5 (trunk)
* Fix #1233 Movim doesn't correctly set the group SDP attribute
* Fix #1234 Disable the chat textarea when the user is a visitor
* Fix #1222 Adding a sentence in the INSTALL.md to ask to deploy Movim as a domain or subdomain
* Save the Pubsub affiliations in the database, allow Communities owners to edit the articles
v0.22.4
---------------------------

11
app/Affiliation.php

@ -0,0 +1,11 @@
<?php
namespace App;
use Movim\Model;
class Affiliation extends Model
{
public $primaryKey = ['server', 'node', 'jid'];
public $incrementing = false;
}

3
app/Info.php

@ -2,8 +2,7 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Movim\Route;
use Movim\Model;
class Info extends Model
{

15
app/Post.php

@ -4,18 +4,20 @@ namespace App;
use Respect\Validation\Validator;
use Illuminate\Database\Eloquent\Model;
use Awobaz\Compoships\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;
class Post extends Model
{
use \Awobaz\Compoships\Compoships;
protected $primaryKey = 'id';
protected $guarded = [];
public $with = ['attachments', 'likes', 'comments',
'contact', 'openlink', 'embed',
'links', 'files', 'pictures', 'picture',
'attachment'];
'attachment', 'userAffiliation'];
public $withCount = ['userViews'];
private $titleLimit = 200;
@ -48,8 +50,13 @@ class Post extends Model
public function info()
{
return $this->hasOne('App\Info', 'server', 'server')
->where('node', $this->node);
return $this->hasOne('App\Info', ['server', 'node'], ['server', 'node']);
}
public function userAffiliation()
{
return $this->hasOne('App\Affiliation', ['server', 'node'], ['server', 'node'])
->where('jid', \App\User::me()->id);
}
public function userViews()

1
app/Presence.php

@ -4,7 +4,6 @@ namespace App;
use Movim\Model;
use Movim\Image;
use Movim\Route;
use Movim\Session;
use Moxl\Xec\Action\Presence\Muc;

5
app/User.php

@ -142,6 +142,11 @@ class User extends Model
return $this->hasMany('App\Subscription', 'jid', 'id');
}
public function affiliations()
{
return $this->hasMany('App\Affiliation', 'jid', 'id');
}
public static function me($reload = false): User
{
$session = Session::start();

86
app/widgets/CommunityAffiliations/CommunityAffiliations.php

@ -1,5 +1,6 @@
<?php
use App\Affiliation;
use Movim\Widget\Base;
use Moxl\Xec\Action\Pubsub\Delete;
@ -14,7 +15,6 @@ class CommunityAffiliations extends Base
public function load()
{
$this->registerEvent('pubsub_getaffiliations_handle', 'onAffiliations');
$this->registerEvent('disco_request_affiliations', 'onAffiliations');
$this->registerEvent('pubsub_setaffiliations_handle', 'onAffiliationsSet');
$this->registerEvent('pubsub_delete_handle', 'onDelete');
$this->registerEvent('pubsub_delete_error', 'onDeleteError');
@ -25,39 +25,33 @@ class CommunityAffiliations extends Base
public function onAffiliations($packet)
{
list($affiliations, $server, $node) = array_values($packet->content);
list($server, $node) = array_values($packet->content);
$role = null;
if (array_key_exists('owner', $affiliations)) {
foreach ($affiliations['owner'] as $r) {
if ($r['jid'] == $this->user->id) {
$role = 'owner';
}
}
}
$affiliations = Affiliation::where('server', $server)
->where('node', $node)
->get();
$view = $this->tpl();
$view->assign('role', $role);
$view->assign('myaffiliation', $affiliations->where('jid', $this->user->id)->first());
$view->assign('info', \App\Info::where('server', $server)
->where('node', $node)
->first());
->where('node', $node)
->first());
$view->assign('server', $server);
$view->assign('node', $node);
$view->assign('affiliations', $affiliations);
$view->assign('rostersubscriptions', \App\Subscription::where('server', $server)
->where('node', $node)
->where('public', true)
->whereIn('jid', function ($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID);
})
->get());
->where('node', $node)
->where('public', true)
->whereIn('jid', function ($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID);
})
->get());
$view->assign('allsubscriptionscount', \App\Subscription::where('server', $server)
->where('node', $node)
->where('public', true)
->count());
->where('node', $node)
->where('public', true)
->count());
$this->rpc(
'MovimTpl.fill',
@ -71,8 +65,8 @@ class CommunityAffiliations extends Base
$caps = \App\Info::where('server', $server)->where('node', '')->first();
$view->assign('subscriptions', \App\Subscription::where('server', $server)
->where('node', $node)
->get());
->where('node', $node)
->get());
$view->assign('server', $server);
$view->assign('node', $node);
$view->assign('affiliations', $affiliations);
@ -98,8 +92,8 @@ class CommunityAffiliations extends Base
$view = $this->tpl();
$view->assign('subscriptions', \App\Subscription::where('server', $server)
->where('node', $node)
->get());
->where('node', $node)
->get());
$view->assign('server', $server);
$view->assign('node', $node);
@ -108,8 +102,10 @@ class CommunityAffiliations extends Base
private function deleted($packet)
{
if ($packet->content['server'] != $this->user->id
&& substr($packet->content['node'], 0, 29) != 'urn:xmpp:microblog:0:comments') {
if (
$packet->content['server'] != $this->user->id
&& substr($packet->content['node'], 0, 29) != 'urn:xmpp:microblog:0:comments'
) {
Toast::send($this->__('communityaffiliation.deleted'));
$this->rpc(
@ -146,9 +142,9 @@ class CommunityAffiliations extends Base
{
$view = $this->tpl();
$view->assign('subscriptions', \App\Subscription::where('server', $server)
->where('node', $node)
->where('public', true)
->get());
->where('node', $node)
->where('public', true)
->get());
Dialog::fill($view->draw('_communityaffiliations_public_subscriptions_dialog'), true);
}
@ -161,7 +157,7 @@ class CommunityAffiliations extends Base
$r = new GetAffiliations;
$r->setTo($server)->setNode($node)
->request();
->request();
}
public function ajaxGetSubscriptions(string $server, string $node, $notify = true)
@ -172,9 +168,9 @@ class CommunityAffiliations extends Base
$r = new GetSubscriptions;
$r->setTo($server)
->setNode($node)
->setNotify($notify)
->request();
->setNode($node)
->setNotify($notify)
->request();
}
public function ajaxDelete(string $server, string $node, $clean = false)
@ -201,7 +197,7 @@ class CommunityAffiliations extends Base
$d = new Delete;
$d->setTo($server)->setNode($node)
->request();
->request();
}
public function ajaxAffiliations(string $server, string $node)
@ -223,13 +219,15 @@ class CommunityAffiliations extends Base
$caps = \App\Info::where('server', $server)->where('node', '')->first();
if (Validator::in($caps ? array_keys($caps->getPubsubRoles()) : [])->validate($form->role->value)
&& Validator::stringType()->length(2, 100)->validate($form->jid->value)) {
if (
Validator::in($caps ? array_keys($caps->getPubsubRoles()) : [])->validate($form->role->value)
&& Validator::stringType()->length(2, 100)->validate($form->jid->value)
) {
$sa = new SetAffiliations;
$sa->setTo($server)
->setNode($node)
->setData([$form->jid->value => $form->role->value])
->request();
->setNode($node)
->setData([$form->jid->value => $form->role->value])
->request();
}
}

14
app/widgets/CommunityAffiliations/_communityaffiliations.tpl

@ -1,4 +1,4 @@
{if="$role == 'owner' && $info"}
{if="$myaffiliation && $myaffiliation->affiliation == 'owner' && $info"}
<ul class="list active">
<li onclick="CommunityConfig_ajaxGetAvatar('{$info->server|echapJS}', '{$info->node|echapJS}')">
<span class="primary icon gray">
@ -43,15 +43,15 @@
</ul>
{/if}
{if="array_key_exists('owner', $affiliations)"}
{if="$affiliations->where('affiliation', 'owner')->isNotEmpty()"}
<ul class="list card active">
<li class="subheader">
<div>
<p>{$c->__('communityaffiliation.owners')}</p>
</div>
</li>
{loop="$affiliations['owner']"}
{$contact = $c->getContact($value['jid'])}
{loop="$affiliations->where('affiliation', 'owner')"}
{$contact = $c->getContact($value->jid)}
<li title="{$contact->jid}"
onclick="MovimUtils.reload('{$c->route('contact', $contact->jid)}')">
<span class="primary icon bubble">
@ -66,15 +66,15 @@
</ul>
{/if}
{if="array_key_exists('publisher', $affiliations)"}
{if="$affiliations->where('affiliation', 'publisher')->isNotEmpty()"}
<ul class="list card active">
<li class="subheader">
<div>
<p>{$c->__('communityaffiliation.publishers')}</p>
</div>
</li>
{loop="$affiliations['publisher']"}
{$contact = $c->getContact($value['jid'])}
{loop="$affiliations->where('affiliation', 'publisher')"}
{$contact = $c->getContact($value->jid)}
<li title="{$contact->jid}"
onclick="MovimUtils.reload('{$c->route('contact', $contact->jid)}')">
<span class="primary icon bubble">

46
app/widgets/CommunityAffiliations/_communityaffiliations_config_content.tpl

@ -1,10 +1,8 @@
<h3>{$c->__('communityaffiliation.roles')}</h3>
<br />
<ul class="list thin">
{loop="$affiliations"}
{$role = $key}
{loop="$affiliations[$role]"}
{$contact = $c->getContact($value['jid'])}
{loop="$affiliations"}
{$contact = $c->getContact($value->jid)}
<li title="{$contact->jid}">
<span class="primary icon bubble">
<img src="{$contact->getPicture('m')}">
@ -12,23 +10,19 @@
<form name="{$contact->jid}">
<input type="hidden" name="jid" value="{$contact->jid}"/>
<div>
{if="$role == 'owner' && $contact->jid == $me"}
{if="$value->affiliation == 'owner' && $contact->jid == $me"}
<input type="text" disabled value="{$c->__('affiliation.owner')}"/>
{else}
<div class="select">
<select name="role" id="role" onchange="CommunityAffiliations.update('{$contact->jid}')">
{$affiliation = $value->affiliation}
{loop="$roles"}
{if="$key == $role"}
<option
value="{$key}"
selected="selected">
{$value}
</option>
{else}
<option value="{$key}">
{$value}
</option>
{/if}
<option
value="{$key}"
{if="$key == $affiliation"}selected="selected"{/if}
>
{$value}
</option>
{/loop}
</select>
</div>
@ -38,7 +32,6 @@
</form>
</li>
{/loop}
{/loop}
<br />
<hr />
@ -64,17 +57,14 @@
<div class="select">
<select name="role" id="role" onchange="">
{loop="$roles"}
{if="$key == 'none'"}
<option
value="{$key}"
selected="selected">
{$value}
</option>
{else}
<option value="{$key}">
{$value}
</option>
{/if}
<option
value="{$key}"
{if="$key == 'none'"}
selected="selected"
{/if}
>
{$value}
</option>
{/loop}
</select>
</div>

2
app/widgets/CommunityPosts/CommunityPosts.php

@ -206,8 +206,6 @@ class CommunityPosts extends Base
->first());
$view->assign('paging', $this->_paging);
$view->assign('gallery', $info && $info->isGallery());
$view->assign('publicposts', ($ids == false)
? \App\Post::where('server', $origin)
->where('node', $node)

8
app/widgets/CommunityPosts/_communityposts.tpl

@ -1,8 +1,8 @@
{if="!empty($ids)"}
<ul class="list card shadow {if="$gallery"}middle flex third gallery large active{/if}">
<ul class="list card shadow {if="$info && $info->isGallery()"}middle flex third gallery large active{/if}">
{loop="$ids"}
{if="isset($posts[$value])"}
{if="$gallery"}
{if="$info && $info->isGallery()"}
{autoescape="off"}
{$c->prepareTicket($posts[$value])}
{/autoescape}
@ -17,9 +17,9 @@
{/loop}
</ul>
{elseif="$publicposts->isNotEmpty()"}
<ul class="list card shadow {if="$gallery"}flex third gallery large active{/if}">
<ul class="list card shadow {if="$info && $info->isGallery()"}flex third gallery large active{/if}">
{loop="$publicposts"}
{if="$gallery"}
{if="$info && $info->isGallery()"}
{autoescape="off"}
{$c->prepareTicket($value)}
{/autoescape}

19
app/widgets/Post/Post.php

@ -210,21 +210,21 @@ class Post extends Base
return $view->draw('_post_not_found');
}
public function preparePost(\App\Post $p, $public = false, $card = false, $requestComments = true)
public function preparePost(\App\Post $post, $public = false, $card = false, $requestComments = true)
{
if (isset($p)) {
if (isset($post)) {
$view = $this->tpl();
$commentsDisabled = false;
if ($p->hasCommentsNode()
if ($post->hasCommentsNode()
&& !$public && !$card) {
if ($requestComments) {
$this->requestComments($p); // Broken in case of repost
$this->requestComments($post); // Broken in case of repost
}
} elseif (!$card) {
$viewd = $this->tpl();
$viewd->assign('post', $p);
$viewd->assign('post', $post);
if ($requestComments) {
$commentsDisabled = $viewd->draw('_post_comments_error');
@ -233,14 +233,11 @@ class Post extends Base
$view->assign('commentsdisabled', $commentsDisabled);
$view->assign('public', $public);
$view->assign('reply', $p->isReply() ? $p->getReply() : false);
$view->assign('repost', $p->isRecycled() ? \App\Contact::find($p->server) : false);
$view->assign('reply', $post->isReply() ? $post->getReply() : false);
$view->assign('repost', $post->isRecycled() ? \App\Contact::find($post->server) : false);
$view->assign('nsfw', $this->user->nsfw);
$view->assign('post', $p);
$view->assign('info', \App\Info::where('server', $p->server)
->where('node', $p->node)
->first());
$view->assign('post', $post);
return ($card)
? $view->draw('_post_card')

13
app/widgets/Post/_post.tpl

@ -7,7 +7,7 @@
<i class="material-icons">arrow_back</i>
</span>
{if="$post->isMine()"}
{if="$post->isMine() || ($post->userAffiliation && $post->userAffiliation->affiliation == 'owner')"}
{if="$post->isEditable()"}
<span class="control icon active gray"
onclick="MovimUtils.reload('{$c->route('publish', [$post->server, $post->node, $post->nodeid])}')"
@ -57,11 +57,11 @@
</span>
{/if}
{else}
{if="$info != null"}
{if="$post->info != null"}
<span class="primary icon bubble active"
onclick="MovimUtils.reload('{$c->route('community', [$post->server, $post->node])}')"
>
<img src="{$info->getPicture('l')}"/>
<img src="{$post->info->getPicture('l')}"/>
</span>
{else}
<span class="primary icon bubble color {$post->node|stringToColor} active"
@ -101,9 +101,12 @@
<p>
{if="$contact"}
{if="!$public"}
<a href="#" onclick="if (typeof Post_ajaxGetContact == 'function') { Post_ajaxGetContact('{$contact->jid}'); } else { Group_ajaxGetContact('{$contact->jid}'); } ">
<span class="icon bubble tiny">
<img src="{$contact->getPicture()}">
</span>
<a href="#" onclick="if (typeof Post_ajaxGetContact == 'function') { Post_ajaxGetContact('{$contact->jid}'); } else { Group_ajaxGetContact('{$contact->jid}'); } ">
{/if}
{$contact->truename}
{$contact->truename}
{if="!$public"}</a>{/if} ·
{elseif="$post->aname"}
{$post->aname} ·

27
app/widgets/Post/_post_card.tpl

@ -34,16 +34,23 @@
{/autoescape}
</p>
<p>
{if="$post->isMicroblog()"}
<a {if="$public"}
href="{$c->route('blog', $post->aid)}"
{else}
href="{$c->route('contact', $post->aid)}"
{if="!$post->isMicroblog()"}
{if="$post->aid"}
{if="$post->contact"}
<span class="icon bubble tiny">
<img src="{$post->contact->getPicture()}">
</span>
{/if}
>
{$post->truename}
</a> ·
{else}
<a {if="$public"}
href="{$c->route('blog', $post->aid)}"
{else}
href="{$c->route('contact', $post->aid)}"
{/if}
>
{$post->truename}
</a> ·
{/if}
{if="$public"}
{$post->server}
{else}
@ -214,7 +221,7 @@
{/if}
{/if}
{if="$post->isMine()"}
{if="$post->isMine() || ($post->userAffiliation && $post->userAffiliation->affiliation == 'owner')"}
{if="$post->isEditable()"}
<a class="button narrow icon flat oppose gray on_desktop"
href="{$c->route('publish', [$post->server, $post->node, $post->nodeid])}"

6
app/widgets/Post/_post_ticket.tpl

@ -39,10 +39,10 @@
<span class="icon bubble tiny">
<img src="{$post->contact->getPicture()}">
</span>
<a href="{$c->route('contact', $post->contact->jid)}">
{$post->contact->truename}
</a>
{/if}
<a href="{$c->route('contact', $post->aid)}">
{$post->truename}
</a>
{if="!$post->isMicroblog()"}
<a class="node"

3
composer.json

@ -43,7 +43,8 @@
"ratchet/pawl": "^0.4",
"minishlink/web-push": "^8.0",
"vlucas/phpdotenv": "^5.5",
"react/promise-timer": "^1.10"
"react/promise-timer": "^1.10",
"awobaz/compoships": "^2.2"
},
"config": {
"platform": {

132
composer.lock

@ -4,8 +4,70 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c0e32b04c7fbda08097574d62dee05ee",
"content-hash": "86907b795d2e4882d865205d45e9493b",
"packages": [
{
"name": "awobaz/compoships",
"version": "2.2.3",
"source": {
"type": "git",
"url": "https://github.com/topclaudy/compoships.git",
"reference": "404901e2ebd6794f70d2710a56edd4b0c500ce1f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/topclaudy/compoships/zipball/404901e2ebd6794f70d2710a56edd4b0c500ce1f",
"reference": "404901e2ebd6794f70d2710a56edd4b0c500ce1f",
"shasum": ""
},
"require": {
"fakerphp/faker": "^1.18",
"illuminate/database": ">=5.6 <11.0"
},
"require-dev": {
"ext-sqlite3": "*",
"phpunit/phpunit": "^6.0|^8.0|^9.0"
},
"suggest": {
"awobaz/blade-active": "Blade directives for the Laravel 'Active' package",
"awobaz/eloquent-auto-append": "Automatically append accessors to model serialization",
"awobaz/eloquent-mutators": "Reusable mutators (getters/setters) for Laravel 5's Eloquent",
"awobaz/syntactic": "Syntactic sugar for named and indexed parameters call."
},
"type": "library",
"autoload": {
"psr-4": {
"Awobaz\\Compoships\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Claudin J. Daniel",
"email": "cdaniel@awobaz.com"
}
],
"description": "Laravel relationships with support for composite/multiple keys",
"keywords": [
"laravel",
"laravel composite keys",
"laravel relationships"
],
"support": {
"issues": "https://github.com/topclaudy/compoships/issues",
"source": "https://github.com/topclaudy/compoships/tree/2.2.3"
},
"funding": [
{
"url": "https://paypal.me/awobaz",
"type": "custom"
}
],
"time": "2023-02-22T16:52:55+00:00"
},
{
"name": "brick/math",
"version": "0.11.0",
@ -1349,6 +1411,74 @@
},
"time": "2023-05-12T11:38:03+00:00"
},
{
"name": "fakerphp/faker",
"version": "v1.23.0",
"source": {
"type": "git",
"url": "https://github.com/FakerPHP/Faker.git",
"reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01",
"reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"psr/container": "^1.0 || ^2.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"conflict": {
"fzaninotto/faker": "*"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"doctrine/persistence": "^1.3 || ^2.0",
"ext-intl": "*",
"phpunit/phpunit": "^9.5.26",
"symfony/phpunit-bridge": "^5.4.16"
},
"suggest": {
"doctrine/orm": "Required to use Faker\\ORM\\Doctrine",
"ext-curl": "Required by Faker\\Provider\\Image to download images.",
"ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.",
"ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.",
"ext-mbstring": "Required for multibyte Unicode string functionality."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "v1.21-dev"
}
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"support": {
"issues": "https://github.com/FakerPHP/Faker/issues",
"source": "https://github.com/FakerPHP/Faker/tree/v1.23.0"
},
"time": "2023-06-12T08:44:38+00:00"
},
{
"name": "fig/http-message-util",
"version": "1.1.5",

26
database/migrations/20231014161444_create_affiliations_table.php

@ -0,0 +1,26 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAffiliationsTable extends Migration
{
public function up()
{
$this->schema->create('affiliations', function (Blueprint $table) {
$table->string('server', 256);
$table->string('node', 256);
$table->enum('affiliation', ['member', 'none', 'outcast', 'owner', 'publisher', 'publish-only']);
$table->string('jid', 256)->index();
$table->unique(['server', 'node', 'jid']);
$table->index(['server', 'node']);
$table->timestamps();
});
}
public function down()
{
$this->schema->drop('affiliations');
}
}

2
src/Movim/Model.php

@ -12,6 +12,8 @@ use Illuminate\Database\Eloquent\Model as EloquentModel;
class Model extends EloquentModel
{
use \Awobaz\Compoships\Compoships;
/**
* The "type" of the primary key ID.
*

29
src/Moxl/Xec/Action/Disco/Request.php

@ -56,34 +56,5 @@ class Request extends Action
&& !$info->identities->contains('category', 'client')) {
$this->deliver();
}
// Affiliations
$affiliations = [];
$owners = $stanza->query->xpath("//field[@var='pubsub#owner']/value/text()");
if (!empty($owners)) {
$affiliations['owner'] = [];
foreach ($owners as $owner) {
array_push($affiliations['owner'], ['jid' => (string)$owner]);
}
}
$publishers = $stanza->query->xpath("//field[@var='pubsub#publisher']/value/text()");
if (!empty($publishers)) {
$affiliations['publisher'] = [];
foreach ($publishers as $publisher) {
array_push($affiliations['publisher'], ['jid' => (string)$publisher]);
}
}
if (!empty($affiliations)) {
$this->pack([
'affiliations' => $affiliations,
'server' => $this->_to,
'node' => $this->_node
]);
$this->method('affiliations');
$this->deliver();
}
}
}

19
src/Moxl/Xec/Action/Pubsub/GetAffiliations.php

@ -2,6 +2,7 @@
namespace Moxl\Xec\Action\Pubsub;
use App\Affiliation;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action;
@ -18,18 +19,18 @@ class GetAffiliations extends Action
public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null)
{
$tab = [];
foreach ($stanza->pubsub->affiliations->children() as $i) {
$affiliation = (string)$i['affiliation'];
if (!array_key_exists($affiliation, $tab)) {
$tab[$affiliation] = [];
}
Affiliation::where('server', $this->_to)->where('node', $this->_node)->delete();
array_push($tab[$affiliation], ['jid' => (string)$i['jid'], 'subid' => (string)$i['subid']]);
foreach ($stanza->pubsub->affiliations->children() as $i) {
$affiliation = new Affiliation;
$affiliation->server = $this->_to;
$affiliation->node = $this->_node;
$affiliation->jid = (string)$i['jid'];
$affiliation->affiliation = (string)$i['affiliation'];
$affiliation->save();
}
$this->pack(['affiliations' => $tab, 'server' => $this->_to, 'node' => $this->_node]);
$this->pack(['server' => $this->_to, 'node' => $this->_node]);
$this->deliver();
}
}
Loading…
Cancel
Save