$self->app->log->info($self->session('name')." leaved the room $name");
$self->app->log->info($self->session('name')." leaved the room $name");
return1;
return1;
@ -238,7 +238,7 @@ helper get_participants => sub {
my$self=shift;
my$self=shift;
my($name)=@_;
my($name)=@_;
my$room=$self->get_room($name)||returnundef;
my$room=$self->get_room($name)||returnundef;
my$sth=eval{$self->db->prepare("SELECT participant FROM participants WHERE id=?;")}||returnundef;
my$sth=eval{$self->db->prepare("SELECT `participant` FROM `participants` WHERE `id`=?;")}||returnundef;
$sth->execute($room->{id})||returnundef;
$sth->execute($room->{id})||returnundef;
my@res;
my@res;
while(my@row=$sth->fetchrow_array){
while(my@row=$sth->fetchrow_array){
@ -252,11 +252,12 @@ helper set_peer_role => sub {
my$self=shift;
my$self=shift;
my($room,$name,$id,$role)=@_;
my($room,$name,$id,$role)=@_;
# Check if this ID isn't the one from another peer first
# Check if this ID isn't the one from another peer first
my$sth=eval{$self->db->prepare("SELECT * FROM participants WHERE peer_id=? AND participant!=? AND id IN (SELECT id FROM rooms WHERE name=?)")}||returnundef;
my$sth=eval{$self->db->prepare("SELECT * FROM `participants` WHERE `peer_id`=? AND `participant`!=? AND `id` IN (SELECT `id` FROM `rooms` WHERE `name`=?)")}||returnundef;
$sth->execute($id,$name,$room)||returnundef;
$sth->execute($id,$name,$room)||returnundef;
returnundefif($sth->rows>0);
returnundefif($sth->rows>0);
$sth=eval{$self->db->prepare("UPDATE participants SET peer_id=?,role=? WHERE participant=? AND id IN (SELECT id FROM rooms WHERE name=?)")}||returnundef;
$sth=eval{$self->db->prepare("UPDATE `participants` SET `peer_id`=?,`role`=? WHERE `participant`=? AND `id` IN (SELECT `id` FROM `rooms` WHERE `name`=?)")}||returnundef;
$self->app->log->info("User $id has now the $role role in room $name");
return1;
return1;
};
};
@ -264,7 +265,7 @@ helper set_peer_role => sub {
helperget_peer_role=>sub{
helperget_peer_role=>sub{
my$self=shift;
my$self=shift;
my($room,$id)=@_;
my($room,$id)=@_;
my$sth=eval{$self->db->prepare("SELECT role from participants WHERE peer_id=? AND id IN (SELECT id FROM rooms WHERE name=?)")}||returnundef;
my$sth=eval{$self->db->prepare("SELECT `role` FROM `participants` WHERE `peer_id`=? AND `id` IN (SELECT `id` FROM `rooms` WHERE `name`=?)")}||returnundef;
$sth->execute($id,$room)||returnundef;
$sth->execute($id,$room)||returnundef;
if($sth->rows==1){
if($sth->rows==1){
my($role)=$sth->fetchrow_array();
my($role)=$sth->fetchrow_array();
@ -281,7 +282,7 @@ helper has_joined => sub {
my$self=shift;
my$self=shift;
my($session,$name)=@_;
my($session,$name)=@_;
my$ret=0;
my$ret=0;
my$sth=eval{$self->db->prepare("SELECT * FROM rooms WHERE name=? AND id IN (SELECT id FROM participants WHERE participant=?)")}||returnundef;
my$sth=eval{$self->db->prepare("SELECT * FROM `rooms` WHERE `name`=? AND `id` IN (SELECT `id` FROM `participants` WHERE `participant`=?)")}||returnundef;
$sth->execute($name,$session)||returnundef;
$sth->execute($name,$session)||returnundef;
$ret=1if($sth->rows>0);
$ret=1if($sth->rows>0);
return$ret;
return$ret;
@ -293,18 +294,18 @@ helper delete_rooms => sub {
$self->app->log->debug('Removing unused rooms');
$self->app->log->debug('Removing unused rooms');
eval{
eval{
my$timeout=time()-$config->{inactivityTimeout};
my$timeout=time()-$config->{inactivityTimeout};
$self->db->do("DELETE FROM participants WHERE id IN (SELECT id FROM rooms WHERE activity_timestamp < $timeout AND persistent='0');");
$self->db->do("DELETE FROM `participants` WHERE `id` IN (SELECT `id` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0');");
$self->db->do("DELETE FROM notifications WHERE id IN (SELECT id FROM rooms WHERE activity_timestamp < $timeout AND persistent='0');");
$self->db->do("DELETE FROM `notifications` WHERE `id` IN (SELECT `id` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0');");
$self->db->do("DELETE FROM invitations WHERE id IN (SELECT id FROM rooms WHERE activity_timestamp < $timeout AND persistent='0');");
$self->db->do("DELETE FROM `invitations` WHERE `id` IN (SELECT `id` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0');");
$self->db->do("DELETE FROM rooms WHERE activity_timestamp < $timeout AND persistent='0';");
$self->db->do("DELETE FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0';");