Browse Source

Use composite foreign keys for Session presences relationships

Add presences in the AdminSessions widget
pull/1373/head
Timothée Jaussoin 1 year ago
parent
commit
c99070c56b
  1. 2
      CHANGELOG.md
  2. 5
      app/Presence.php
  3. 11
      app/Session.php
  4. 2
      app/Widgets/AdminSessions/AdminSessions.php
  5. 2
      app/Widgets/AdminSessions/adminsessions.tpl

2
CHANGELOG.md

@ -13,6 +13,8 @@ v0.28.1 (master)
* Add a boot() method to the Base widget class to allow tasks registration
* Clear Chats widget cache during the night
* Completely replace the offset parameter with a Session Timezone set on Login
* Use composite foreign keys for Session presences relationships
* Add presences in the AdminSessions widget
v0.28
---------------------------

5
app/Presence.php

@ -2,14 +2,17 @@
namespace App;
use Movim\Model;
use Movim\Image;
use Movim\ImageSize;
use Movim\Session;
use Moxl\Xec\Action\Presence\Muc;
use Awobaz\Compoships\Database\Eloquent\Model;
class Presence extends Model
{
use \Awobaz\Compoships\Compoships;
protected $primaryKey = ['session_id', 'jid', 'resource'];
public $incrementing = false;

11
app/Session.php

@ -2,12 +2,15 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Movim\Session as MemorySession;
use Awobaz\Compoships\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;
class Session extends Model
{
use \Awobaz\Compoships\Compoships;
protected $fillable = ['id'];
protected $keyType = 'string';
protected $with = ['serverCapability'];
@ -25,14 +28,12 @@ class Session extends Model
public function ownPresences()
{
return $this->hasMany('App\Presence')->where('jid', $this->user_id);
return $this->hasMany('App\Presence', ['jid', 'session_id'], ['user_id', 'id']);
}
public function presence()
{
return $this->hasOne('App\Presence', 'jid', 'user_id')
->where('resource', $this->resource)
->where('session_id', $this->id);
return $this->hasOne('App\Presence', ['jid', 'resource', 'session_id'], ['user_id', 'resource', 'id']);
}
public function serverCapability()

2
app/Widgets/AdminSessions/AdminSessions.php

@ -13,6 +13,6 @@ class AdminSessions extends Base
public function display()
{
$this->view->assign('sessions', \App\Session::with('user')->get());
$this->view->assign('sessions', \App\Session::with(['user', 'presence'])->get());
}
}

2
app/Widgets/AdminSessions/adminsessions.tpl

@ -16,7 +16,7 @@
<span class="control gray icon">
<i class="material-symbols">chevron_right</i>
</span>
<span class="primary icon bubble">
<span class="primary icon bubble status {if="$value->presence"}{$value->presence->presencekey}{/if}">
<img src="{$user->getPicture()}">
</span>
<div>

Loading…
Cancel
Save