Browse Source

Only return chatroom that belongs to non-gateway services

Send an unsubscribe when removing a bookmark
Set the parent service when requesting the chatroom disco#info
feature/templater
Timothée Jaussoin 4 weeks ago
parent
commit
00cc34cc4c
  1. 18
      app/Info.php
  2. 2
      app/Message.php
  3. 10
      app/Widgets/Chat/_chat_header.tpl
  4. 11
      app/Widgets/Rooms/Rooms.php
  5. 9
      app/Widgets/RoomsExplore/RoomsExplore.php
  6. 5
      app/Widgets/RoomsUtils/RoomsUtils.php
  7. 22
      app/Widgets/RoomsUtils/_rooms_drawer.tpl
  8. 4
      src/Moxl/Stanza/Register.php
  9. 7
      src/Moxl/Xec/Action/Register/Remove.php

18
app/Info.php

@ -74,6 +74,24 @@ class Info extends Model
} }
} }
public function scopeRestrictMucServices($query)
{
$query->whereIn('parent', function ($query) {
$query->select('server')
->from('infos')
->whereIn('id', function ($query) {
$query->select('info_id')
->from('identities')
->where('category', 'conference');
})
->whereNotIn('id', function ($query) {
$query->select('info_id')
->from('identities')
->where('category', 'gateway');
});
});
}
public function setReactionsrestrictionsAttribute(array $arr) public function setReactionsrestrictionsAttribute(array $arr)
{ {
$this->attributes['reactionsrestrictions'] = serialize($arr); $this->attributes['reactionsrestrictions'] = serialize($arr);

2
app/Message.php

@ -657,7 +657,7 @@ class Message extends Model
if ($post = $xmppUri->getPost()) { if ($post = $xmppUri->getPost()) {
$this->postid = $post->id; $this->postid = $post->id;
} else {
} elseif($xmppUri->getServer() && $xmppUri->getNode() && $xmppUri->getNodeItemId()) {
$getItem = new GetItem; $getItem = new GetItem;
$getItem->setTo($xmppUri->getServer()) $getItem->setTo($xmppUri->getServer())
->setNode($xmppUri->getNode()) ->setNode($xmppUri->getNode())

10
app/Widgets/Chat/_chat_header.tpl

@ -111,16 +111,6 @@
{/if} {/if}
</span> </span>
{if="$conference && $conference->info && $conference->info->name"}
<span class="second" title="{$conference->info->name}">
{$conference->info->name}
</span>
{/if}
{if="$conference && $conference->info && $conference->isGroupChat() && $conference->subject && $conference->info->name"}
<span class="second">•</span>
{/if}
{if="$conference && $conference->isGroupChat() && $subject = $conference->subject"} {if="$conference && $conference->isGroupChat() && $subject = $conference->subject"}
<span class="second" title="{$subject}"> <span class="second" title="{$subject}">
{$subject} {$subject}

11
app/Widgets/Rooms/Rooms.php

@ -167,8 +167,11 @@ class Rooms extends Base
->get() as $room ->get() as $room
) { ) {
if (!$room->info) { if (!$room->info) {
$jid = explodeJid($room->conference);
$request = new Request; $request = new Request;
$request->setTo($room->conference) $request->setTo($room->conference)
->setParent($jid['server'])
->request(); ->request();
} }
@ -284,8 +287,11 @@ class Rooms extends Base
return; return;
} }
$jid = explodeJid($room);
$r = new Request; $r = new Request;
$r->setTo($room) $r->setTo($room)
->setParent($jid['server'])
->request(); ->request();
$p = new Muc; $p = new Muc;
@ -295,7 +301,6 @@ class Rooms extends Base
$nickname = $this->user->username; $nickname = $this->user->username;
} }
$jid = explodeJid($room);
$capability = \App\Info::where('server', $jid['server']) $capability = \App\Info::where('server', $jid['server'])
->where('node', '') ->where('node', '')
->first(); ->first();
@ -308,10 +313,6 @@ class Rooms extends Base
if ($capability->isMAM2()) { if ($capability->isMAM2()) {
$p->enableMAM2(); $p->enableMAM2();
} }
} else {
$r = new Request;
$r->setTo($jid['server'])
->request();
} }
$m = new GetMembers; $m = new GetMembers;

9
app/Widgets/RoomsExplore/RoomsExplore.php

