Browse Source

Merge Capabilities and Infos and create Identities

pull/874/head
Timothée Jaussoin 6 years ago
parent
commit
4636dd557c
  1. 120
      app/Capability.php
  2. 4
      app/Conference.php
  3. 16
      app/Identity.php
  4. 196
      app/Info.php
  5. 9
      app/Post.php
  6. 2
      app/Presence.php
  7. 26
      app/Session.php
  8. 6
      app/User.php
  9. 13
      app/helpers/UtilsHelper.php
  10. 2
      app/widgets/Account/Account.php
  11. 2
      app/widgets/Caps/Caps.php
  12. 2
      app/widgets/Chat/Chat.php
  13. 2
      app/widgets/CommunitiesServer/CommunitiesServer.php
  14. 12
      app/widgets/CommunitiesServers/CommunitiesServers.php
  15. 4
      app/widgets/CommunityAffiliations/CommunityAffiliations.php
  16. 12
      app/widgets/CommunityHeader/CommunityHeader.php
  17. 4
      app/widgets/Post/Post.php
  18. 2
      app/widgets/PublishBrief/PublishBrief.php
  19. 18
      app/widgets/Rooms/Rooms.php
  20. 5
      app/widgets/Rooms/_rooms_add.tpl
  21. 2
      app/widgets/Rooms/rooms.js
  22. 4
      app/widgets/Search/Search.php
  23. 2
      app/widgets/Statistics/Statistics.php
  24. 2
      app/widgets/Upload/Upload.php
  25. 1
      database/migrations/20190324190611_create_reactions_table.php
  26. 73
      database/migrations/20191017214225_create_identities_table.php
  27. 51
      lib/moxl/src/Moxl/Xec/Action/Disco/Items.php
  28. 38
      lib/moxl/src/Moxl/Xec/Action/Disco/Request.php
  29. 28
      lib/moxl/src/Moxl/Xec/Payload/Caps.php

120
app/Capability.php

@ -1,120 +0,0 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Capability extends Model
{
protected $primaryKey = 'node';
protected $fillable = ['features'];
public $incrementing = false;
public function save(array $options = [])
{
try {
parent::save($options);
} catch (\Exception $e) {
/*
* When an capability is received by two accounts simultaenously
*/
}
}
public function set($query, $node = false)
{
if (!$node) {
$this->node = (string)$query->query->attributes()->node;
} else {
$this->node = $node;
}
if (isset($query->query)) {
foreach ($query->query->identity as $i) {
if ($i->attributes()) {
$this->category = (string)$i->attributes()->category;
$this->type = (string)$i->attributes()->type;
if ($i->attributes()->name) {
$this->name = (string)$i->attributes()->name;
} else {
$this->name = $this->node;
}
}
}
$fet = [];
foreach ($query->query->feature as $f) {
array_push($fet, (string)$f->attributes()->var);
}
$this->setFeaturesAttribute($fet);
}
}
public function getPubsubRoles()
{
$roles = ['owner' => __('affiliation.owner'), 'none' => __('affiliation.no-aff')];
foreach ($this->getFeaturesAttribute() as $feature) {
preg_match("/http:\/\/jabber.org\/protocol\/pubsub#(.*)-affiliation$/", $feature, $matches);
if (!empty($matches)) {
$roles[$matches[1]] = __('affiliation.' . $matches[1]);
}
}
return $roles;
}
public function isPubsub()
{
return (in_array('http://jabber.org/protocol/pubsub#persistent-items', $this->getFeaturesAttribute()));
}
public function isJingle()
{
return (in_array('urn:xmpp:jingle:1', $this->getFeaturesAttribute()));
}
public function isMAM()
{
return (in_array('urn:xmpp:mam:1', $this->getFeaturesAttribute()));
}
public function isMAM2()
{
return (in_array('urn:xmpp:mam:2', $this->getFeaturesAttribute()));
}
public function getDeviceIcon()
{
if (in_array($this->type, ['handheld', 'phone'])) {
return 'smartphone';
}
if ($this->type == 'bot') {
return 'memory';
}
if ($this->type == 'console') {
return 'video_label';
}
if ($this->type == 'web') {
if ($this->name == 'Movim') {
return 'cloud_queue';
}
return 'language';
}
return 'desktop_windows';
}
public function getFeaturesAttribute()
{
return unserialize($this->attributes['features']);
}
public function setFeaturesAttribute($features)
{
$this->attributes['features'] = serialize($features);
}
}

