Browse Source

Merge pull request #874 from movim/feature/multi-identities

Feature/multi identities
pull/898/head
Jaussoin Timothée 6 years ago
committed by GitHub
parent
commit
3d8548845a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 120
      app/Capability.php
  2. 4
      app/Conference.php
  3. 16
      app/Identity.php
  4. 175
      app/Info.php
  5. 9
      app/Post.php
  6. 2
      app/Presence.php
  7. 26
      app/Session.php
  8. 6
      app/User.php
  9. 1
      app/controllers/AccountController.php
  10. 1
      app/helpers/StringHelper.php
  11. 1
      app/helpers/UtilsHelper.php
  12. 2
      app/widgets/Account/Account.php
  13. 2
      app/widgets/Caps/Caps.php
  14. 3
      app/widgets/Chat/Chat.php
  15. 2
      app/widgets/Chats/_chats_item.tpl
  16. 1
      app/widgets/Communities/Communities.php
  17. 2
      app/widgets/CommunitiesServer/CommunitiesServer.php
  18. 15
      app/widgets/CommunitiesServers/CommunitiesServers.php
  19. 74
      app/widgets/CommunitiesServers/_communitiesservers.tpl
  20. 3
      app/widgets/CommunitiesServers/locales.ini
  21. 8
      app/widgets/CommunityAffiliations/CommunityAffiliations.php
  22. 12
      app/widgets/CommunityHeader/CommunityHeader.php
  23. 10
      app/widgets/ContactActions/_contactactions_drawer.tpl
  24. 4
      app/widgets/Post/Post.php
  25. 2
      app/widgets/PublishBrief/PublishBrief.php
  26. 18
      app/widgets/Rooms/Rooms.php
  27. 5
      app/widgets/Rooms/_rooms_add.tpl
  28. 2
      app/widgets/Rooms/rooms.js
  29. 4
      app/widgets/Search/Search.php
  30. 2
      app/widgets/Statistics/Statistics.php
  31. 2
      app/widgets/Upload/Upload.php
  32. 1
      database/migrations/20190324190611_create_reactions_table.php
  33. 73
      database/migrations/20191017214225_create_identities_table.php
  34. 4
      lib/moxl/src/Moxl/Utils.php
  35. 51
      lib/moxl/src/Moxl/Xec/Action/Disco/Items.php
  36. 38
      lib/moxl/src/Moxl/Xec/Action/Disco/Request.php
  37. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/Create.php
  38. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/Delete.php
  39. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetAffiliations.php
  40. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetConfig.php
  41. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItem.php
  42. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItems.php
  43. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItemsId.php
  44. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/GetSubscriptions.php
  45. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/PostDelete.php
  46. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/PostPublish.php
  47. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/SetAffiliations.php
  48. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/SetConfig.php
  49. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/SetSubscriptions.php
  50. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/Subscribe.php
  51. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/TestCreate.php
  52. 3
      lib/moxl/src/Moxl/Xec/Action/Pubsub/TestPostPublish.php
  53. 1
      lib/moxl/src/Moxl/Xec/Action/Pubsub/Unsubscribe.php
  54. 1
      lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Add.php
  55. 1
      lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Get.php
  56. 1
      lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Remove.php
  57. 28
      lib/moxl/src/Moxl/Xec/Payload/Caps.php
  58. 1
      src/Movim/ChatOwnState.php
  59. 1
      src/Movim/Controller/Base.php
  60. 3
      src/Movim/Daemon/Api.php
  61. 2
      src/Movim/Daemon/Session.php
  62. 1
      src/Movim/Widget/Base.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');
}
}

175
app/Info.php

