1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/app/widgets/Notifs/Notifs.php

152 lines
3.5 KiB
PHP
Raw Normal View History

<?php
/**
* @package Widgets
*
* @file Notifs.php
* This file is part of MOVIM.
*
* @brief The notification widget
*
* @author Timothée Jaussoin <edhelas@gmail.com>
*
* @version 1.0
* @date 16 juin 2011
*
* Copyright (C)2010 MOVIM project
*
* See COPYING for licensing information.
*/
use Moxl\Xec\Action\Presence\Subscribed;
use Moxl\Xec\Action\Presence\Unsubscribed;
use Moxl\Xec\Action\Roster\AddItem;
use Moxl\Xec\Action\Roster\UpdateItem;
use Moxl\Xec\Action\Presence\Subscribe;
class Notifs extends WidgetBase
{
function load()
{
$this->addcss('notifs.css');
$this->addjs('notifs.js');
$this->registerEvent('subscribe', 'onNotifs');
$this->registerEvent('roster_additem_handle', 'onNotifs');
$this->registerEvent('roster_updateitem_handle', 'onNotifs');
$this->registerEvent('presence_subscribe_handle', 'onNotifs');
$this->registerEvent('presence_subscribed_handle', 'onNotifs');
}
function onNotifs($packet = false)
{
$html = $this->prepareNotifs();
RPC::call('movim_fill', 'notifs_widget', $html);
RPC::call('Notifs.refresh');
}
2015-08-19 11:28:28 +02:00
function ajaxGet()
{
$this->onNotifs();
}
/*
* Create the list of notifications
* @return string
2015-08-19 11:28:28 +02:00
*/
function prepareNotifs()
{
$cd = new \Modl\ContactDAO();
$contacts = $cd->getRosterFrom();
$invitations = array();
2015-08-19 11:28:28 +02:00
$session = \Session::start();
$notifs = $session->get('activenotifs');
if(is_array($notifs)) {
foreach($notifs as $key => $value) {
array_push($invitations, $cd->get($key));
}
}
$nft = $this->tpl();
$nft->assign('invitations', $invitations);
$nft->assign('contacts', $contacts);
return $nft->draw('_notifs_from', true);
}
function ajaxAsk($jid)
{
$view = $this->tpl();
$view->assign('jid', $jid);
Dialog::fill($view->draw('_notifs_confirm', true));
}
function ajaxAccept($jid)
{
$jid = echapJid($jid);
$rd = new \Modl\RosterLinkDAO();
$c = $rd->get($jid);
if(isset($c) && $c->groupname) {
$ui = new UpdateItem;
$ui->setTo($jid)
->setFrom($this->user->getLogin())
->setName($c->rostername)
->setGroup($c->groupname)
->request();
} else {
$r = new AddItem;
$r->setTo($jid)
->setFrom($this->user->getLogin())
->request();
}
$p = new Subscribe;
$p->setTo($jid)
->request();
$p = new Subscribed;
$p->setTo($jid)
->request();
// TODO : move in Moxl
2015-08-19 11:28:28 +02:00
$session = \Session::start();
$notifs = $session->get('activenotifs');
unset($notifs[$jid]);
2015-08-19 11:28:28 +02:00
$session->set('activenotifs', $notifs);
}
function ajaxRefuse($jid)
{
$jid = echapJid($jid);
2015-08-19 11:28:28 +02:00
$p = new Unsubscribed;
$p->setTo($jid)
->request();
// TODO : move in Moxl
2015-08-19 11:28:28 +02:00
$session = \Session::start();
$notifs = $session->get('activenotifs');
unset($notifs[$jid]);
2015-08-19 11:28:28 +02:00
$session->set('activenotifs', $notifs);
$this->onNotifs();
}
function genCallAccept($jid)
{
return $this->call('ajaxAccept', "'".$jid."'");
}
function genCallRefuse($jid)
{
return $this->call('ajaxRefuse', "'".$jid."'");
}
}