@ -29,7 +29,9 @@ class RoomsExplore extends Base
} }
$view->assign('vcards', Contact::whereIn('id', $keys)->get()->keyBy('id')); $view->assign('vcards', Contact::whereIn('id', $keys)->get()->keyBy('id'));
$view->assign('bookmarks', $this->user->session
$view->assign(
'bookmarks',
$this->user->session
->conferences() ->conferences()
->whereIn('conference', $keys) ->whereIn('conference', $keys)
->get() ->get()
@ -88,6 +90,7 @@ class RoomsExplore extends Base
$view = $this->tpl(); $view = $this->tpl();
$rooms = \App\Info::whereCategory('conference') $rooms = \App\Info::whereCategory('conference')
->restrictUserHost() ->restrictUserHost()
->restrictMucServices()
->whereType('text') ->whereType('text')
->where('mucpublic', true) ->where('mucpublic', true)
->where('mucpersistent', true) ->where('mucpersistent', true)
@ -106,7 +109,9 @@ class RoomsExplore extends Base
$view->assign('vcards', Contact::whereIn('id', $rooms->pluck('server'))->get()->keyBy('id')); $view->assign('vcards', Contact::whereIn('id', $rooms->pluck('server'))->get()->keyBy('id'));
$view->assign('rooms', $rooms); $view->assign('rooms', $rooms);
$view->assign('bookmarks', $this->user->session
$view->assign(
'bookmarks',
$this->user->session
->conferences() ->conferences()
->whereIn('conference', $rooms->pluck('server')) ->whereIn('conference', $rooms->pluck('server'))
->get() ->get()

5
app/Widgets/RoomsUtils/RoomsUtils.php

@ -34,6 +34,7 @@ use Moxl\Xec\Action\Presence\Muc;
use Moxl\Xec\Action\Presence\Unavailable; use Moxl\Xec\Action\Presence\Unavailable;
use Illuminate\Database\Capsule\Manager as DB; use Illuminate\Database\Capsule\Manager as DB;
use Moxl\Xec\Action\Register\Remove;
class RoomsUtils extends Base class RoomsUtils extends Base
{ {
@ -557,6 +558,10 @@ class RoomsUtils extends Base
$d->setId($room) $d->setId($room)
->setVersion($conference->bookmarkversion) ->setVersion($conference->bookmarkversion)
->request(); ->request();
$unregister = new Remove;
$unregister->setTo($room)
->request();
} }
/** /**

22
app/Widgets/RoomsUtils/_rooms_drawer.tpl

@ -65,7 +65,7 @@
{if="$conference->subject"} {if="$conference->subject"}
<li> <li>
<span class="primary icon gray"> <span class="primary icon gray">
<i class="material-symbols">short_text</i>
<i class="material-symbols">info_i</i>
</span> </span>
<div> <div>
<p class="line"> <p class="line">
@ -77,7 +77,25 @@
</p> </p>
<p class="all"> <p class="all">
{autoescape="off"} {autoescape="off"}
{$conference->subject|addUrls}
{$conference->subject|addUrls|nl2br}
{/autoescape}
</p>
</div>
</li>
{/if}
{if="$conference->info->description"}
<li>
<span class="primary icon gray">
<i class="material-symbols">short_text</i>
</span>
<div>
<p class="line">
{$c->__('information.description')}
</p>
<p class="all">
{autoescape="off"}
{$conference->info->description|addUrls|nl2br}
{/autoescape} {/autoescape}
</p> </p>
</div> </div>

4
src/Moxl/Stanza/Register.php

@ -34,13 +34,13 @@ class Register
\Moxl\API::request(\Moxl\API::iqWrapper($query, $to, 'set')); \Moxl\API::request(\Moxl\API::iqWrapper($query, $to, 'set'));
} }
public static function remove()
public static function remove(?string $to)
{ {
$dom = new \DOMDocument('1.0', 'UTF-8'); $dom = new \DOMDocument('1.0', 'UTF-8');
$query = $dom->createElementNS('jabber:iq:register', 'query'); $query = $dom->createElementNS('jabber:iq:register', 'query');
$query->appendChild($dom->createElement('remove')); $query->appendChild($dom->createElement('remove'));
\Moxl\API::request(\Moxl\API::iqWrapper($query, false, 'set'));
\Moxl\API::request(\Moxl\API::iqWrapper($query, $to ?? false, 'set'));
} }
public static function changePassword($to, $username, $password) public static function changePassword($to, $username, $password)

7
src/Moxl/Xec/Action/Register/Remove.php

@ -7,10 +7,12 @@ use Moxl\Stanza\Register;
class Remove extends Action class Remove extends Action
{ {
protected ?string $_to = null;
public function request() public function request()
{ {
$this->store(); $this->store();
Register::remove();
Register::remove($this->_to);
} }
public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null) public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null)
@ -20,7 +22,10 @@ class Remove extends Action
public function error(string $errorId, ?string $message = null) public function error(string $errorId, ?string $message = null)
{ {
// We don't handle errors for now if we unregister from a specific thing
if ($this->_to == null) {
$this->pack($message); $this->pack($message);
$this->deliver(); $this->deliver();
} }
} }
}
Loading…
Cancel
Save