4
app/Conference.php

@ -52,8 +52,8 @@ class Conference extends Model
public function info()
{
return $this->hasOne('App\Info', 'server', 'conference')
->where('category', 'conference')
->where('type', 'text');
->whereCategory('conference')
->whereType('text');
}
public function contact()

16
app/Identity.php

@ -0,0 +1,16 @@
<?php
namespace App;
use Movim\Model;
class Identity extends Model
{
protected $primaryKey = ['info_id', 'category', 'type'];
public $incrementing = false;
public function info()
{
return $this->belongsTo('App\Info');
}
}

196
app/Info.php

@ -2,13 +2,49 @@
namespace App;
use Movim\Model;
use Illuminate\Database\Eloquent\Model;
class Info extends Model
{
protected $primaryKey = ['server', 'node'];
public $incrementing = false;
protected $fillable = ['server', 'node', 'avatarhash'];
protected $with = ['identities'];
private $freshIdentities;
public function identities()
{
return $this->hasMany('App\Identity');
}
public function save(array $options = [])
{
try {
parent::save($options);
if ($this->freshIdentities) {
$this->identities()->delete();
$this->identities()->saveMany($this->freshIdentities);
}
} catch (\Exception $e) {
/**
* Existing info are saved in the DB
*/
}
}
public function scopeWhereCategory($query, $category)
{
return $query->whereHas('identities', function($query) use ($category) {
$query->where('category', $category);
});
}
public function scopeWhereType($query, $type)
{
return $query->whereHas('identities', function($query) use ($type) {
$query->where('type', $type);
});
}
public function setAdminaddressesAttribute(array $arr)
{
@ -90,13 +126,13 @@ class Info extends Model
public function getRelatedAttribute()
{
if ($this->category == 'pubsub' && $this->type == 'leaf') {
if ($this->identities->contains('category', 'pubsub') && $this->identities->contains('type', 'leaf')) {
return \App\Info::where('related', 'xmpp:'.$this->server.'?;node='.$this->node)
->first();
}
if (isset($this->attributes['related'])
&& $this->category == 'conference' && $this->type == 'text') {
&& $this->identities->contains('category', 'conference') && $this->identities->contains('type', 'text')) {
$uri = parse_url($this->attributes['related']);
if (isset($uri['query']) && isset($uri['path'])) {
@ -128,36 +164,73 @@ class Info extends Model
: null;
}
public function getDeviceIcon()
{
if ($this->identities->contains('type', 'handheld')
|| $this->identities->contains('type', 'phone')) {
return 'smartphone';
}
if ($this->identities->contains('type', 'bot')) {
return 'memory';
}
if ($this->identities->contains('type', 'console')) {
return 'video_label';
}
if ($this->identities->contains('type', 'web')) {
if ($this->name == 'Movim') {
return 'cloud_queue';
}
return 'language';
}
return 'desktop_windows';
}
public function hasFeature(string $feature)
{
return (in_array($feature, unserialize($this->attributes['features'])));
}
public function isJingle()
{
return $this->hasFeature('urn:xmpp:jingle:1');
}
public function isMAM()
{
return $this->hasFeature('urn:xmpp:mam:1');
}
public function isMAM2()
{
return $this->hasFeature('urn:xmpp:mam:2');
}
public function set($query)
{
$from = (string)$query->attributes()->from;
if (strpos($from, '/') == false
&& isset($query->query)) {
$this->server = $from;
if (isset($query->query)) {
$this->server = strpos($from, '/') == false ? $from : null;
$this->node = (string)$query->query->attributes()->node;
$this->freshIdentities = collect();
foreach ($query->query->identity as $i) {
if ($i->attributes()) {
$this->category = (string)$i->attributes()->category;
$this->type = (string)$i->attributes()->type;
if ($i->attributes()->name) {
$this->name = (string)$i->attributes()->name;
} elseif (!empty($this->node)) {
$this->name = $this->node;
}
}
$identity = new Identity;
$identity->category = (string)$i->attributes()->category;
$identity->type = (string)$i->attributes()->type;
$this->freshIdentities->push($identity);
$this->name = ($i->attributes()->name)
? (string)$i->attributes()->name
: $this->node;
}
foreach ($query->query->feature as $feature) {
$key = (string)$feature->attributes()->var;
switch ($key) {
// If it's a MUC we clear the node
case 'http://jabber.org/protocol/muc':
$this->node = '';
break;
$features = [];
foreach ($query->query->feature as $feature) {
switch ((string)$feature->attributes()->var) {
case 'muc_public':
$this->mucpublic = true;
break;
@ -177,12 +250,14 @@ class Info extends Model
$this->mucsemianonymous = true;
break;
}
array_push($features, (string)$feature->attributes()->var);
}
$this->attributes['features'] = serialize($features);
if (isset($query->query->x)) {
foreach ($query->query->x->field as $field) {
$key = (string)$field->attributes()->var;
switch ($key) {
switch ((string)$field->attributes()->var) {
case 'pubsub#title':
$this->name = (string)$field->value;
break;
@ -210,45 +285,45 @@ class Info extends Model
case 'muc#roominfo_occupants':
$this->occupants = (int)$field->value;
break;
case 'abuse-addresses':
case 'abuseaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->abuseaddresses = $arr;
break;
case 'admin-addresses':
case 'adminaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->adminaddresses = $arr;
break;
case 'feedback-addresses':
case 'feedbackaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->feedbackaddresses = $arr;
break;
case 'sales-addresses':
case 'salesaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->salesaddresses = $arr;
break;
case 'security-addresses':
case 'securityaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->securityaddresses = $arr;
break;
case 'support-addresses':
case 'supportaddresses':
$arr = [];
foreach ($field->children() as $value) {
$arr[] = (string)$value;
foreach ($field>children() as $value) {
$arr[] = (string)$value;
}
$this->supportaddresses = $arr;
break;
@ -258,7 +333,7 @@ class Info extends Model
}
}
public function setItem($item)
public function setPubsubItem($item)
{
$this->server = (string)$item->attributes()->jid;
$this->node = (string)$item->attributes()->node;
@ -266,20 +341,37 @@ class Info extends Model
if ($item->attributes()->name) {
$this->name = (string)$item->attributes()->name;
}
$this->identities = collect();
$identity = new Identity;
$identity->category = 'pubsub';
$identity->type = 'leaf';
$this->identities->push($identity);
}
public function isPubsubService()
public function getPubsubRoles()
{
return ($this->category == 'pubsub' && $this->type == 'service');
$roles = ['owner' => __('affiliation.owner'), 'none' => __('affiliation.no-aff')];
foreach (unserialize($this->attributes['features']) as $feature) {
preg_match("/http:\/\/jabber.org\/protocol\/pubsub#(.*)-affiliation$/", $feature, $matches);
if (!empty($matches)) {
$roles[$matches[1]] = __('affiliation.' . $matches[1]);
}
}
return $roles;
}
public function isMicroblogCommentsNode()
public function isPubsubService()
{
return (substr($this->node, 0, 29) == 'urn:xmpp:microblog:0:comments');
return ($this->identities->contains('category', 'pubsub')
&& $this->identities->contains('type', 'service'));
}
public function isOld()
public function isMicroblogCommentsNode()
{
return (strtotime($this->updated_at) < time() - 3600);
return (substr($this->node, 0, 29) == 'urn:xmpp:microblog:0:comments');
}
}

9
app/Post.php

@ -4,9 +4,6 @@ namespace App;
use Respect\Validation\Validator;
use Movim\Picture;
use Movim\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;
@ -486,7 +483,7 @@ class Post extends Model
$enc = (array)$attachment->attributes();
$enc = $enc['@attributes'];
$att = new \App\Attachment;
$att = new Attachment;
if (empty($enc['href']) || empty($enc['rel'])) {
continue;
@ -526,7 +523,7 @@ class Post extends Model
$att->logo = (isset($enc['logo'])) ? $enc['logo'] : null;
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $enc['href'], $match)) {
$atty = new \App\Attachment;
$atty = new Attachment;
$atty->rel = $enc['rel'];
$atty->href = 'https://www.youtube.com/embed/' . $match[1];
$atty->category = 'youtube';
@ -548,7 +545,7 @@ class Post extends Model
}
if ($picture == false && $extra) {
$attachment = new \App\Attachment;
$attachment = new Attachment;
$attachment->rel = 'enclosure';
$attachment->href = $extra;
$attachment->type = 'content';

2
app/Presence.php

@ -31,7 +31,7 @@ class Presence extends Model
public function capability()
{
return $this->hasOne('App\Capability', 'node', 'node');
return $this->hasOne('App\Info', 'node', 'node');
}
public function contact()

26
app/Session.php

@ -93,27 +93,27 @@ class Session extends Model
public function getUploadService()
{
return Capability::where('node', 'like', '%' . $this->host)
->where('category', 'store')
->where('type', 'file')
->where('features', 'like', '%urn:xmpp:http:upload%')
->first();
return Info::where('server', 'like', '%' . $this->host)
->whereCategory('store')
->whereType('file')
->where('features', 'like', '%urn:xmpp:http:upload%')
->first();
}
public function getChatroomsServices()
{
return Capability::where('node', 'like', '%' . $this->host . '%')
->where('node', 'not like', '%@%')
->where('category', 'conference')
->get();
return Info::where('server', 'like', '%' . $this->host . '%')
->where('server', 'not like', '%@%')
->whereCategory('conference')
->get();
}
public function getCommentsService()
{
return Capability::where('node', 'comments.' . $this->host)
->where('category', 'pubsub')
->where('type', 'service')
->first();
return Info::where('server', 'comments.' . $this->host)
->whereCategory('pubsub')
->whereType('service')
->first();
}
public function loadMemory()

6
app/User.php

@ -35,7 +35,7 @@ class User extends Model
public function capability()
{
return $this->hasOne('App\Capability', 'node', 'id');
return $this->hasOne('App\Info', 'server', 'id');
}
public function messages()
@ -132,12 +132,12 @@ class User extends Model
public function hasMAM()
{
return ($this->capability && $this->capability->isMAM2());
return ($this->capability && $this->capability->hasFeature('urn:xmpp:mam:2'));
}
public function hasPubsub()
{
return ($this->capability && $this->capability->isPubsub());
return ($this->capability && $this->capability->hasFeature('http://jabber.org/protocol/pubsub#persistent-items'));
}
public function hasUpload()

13
app/helpers/UtilsHelper.php

@ -630,3 +630,16 @@ function __()
$string = array_shift($args);
return $l->translate($string, $args);
}
/*
* Quick debug and die
*/
function dd($string)
{
if (php_sapi_name() != 'cli') {
\Utils::debug(is_string($string) ? $string : serialize($string));
} else {
\var_dump(is_string($string) ? $string : serialize($string));
}
exit;
}

2
app/widgets/Account/Account.php

@ -155,7 +155,7 @@ class Account extends \Movim\Widget\Base
$view->assign(
'gateways',
\App\Info::where('server', 'like', '%' . $this->user->session->host)
->where('category', 'gateway')
->whereCategory('gateway')
->get()
);

2
app/widgets/Caps/Caps.php

@ -26,7 +26,7 @@ class Caps extends Base
public function display()
{
$clients = App\Capability::where('category', 'client')->orderBy('name')->get();
$clients = \App\Info::whereCategory('client')->orderBy('name')->get();
$oldname = '';
foreach ($clients as $c) {

2
app/widgets/Chat/Chat.php

@ -1016,7 +1016,7 @@ class Chat extends \Movim\Widget\Base
{
$view = $this->tpl();
$conferences = \App\Info::where('category', 'conference')
$conferences = \App\Info::whereCategory('conference')
->whereNotIn('server', $this->user->session->conferences()->pluck('conference')->toArray())
->where('mucpublic', true)
->where('mucpersistent', true);

2
app/widgets/CommunitiesServer/CommunitiesServer.php

@ -69,8 +69,6 @@ class CommunitiesServer extends \Movim\Widget\Base
return;
}
//$this->rpc('MovimTpl.fill', '#communities_server', '');
$r = new Items;
$r->setTo($origin)->request();
}

12
app/widgets/CommunitiesServers/CommunitiesServers.php

@ -2,6 +2,7 @@
use Movim\Widget\Base;
use Moxl\Xec\Action\Disco\Request;
use Moxl\Xec\Action\Disco\Items;
use Respect\Validation\Validator;
@ -23,8 +24,8 @@ class CommunitiesServers extends Base
public function onDiscoInfo($packet)
{
$info = \App\Info::where('category', 'pubsub')
->where('type', 'service')
$info = \App\Info::whereCategory('pubsub')
->whereType('service')
->where('server', $packet->content[0])
->first();
@ -45,6 +46,9 @@ class CommunitiesServers extends Base
return;
}
$r = new Request;
$r->setTo($origin)->request();
$r = new Items;
$r->enableManual()
->setTo($origin)
@ -69,8 +73,8 @@ class CommunitiesServers extends Base
public function prepareCommunities()
{
$servers = \App\Info::where('category', 'pubsub')
->where('type', 'service')
$servers = \App\Info::whereCategory('pubsub')
->whereType('service')
->orderBy('occupants', 'desc')
->get();

4
app/widgets/CommunityAffiliations/CommunityAffiliations.php

@ -55,7 +55,7 @@ class CommunityAffiliations extends Base
// If the configuration is open, we fill it
$view = $this->tpl();
$caps = App\Capability::find($origin);
$caps = \App\Info::where('server', $origin)->first();
$view->assign('subscriptions', \App\Subscription::where('server', $origin)
->where('node', $node)
@ -197,7 +197,7 @@ class CommunityAffiliations extends Base
return;
}
if (Validator::in(array_keys(\App\Capability::find($origin)->getPubsubRoles()))->validate($form->role->value)
if (Validator::in(array_keys(\App\Info::where('node', $origin)->first()->getPubsubRoles()))->validate($form->role->value)
&& Validator::stringType()->length(3, 100)->validate($form->jid->value)) {
$sa = new SetAffiliations;
$sa->setTo($origin)

12
app/widgets/CommunityHeader/CommunityHeader.php

@ -90,8 +90,8 @@ class CommunityHeader extends Base
$view->assign('server', $origin);
$view->assign('node', $node);
$view->assign('info', \App\Info::where('server', $origin)
->where('node', $node)
->first());
->where('node', $node)
->first());
Dialog::fill($view->draw('_communityheader_subscribe'));
}
@ -129,8 +129,8 @@ class CommunityHeader extends Base
$view->assign('server', $origin);
$view->assign('node', $node);
$view->assign('info', \App\Info::where('server', $origin)
->where('node', $node)
->first());
->where('node', $node)
->first());
Dialog::fill($view->draw('_communityheader_unsubscribe'));
}
@ -191,8 +191,8 @@ class CommunityHeader extends Base
->where('node', $node)
->first());
$view->assign('num', $info ?
($info->items > 0)
? $info->items
($info->occupants > 0)
? $info->occupants
: \App\Post::where('server', $origin)
->where('node', $node)
->count()

4
app/widgets/Post/Post.php

@ -272,8 +272,8 @@ class Post extends Base
$view = $this->tpl();
$view->assign('post', $post);
$view->assign('info', \App\Info::where('server', $post->server)
->where('node', $post->node)
->first());
->where('node', $post->node)
->first());
return $view->draw('_post_prevnext_back');
}

2
app/widgets/PublishBrief/PublishBrief.php

@ -175,7 +175,7 @@ class PublishBrief extends Base
}
if ($comments) {
$p->enableComments($comments->node);
$p->enableComments($comments->server);
} else {
$p->enableComments();
}

18
app/widgets/Rooms/Rooms.php

@ -211,12 +211,12 @@ class Rooms extends Base
$view = $this->tpl();
$view->assign('info', \App\Info::where('server', $room)
->where('category', 'conference')
->whereCategory('conference')
->first());
$view->assign('mucservice', \App\Info::where('server', 'like', '%'. $this->user->session->host)
->where('server', 'not like', '%@%')
->where('category', 'conference')
->where('type', 'text')
->whereCategory('conference')
->whereType('text')
->first());
$view->assign('id', $room);
$view->assign(
@ -230,8 +230,8 @@ class Rooms extends Base
\App\Info::whereIn('server', function ($query) {
$query->select('jid')->from('presences');
})
->where('category', 'gateway')
->get()
->whereCategory('gateway')
->get()
);
$this->rpc('Rooms.setDefaultServices', $this->user->session->getChatroomsServices());
@ -476,16 +476,12 @@ class Rooms extends Base
$p = new Muc;
$p->setTo($room);
/*$c = new \Moxl\Xec\Action\Disco\Request;
$c->setTo(explodeJid($room)['server'])
->request();*/
if ($nickname == false) {
$nickname = $this->user->session->username;
}
$jid = explodeJid($room);
$capability = App\Capability::find($jid['server']);
$capability = \App\Info::where('node', $jid['server'])->first();
if ($capability && ($capability->isMAM() || $capability->isMAM2())) {
$p->enableMAM();
@ -529,7 +525,7 @@ class Rooms extends Base
: null;
$jid = explodeJid($room);
$capability = App\Capability::find($jid['server']);
$capability = \App\Info::where('node', $jid['server'])->first();
if (!$capability || !$capability->isMAM()) {
$this->user->messages()->where('jidfrom', $room)->delete();

5
app/widgets/Rooms/_rooms_add.tpl

@ -13,7 +13,10 @@
<option value="">{$c->__('rooms.default_room')}</option>
{loop="$gateways"}
<option value="{$value->server}">
{$value->name} ({$value->type})
{$value->name}
{if="$value->identities()->first()"}
({$value->identities()->first()->type})
{/if}
</option>
{/loop}
</select>

2
app/widgets/Rooms/rooms.js

@ -15,7 +15,7 @@ var Rooms = {
Rooms.default_services.forEach(function(item) {
var option = document.createElement('option');
option.value = input.value + '@' + item.node;
option.value = input.value + '@' + item.server;
suggestions.appendChild(option);
});
}

4
app/widgets/Search/Search.php

@ -102,8 +102,8 @@ class Search extends Base
$communities = Info::whereRaw('lower(node) like ?', '%'.strtolower($key).'%')
->whereRaw('lower(node) not like ?', 'urn:xmpp:microblog:0%')
->where('category', 'pubsub')
->where('type', 'leaf')
->whereCategory('pubsub')
->whereType('leaf')
->where('pubsubaccessmodel', 'open')
->take(5)
->get();

2
app/widgets/Statistics/Statistics.php

@ -11,7 +11,7 @@ class Statistics extends Base
public function getCapabilityName($node)
{
$capability = App\Capability::where('node', 'like', '%' . $node . '%')->first();
$capability = \App\Info::where('node', 'like', '%' . $node . '%')->first();
if ($capability && !filter_var($capability->name, FILTER_VALIDATE_URL)) {
$parts = explode(' ', $capability->name);

2
app/widgets/Upload/Upload.php

@ -60,7 +60,7 @@ class Upload extends Base
if ($upload) {
$r = new Request;
$r->setTo($upload->node)
$r->setTo($upload->server)
->setName($file->name)
->setSize($file->size)
->setType($file->type)

1
database/migrations/20190324190611_create_reactions_table.php

@ -9,7 +9,6 @@ class CreateReactionsTable extends Migration
{
$this->disableForeignKeyCheck();
$this->schema->table('messages', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropPrimary('messages_pkey');

73
database/migrations/20191017214225_create_identities_table.php

@ -0,0 +1,73 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Capsule\Manager as DB;
class CreateIdentitiesTable extends Migration
{
public function up()
{
$this->schema->table('infos', function (Blueprint $table) {
$table->dropPrimary('infos_pkey');
});
DB::table('infos')->truncate();
$this->schema->table('infos', function (Blueprint $table) {
$table->increments('id');
$table->dropColumn('category');
$table->dropColumn('type');
$table->unique(['server', 'node']);
$table->text('features')->nullable();
$table->string('server')->nullable()->change();
});
$this->schema->create('identities', function (Blueprint $table) {
$table->integer('info_id')->unsigned();
$table->string('category');
$table->string('type');
$table->timestamps();
$table->foreign('info_id')->references('id')
->on('infos')->onDelete('cascade');
$table->index('category');
$table->index('type');
$table->primary(['info_id', 'category', 'type']);
});
$this->schema->drop('capabilities');
}
public function down()
{
$this->schema->drop('identities');
DB::table('infos')->truncate();
$this->schema->table('infos', function (Blueprint $table) {
$table->dropColumn('id');
$table->dropColumn('features');
$table->dropUnique('infos_server_node_unique');
$table->string('category', 16);
$table->string('type', 16)->nullable();
$table->primary(['server', 'node']);
$table->string('server')->nullable(false)->change();
});
$this->schema->create('capabilities', function (Blueprint $table) {
$table->string('node', 256);
$table->string('category', 16);
$table->string('type', 16);
$table->string('name', 128);
$table->text('features');
$table->timestamps();
$table->primary('node');
$table->index('category');
$table->index('type');
});
}
}

51
lib/moxl/src/Moxl/Xec/Action/Disco/Items.php

@ -43,8 +43,6 @@ class Items extends Action
$this->method('manual');
}
$jid = null;
$parent = \App\Info::where('server', $this->_to)
->where('node', '')
->first();
@ -52,45 +50,26 @@ class Items extends Action
foreach ($stanza->query->item as $item) {
if ($this->_save) {
$info = \App\Info::firstOrNew([
'server' => $this->_to,
'node' => (string)$item->attributes()->node
]);
$info->setItem($item);
if ($parent && $parent->isPubsubService()) {
$info->category = 'pubsub';
if (!$info->isMicroblogCommentsNode()) {
$counter++;
if ($item->attributes()->node) {
$info = \App\Info::firstOrNew([
'server' => $this->_to,
'node' => (string)$item->attributes()->node
]);
if ($parent && $parent->isPubsubService()) {
$info->setPubsubItem($item);
if (!$info->isMicroblogCommentsNode()) {
$counter++;
$info->save();
}
}
}
if (!empty($info->category)
&& !$info->isMicroblogCommentsNode()) {
$info->save();
}
}
if ($jid != $info->server) {
if (isset($info->node)
&& $info->node != ''
&& $info->node != 'urn:xmpp:microblog:0') {
} elseif ($parent && $parent->identities->contains('category', 'server')) {
$r = new Request;
$r->setTo($info->server)
->setNode($info->node)
->request();
}
if (strpos($info->server, '/') === false) {
$r = new Request;
$r->setTo($info->server)
$r->setTo((string)$item->attributes()->jid)
->request();
}
}
$jid = $info->server;
}
if ($parent && $parent->isPubsubService()) {

38
lib/moxl/src/Moxl/Xec/Action/Disco/Request.php

@ -4,7 +4,6 @@ namespace Moxl\Xec\Action\Disco;
use Moxl\Xec\Action;
use Moxl\Stanza\Disco;
use Moxl\Xec\Action\Disco\Items;
class Request extends Action
{
@ -20,12 +19,7 @@ class Request extends Action
{
$this->store();
/*$info = \App\Info::where('server', $this->_to)
->where('node', (string)$this->_node)
->first();*/
if (!in_array($this->_node, $this->_excluded)
/*&& (!$info || $info->isOld())*/) {
if (!in_array($this->_node, $this->_excluded)) {
Disco::request($this->_to, $this->_node);
}
}
@ -45,35 +39,13 @@ class Request extends Action
if ($found) {
$found->set($stanza);
$found->save();
$this->deliver();
} elseif (!empty($info->category)
&& $info->category !== 'account'
&& $info->category !== 'client') {
$info->save();
$this->deliver();
}
// Caps
$capability = new \App\Capability;
if ($this->_node !== false) {
$capability->set($stanza, $this->_node);
$info = $found;
} else {
$capability->set($stanza, $this->_to);
$info->save();
}
if ($capability->features != null
&& $capability->category != null) {
$found = \App\Capability::find($capability->node);
if ($found) {
$found->delete();
}
$capability->save();
$this->method('caps');
if (!$info->identities->contains('category', 'account')
&& !$info->identities->contains('category', 'client')) {
$this->deliver();
}

28
lib/moxl/src/Moxl/Xec/Payload/Caps.php

@ -1,33 +1,11 @@
<?php
/*
* @file Caps.php
*
* @brief Handle incoming Entity Capabilities (XEP 0115 Entity Capabilities)
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Payload;
use Moxl\Xec\Action\Disco\Request;
use App\Info;
class Caps extends Payload
{
public function handle($stanza, $parent = false)
@ -35,7 +13,7 @@ class Caps extends Payload
$node = $stanza->attributes()->node.'#'.$stanza->attributes()->ver;
$to = (string)$parent->attributes()->from;
if (!\App\Capability::find($node)
if (!Info::whereNull('server')->where('node', $node)->first()
&& $parent->getName() != 'streamfeatures') {
$d = new Request;
$d->setTo($to)

Loading…
Cancel
Save