Browse Source

Chatrooms are working again, yay

pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
de238018af
  1. 8
      app/Conference.php
  2. 3
      app/Presence.php
  3. 12
      app/widgets/Chat/Chat.php
  4. 9
      app/widgets/Chat/_chat.tpl
  5. 3
      app/widgets/Chats/Chats.php
  6. 2
      app/widgets/Chats/_chats_item.tpl
  7. 42
      app/widgets/Rooms/Rooms.php
  8. 2
      app/widgets/Rooms/_rooms.tpl
  9. 17
      app/widgets/Rooms/_rooms_list.tpl
  10. 2
      app/widgets/Roster/_roster_item.tpl

8
app/Conference.php

@ -26,7 +26,9 @@ class Conference extends Model
public function presences()
{
return $this->hasMany('App\Presence', 'jid', 'conference')
->where('session_id', $this->session_id);
->where('session_id', $this->session_id)
->orderBy('mucaffiliation', 'desc')
->orderBy('value');
}
public function setAvatar($vcard)
@ -53,8 +55,8 @@ class Conference extends Model
$resource = $this->nick;
}
return ($this->presences->where('mucjid', \App\User::me()->id)->first()
|| $this->presences->where('resource', $resource)->first());
return ($this->presences->where('mucjid', \App\User::me()->id)->count() > 0
|| $this->presences->where('resource', $resource)->count() > 0);
}
public function getPhoto($size = 'l')

3
app/Presence.php

@ -20,7 +20,8 @@ class Presence extends Model
protected $fillable = [
'session_id',
'jid',
'resource'
'resource',
'mucjid'
];
public function roster()

12
app/widgets/Chat/Chat.php