@ -2,13 +2,64 @@
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 {
unset($this->identities);
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 scopeRestrictUserHost($query)
{
$configuration = Configuration::get();
if ($configuration->restrictsuggestions) {
$query->whereIn('server', function ($query) {
$host = \App\User::me()->session->host;
$query->select('server')
->from('infos')
->where('server', 'like', '%.' . $host);
});
}
}
public function setAdminaddressesAttribute(array $arr)
{
@ -90,13 +141,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 +179,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 +265,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;
@ -258,7 +348,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 +356,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()

1
app/controllers/AccountController.php

@ -1,4 +1,5 @@
<?php
use Movim\Controller\Base;
class AccountController extends Base

1
app/helpers/StringHelper.php

@ -1,7 +1,6 @@
<?php
use Movim\Route;
use App\Configuration;
function addUrls($string, bool $preview = false)
{

1
app/helpers/UtilsHelper.php

@ -3,7 +3,6 @@
use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Handler\StreamHandler;
use GuzzleHttp\Client;
use Movim\Picture;
class Utils

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

3
app/widgets/Chat/Chat.php

@ -1016,8 +1016,9 @@ 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())
->restrictUserHost()
->where('mucpublic', true)
->where('mucpersistent', true);

2
app/widgets/Chats/_chats_item.tpl

@ -5,7 +5,7 @@
{if="$roster && $roster->presence"}
{if="$roster->presence->value > 4"}faded{/if}
{if="$roster->presence->last > 60"} inactive{/if}
{if="$roster->presence->capability && in_array($roster->presence->capability->type, array('handheld', 'phone', 'web'))"}
{if="$roster->presence->capability && $roster->presence->capability->identities()->first() && in_array($roster->presence->capability->identities()->first()->type, ['handheld', 'phone', 'web'])"}
action
{/if}
{/if}

1
app/widgets/Communities/Communities.php

@ -23,6 +23,7 @@ class Communities extends Base
$posts = \App\Post::withoutComments()
->restrictToCommunities()
->restrictNSFW()
->restrictUserHost()
->recents()
->orderBy('posts.published', 'desc')
->where('open', 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();
}

15
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,13 +73,16 @@ class CommunitiesServers extends Base
public function prepareCommunities()
{
$servers = \App\Info::where('category', 'pubsub')
->where('type', 'service')
$servers = \App\Info::whereCategory('pubsub')
->whereType('service')
->restrictUserHost()
->orderBy('occupants', 'desc')
->get();
$configuration = \App\Configuration::get();
$view = $this->tpl();
$view->assign('servers', $servers);
$view->assign('restrict', $configuration->restrictsuggestions);
return $view->draw('_communitiesservers');
}

74
app/widgets/CommunitiesServers/_communitiesservers.tpl

@ -1,30 +1,44 @@
<ul class="list flex third middle active">
{loop="$servers"}
{if="!filter_var($value->server, FILTER_VALIDATE_EMAIL)"}
<li class="block
{if="$value->occupants == 0"}faded{/if}"
onclick="MovimUtils.redirect('{$c->route('community', $value->server)}')">
<span class="primary icon bubble color {$value->server|stringToColor}">
{$value->server|firstLetterCapitalize}
</span>
<p class="line" title="{$value->server} - {$value->name}">
{$value->server}
<span class="second">{$value->name}</span>
</p>
<p>{$c->__('communities.counter', $value->occupants)}</p>
</li>
{/if}
{/loop}
<li class="block large">
<span class="primary icon">
<i class="material-icons">search</i>
</span>
<form>
<div>
<input placeholder="pubsub.server.com" onkeypress="
if (event.keyCode == 13) { CommunitiesServers_ajaxDisco(this.value); return false; }" >
<label>{$c->__('communities.search_server')}</label>
</div>
</form>
</li>
</ul>
{if="$servers->isEmpty()"}
<ul class="thick">
<div class="placeholder">
<i class="material-icons">storage</i>
<h1>{$c->__('communitiesservers.empty_title')}</h1>
<h4>{$c->__('communitiesservers.empty_text')}</h4>
</li>
</ul>
{else}
<ul class="list flex third middle active">
{loop="$servers"}
{if="!filter_var($value->server, FILTER_VALIDATE_EMAIL)"}
<li class="block
{if="$value->occupants == 0"}faded{/if}"
onclick="MovimUtils.redirect('{$c->route('community', $value->server)}')">
<span class="primary icon bubble color {$value->server|stringToColor}">
{$value->server|firstLetterCapitalize}
</span>
<p class="line" title="{$value->server} - {$value->name}">
{$value->server}
<span class="second">{$value->name}</span>
</p>
<p>{$c->__('communities.counter', $value->occupants)}</p>
</li>
{/if}
{/loop}
</ul>
{/if}
{if="!$restrict"}
<ul class="list middle">
<li class="block large">
<span class="primary icon">
<i class="material-icons">search</i>
</span>
<form>
<div>
<input placeholder="pubsub.server.com" onkeypress="
if (event.keyCode == 13) { CommunitiesServers_ajaxDisco(this.value); return false; }" >
<label>{$c->__('communities.search_server')}</label>
</div>
</form>
</li>
</ul>
{/if}

3
app/widgets/CommunitiesServers/locales.ini

@ -0,0 +1,3 @@
[communitiesservers]
empty_title = No Communities Servers yet…
empty_text = "It seems that we can't find any communities for the moment"

8
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)
@ -118,8 +118,8 @@ class CommunityAffiliations extends Base
public function onDeleteError($packet)
{
$m = new Rooms;
$m->setBookmark();
$c = new CommunityHeader;
$c->ajaxUnsubscribe($packet->content['server'], $packet->content['node']);
$this->deleted($packet);
}
@ -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()

10
app/widgets/ContactActions/_contactactions_drawer.tpl

@ -59,11 +59,11 @@
<span class="info">{$value->resource}</span>
{$value->capability->name}
</p>
<p class="line">
{if="isset($clienttype[$value->capability->type])"}
{$clienttype[$value->capability->type]}
{/if}
</p>
{if="$value->capability->identities()->first() && isset($clienttype[$value->capability->identities()->first()->type])"}
<p class="line">
{$clienttype[$value->capability->identities()->first()->type]}
</p>
{/if}
</li>
{/if}
{/loop}

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

4
lib/moxl/src/Moxl/Utils.php

@ -2,10 +2,6 @@
namespace Moxl;
use Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Handler\StreamHandler;
class Utils
{
public static function getSupportedServices()

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();
}

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/Create.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\Pubsub;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/Delete.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\Pubsub;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetAffiliations.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetConfig.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItem.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItems.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetItemsId.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Disco;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Xec\Action\Pubsub\GetItem;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/GetSubscriptions.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/PostDelete.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/PostPublish.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Stanza\PubsubAtom;
use Moxl\Xec\Action\Pubsub\GetItem;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/SetAffiliations.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/SetConfig.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/SetSubscriptions.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/Subscribe.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Xec\Action\PubsubSubscription\Add as SubscriptionAdd;

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/TestCreate.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\Pubsub;

3
lib/moxl/src/Moxl/Xec/Action/Pubsub/TestPostPublish.php

@ -2,10 +2,7 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Stanza\PubsubAtom;
use Moxl\Xec\Action\Pubsub\PostDelete;
use Moxl\Xec\Action\Pubsub\Errors;
class TestPostPublish extends Errors

1
lib/moxl/src/Moxl/Xec/Action/Pubsub/Unsubscribe.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\Pubsub;
use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Xec\Action\PubsubSubscription\Remove as SubscriptionRemove;

1
lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Add.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\PubsubSubscription;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\PubsubSubscription;

1
lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Get.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\PubsubSubscription;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\Pubsub;

1
lib/moxl/src/Moxl/Xec/Action/PubsubSubscription/Remove.php

@ -2,7 +2,6 @@
namespace Moxl\Xec\Action\PubsubSubscription;
use Moxl\Xec\Action;
use Moxl\Xec\Action\Pubsub\Errors;
use Moxl\Stanza\PubsubSubscription;

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)

