Browse Source

Enable rooms messages counter

Improve notifications (add default Movim logo)
pull/183/head
Timothée Jaussoin 10 years ago
parent
commit
3533658d90
  1. 2
      app/widgets/Chats/Chats.php
  2. 21
      app/widgets/Notification/Notification.php
  3. 18
      app/widgets/Rooms/Rooms.php
  4. 1
      app/widgets/Rooms/_rooms.tpl
  5. 4
      app/widgets/Rooms/rooms.js

2
app/widgets/Chats/Chats.php

@ -120,7 +120,7 @@ class Chats extends \Movim\Widget\Base
if(!$this->validateJid($jid)) return;
$chats = Cache::c('chats');
if($chats == null) $chats = array();
if($chats == null) $chats = [];
unset($chats[$jid]);

21
app/widgets/Notification/Notification.php

@ -18,28 +18,33 @@ class Notification extends \Movim\Widget\Base
* @param integer $action An action
* @return void
*/
static function append($key = null, $title, $body = null, $picture = null, $time = 2, $action = null)
static function append($key = null, $title = null, $body = null, $picture = null, $time = 2, $action = null)
{
// In this case we have an action confirmation
if($key == null) {
if($key == null && $title != null) {
RPC::call('Notification.toast', $title);
return;
}
if($picture == null) {
$picture = BASE_URI . '/themes/material/img/app/128.png';
}
$session = Session::start();
$notifs = $session->get('notifs');
RPC::call('Notification.desktop', $title, $body, $picture, $action);
if($title != null)
RPC::call('Notification.desktop', $title, $body, $picture, $action);
$notifs_key = $session->get('notifs_key');
if($notifs == null) $notifs = array();
if($notifs == null) $notifs = [];
$explode = explode('|', $key);
$first = reset($explode);
// What we receive is not what it's on the screen on Android
if($key != null && $key != $notifs_key) {
if($key != null && $key != $notifs_key && $title != null) {
RPC::call('Notification.android', $title, $body, $picture, $action);
}
@ -63,8 +68,10 @@ class Notification extends \Movim\Widget\Base
RPC::call('Notification.counter', $key, $notifs[$key]);
}
$n = new Notification;
RPC::call('Notification.snackbar', $n->prepareSnackbar($title, $body, $picture, $action), $time);
if($title != null) {
$n = new Notification;
RPC::call('Notification.snackbar', $n->prepareSnackbar($title, $body, $picture, $action), $time);
}
$session->set('notifs', $notifs);
}

18
app/widgets/Rooms/Rooms.php

@ -13,12 +13,30 @@ class Rooms extends \Movim\Widget\Base
{
$this->addjs('rooms.js');
$this->addcss('rooms.css');
$this->registerEvent('message', 'onMessage');
$this->registerEvent('bookmark_set_handle', 'onBookmark');
$this->registerEvent('presence_muc_handle', 'onConnected');
$this->registerEvent('presence_unavailable_handle', 'onDisconnected');
$this->registerEvent('presence_muc_errorconflict', 'onConflict');
}
function onMessage($packet)
{
$message = $packet->content;
if($message->session == $message->jidto
&& $message->type == 'groupchat') {
Notification::append(
'chat|'.$message->jidfrom,
null,
$message->body,
null,
0,
null
);
}
}
function onBookmark()
{
$this->refreshRooms();

1
app/widgets/Rooms/_rooms.tpl

@ -10,6 +10,7 @@
<li data-jid="{$value->conference}"
{if="$value->nick != null"} data-nick="{$value->nick}" {/if}
class="room {if="$value->connected"}online{/if}">
<span data-key="chat|{$value->conference}" class="counter"></span>
{if="$value->connected"}
<span class="primary icon small bubble color {$value->name|stringToColor}"><i class="zmdi zmdi-accounts"></i></span>
{else}

4
app/widgets/Rooms/rooms.js

@ -9,7 +9,9 @@ var Rooms = {
if(items[i].dataset.jid != null) {
items[i].onclick = function(e) {
Chats.refresh();
Notification.current('chat');
Notification_ajaxClear('chat|' + this.dataset.jid);
Notification.current('chat|' + this.dataset.jid);
if(!movim_has_class(this, 'online')) {
if(this.dataset.nick != null) {

Loading…
Cancel
Save