@ -104,6 +104,8 @@ class Chat extends \Movim\Widget\Base
$cd = new \Modl\ConferenceDAO;
$c = $cd->get($from);
//$this->user->session->conferences->where('conference', $room)->first();
Notification::append(
'chat|'.$from,
($c != null && $c->name) ? $c->name : $from,
@ -226,12 +228,10 @@ class Chat extends \Movim\Widget\Base
{
if (!$this->validateJid($room)) return;
$cod = new \Modl\ConferenceDAO;
$r = $cod->get($room);
$r = $this->user->session->conferences->where('conference', $room)->first();
if ($r) {
$rooms = new Rooms;
if (!$rooms->checkConnected($r->conference, $r->nick)) {
if (!$r->connected) {
$this->rpc('Rooms_ajaxJoin', $r->conference, $r->nick);
}
@ -579,7 +579,9 @@ class Chat extends \Movim\Widget\Base
$view->assign('room', $jid);
$view->assign('subject', $md->getRoomSubject($jid));
$view->assign('presence', $pd->getMyPresenceRoom($jid));
$view->assign('conference', $cd->get($jid));
$view->assign('conference', $this->user->session->conferences
->where('conference', $jid)
->first());
$mucinfo = $id->getJid(explodeJid($jid)['server']);
if ($mucinfo && !empty($mucinfo->abuseaddresses)) {

9
app/widgets/Chat/_chat.tpl

@ -1,6 +1,5 @@
<header class="fixed">
{if="$muc"}
{$connected = $conference->checkConnected()}
<ul class="list middle">
<li>
<span id="back" class="primary icon active"
@ -29,7 +28,7 @@
</span>
{/if}
<span class="control icon show_context_menu active {if="!$connected"}disabled{/if}">
<span class="control icon show_context_menu active {if="!$conference->connected"}disabled{/if}">
<i class="zmdi zmdi-more-vert"></i>
</span>
@ -41,7 +40,7 @@
</span>
<span
class="control icon active {if="!$connected"}disabled{/if}"
class="control icon active {if="!$conference->connected"}disabled{/if}"
onclick="Rooms_ajaxList('{$jid|echapJS}')">
<i class="zmdi zmdi-accounts"></i>
</span>
@ -52,7 +51,7 @@
<p class="line">{$room}</p>
{/if}
{if="!$connected"}
{if="!$conference->connected"}
<p>{$c->__('button.connecting')}…</p>
{elseif="$subject != null"}
<p class="line" title="{$subject->subject}">{$subject->subject|addUrls}</p>
@ -185,7 +184,7 @@
</div>
<div class="chat_box">
<ul class="list">
<li class="{if="$muc && !$connected"}disabled{/if}">
<li class="{if="$muc && !$conference->connected"}disabled{/if}">
{if="!$muc"}
<span class="primary icon gray emojis_open" onclick="Stickers_ajaxShow('{$jid}')">
<img alt=":smiley:" class="emoji large" src="{$c->getSmileyPath('1f603')}">

3
app/widgets/Chats/Chats.php

@ -39,12 +39,11 @@ class Chats extends \Movim\Widget\Base
function onPresence($packet)
{
if ($packet->content != null){
$c = $contacts[0];
$chats = \App\Cache::c('chats');
if (is_array($chats) && array_key_exists($packet->content->jid, $chats)) {
$this->rpc(
'MovimTpl.replace',
'#' . cleanupId($c->jid.'_chat_item'),
'#' . cleanupId($packet->content->jid.'_chat_item'),
$this->prepareChat($packet->content->jid));
$this->rpc('Chats.refresh');

2
app/widgets/Chats/_chats_item.tpl

@ -39,7 +39,7 @@
{/if}
{if="$roster && $roster->presence && $roster->presence->capability"}
<span class="second">
<span class="second" title="{$roster->presence->capability->name}">
<i class="zmdi {$roster->presence->capability->getDeviceIcon()}"></i>
</span>
{/if}

42
app/widgets/Rooms/Rooms.php

@ -10,6 +10,7 @@ use Moxl\Xec\Action\Disco\Request;
use Ramsey\Uuid\Uuid;
use Respect\Validation\Validator;
use Illuminate\Support\Collection;
use Movim\Session;
@ -61,8 +62,7 @@ class Rooms extends \Movim\Widget\Base
function onGetBookmark()
{
foreach($this->user->session->conferences as $room) {
if ($room->autojoin
&& !$this->checkConnected($room->conference, $room->nick)) {
if ($room->autojoin && !$room->connected) {
$this->ajaxJoin($room->conference, $room->nick);
}
}
@ -348,44 +348,22 @@ class Rooms extends \Movim\Widget\Base
->request();
}
function checkConnected($room, $resource = false)
{
if (!$this->validateRoom($room)) return;
if ($resource && !$this->validateResource($resource)) {
Notification::append(null, $this->__('chatrooms.bad_id'));
return;
}
if ($resource == false) {
$session = Session::start();
$resource = $session->get('username');
}
$conference = $this->user->session->conferences
->where('conference', $room)->first();
return ($conference->presences->where('mucjid', $this->user->id)->first()
|| $conference->presences->where('resource', $resource)->first());
}
function prepareRooms($edit = false)
{
$list = $this->user->session->conferences;
/*$connected = [];
foreach ($list as $key => $room) {
if ($this->checkConnected($room->conference, $room->nick)) {
$room->connected = true;
array_push($connected, $room);
unset($list[$key]);
$conferences = $this->user->session->conferences;
$connected = new Collection;
foreach ($conferences as $key => $conference) {
if ($conference->connected) {
$connected->push($conferences->pull($key));
}
}
$connected = array_merge($connected, $list);*/
$conferences = $connected->merge($conferences);
$view = $this->tpl();
$view->assign('edit', $edit);
$view->assign('conferences', $list);
$view->assign('conferences', $conferences);
$view->assign('room', $this->get('r'));
return $view->draw('_rooms', true);

2
app/widgets/Rooms/_rooms.tpl

@ -50,7 +50,7 @@
{if="isset($info) && $info->description"}title="{$info->description}"{/if}>
{if="$value->connected"}
<span title="{$c->__('communitydata.sub', $info->occupants)}">
{$value->countConnected()} <i class="zmdi zmdi-accounts"></i> –
{$value->presences->count()} <i class="zmdi zmdi-accounts"></i> –
</span>
{elseif="isset($info) && $info->occupants > 0"}
<span title="{$c->__('communitydata.sub', $info->occupants)}">

17
app/widgets/Rooms/_rooms_list.tpl

@ -32,17 +32,22 @@
<i class="zmdi zmdi-star"></i>
</span>
{/if}
{if="$value->mucjid && strpos($value->mucjid, '/') == false && !$c->supported('anonymous')"}
<p class="line normal">
<p class="line normal">
{if="$value->mucjid && strpos($value->mucjid, '/') == false && !$c->supported('anonymous')"}
{if="$value->mucjid == $me"}
{$value->resource}
{else}
<a href="{$c->route('contact', $value->mucjid)}">{$value->resource}</a>
{/if}
</p>
{else}
<p class="line normal">{$value->resource}</p>
{/if}
{else}
{$value->resource}
{/if}
{if="$value->capability"}
<span class="second" title="{$value->capability->name}">
<i class="zmdi {$value->capability->getDeviceIcon()}"></i>
</span>
{/if}
</p>
{if="$value->status"}
<p class="line">{$value->status}</p>
{/if}

2
app/widgets/Roster/_roster_item.tpl

@ -41,7 +41,7 @@
<p class="normal line">
{$contact->truename}
{if="$contact->presence && $contact->presence->capability"}
<span class="second">
<span class="second" title="{$contact->presence->capability->name}">
<i class="zmdi {$contact->presence->capability->getDeviceIcon()}"></i>
</span>
{/if}

Loading…
Cancel
Save