1
src/Movim/ChatOwnState.php

@ -4,7 +4,6 @@ namespace Movim;
use Moxl\Xec\Action\Message\Composing;
use Moxl\Xec\Action\Message\Paused;
use Moxl\Xec\Action\Message\Inactive;
/**
* This class handle all the outgoing chatstates

1
src/Movim/Controller/Base.php

@ -4,7 +4,6 @@ namespace Movim\Controller;
use Movim\Template\Builder;
use Movim\Route;
use Movim\User;
class Base
{

3
src/Movim/Daemon/Api.php

@ -7,9 +7,6 @@ use Movim\Bootstrap;
use Psr\Http\Message\ServerRequestInterface;
use React\Socket\Server as Reactor;
use React\Http\Middleware\LimitConcurrentRequestsMiddleware;
use React\Http\Middleware\RequestBodyBufferMiddleware;
use React\Http\Middleware\RequestBodyParserMiddleware;
use React\Http\Server;
use React\Http\Response;

2
src/Movim/Daemon/Session.php

@ -2,8 +2,6 @@
namespace Movim\Daemon;
use Ratchet\ConnectionInterface;
use React\EventLoop\Timer\Timer;
use Movim\Controller\Front;
use App\Session as DBSession;
class Session

1
src/Movim/Widget/Base.php

@ -4,7 +4,6 @@ namespace Movim\Widget;
use Rain\Tpl;
use Movim\Controller\Ajax;
use Movim\User;
use Movim\Template\Partial;
class Base

Loading…
Cancel
Save