Skip to content

Commit

Permalink
personal message option
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasCaleb committed Apr 29, 2024
1 parent 4af7a51 commit cf773c0
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
6 changes: 4 additions & 2 deletions classes/task/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public function execute() {
$viewaction = \core_message\api::MESSAGE_ACTION_READ;// 1
$users = null;

$types = $individualmessage.','.\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF;
$types = $individualmessage;
if ($configs->deletegroupmessages > 0) {
$types .= ','.\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP;
}

if ($configs->deletepersonalmessage > 0) {
$types .= ','.\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF;
}
if ($configs->deletereadmessages > 0) {
$reftime = time() - $configs->deletereadmessages;
$sql = "SELECT distinct userid from {message_conversation_members}";
Expand Down
2 changes: 2 additions & 0 deletions lang/en/tool_deletemessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
$string['cleanmessage_desc'] = "When Both user delete all messages between them the messages will be erased from database";
$string['deletegroupmessages'] = "Delete Group Messages";
$string['deletegroupmessages_desc'] = "Include Group Messagens in filter to delete old and readed messages";
$string['deletepersonalmessage'] = "Delete Private Messages";
$string['deletegroupmessages_desc'] = "Delete messages in the personal conversation, messages send by user to himself if they are in filter";
2 changes: 2 additions & 0 deletions lang/pt_br/tool_deletemessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
$string['cleanmessage_desc'] = "Quando dois usuários apagam todas as mensagens entre eles as conversas serão apagadas do banco de dados";
$string['deletegroupmessages'] = "Deletar Mensagens de Grupo";
$string['deletegroupmessages_desc'] = "Incluir mensagens de grupo nas mensagens a serem apagadas apos leitura";
$string['deletepersonalmessage'] = "Deletar Mensagens Privadas";
$string['deletegroupmessages_desc'] = "Incluir as mensagens do usuário para ele mesmo para serem apagadas pelo filtro";
4 changes: 4 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
get_string('deletegroupmessages', 'tool_deletemessage'),
get_string('deletegroupmessages_desc', 'tool_deletemessage'), $default));

$page->add(new admin_setting_configcheckbox('tool_deletemessage/deletepersonalmessage',
get_string('deletepersonalmessage', 'tool_deletemessage'),
get_string('deletepersonalmessage_desc', 'tool_deletemessage'), $default));

$ADMIN->add('messaging', $page);

}
Expand Down
91 changes: 91 additions & 0 deletions tests/tool_deletemessage_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Delete Task.
*
* @package tool_deletemessage
* @author Esdras Caleb
* @copyright 2023 Esdras Caleb
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_deletemessage;


/**
* Class test if this plugin is deleting things it should not delete
* @author Esdras Caleb
* @copyright 2023 Esdras Caleb
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_deletemessage_test extends \advanced_testcase {

/**
* Make message to tests
* @return int message id
*/
private function make_message() {
$userfrom = $this->getDataGenerator()->create_user();
$userto = $this->getDataGenerator()->create_user();

// Message text.
$messagetext = "hello";

// Create message object.
$message = new \core\message\message();
$message->component = 'core';
$message->name = 'instantmessage';
$message->userfrom = $userfrom;
$message->userto = $userto;
$message->subject = '';
$message->fullmessage = $messagetext;
$message->fullmessageformat = FORMAT_PLAIN;
$message->fullmessagehtml = $messagetext;
$message->smallmessage = $messagetext;

return message_send($message);
}

/**
* Test if the hard delection function works
* @return void
*/
public function test_deleting() {
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');

$messageid = $this->make_message();
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
hard_delete_message($messageid);
$this->assertEmpty($DB->get_records('message', ['id' => $messageid]));
}

/**
* Test taks of delection to not delete all messages
* @return void
*/
public function test_taks_isnotdeleting() {
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');

$messageid = $this->make_message();

$cron = new \tool_deletemessage\task\delete();
$cron->execute();
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
$this->assertNotEmpty($DB->get_records('message'));
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

// Plugin version.
$plugin->version = 2024042900;
$plugin->version = 2024042905;

// Required Moodle version.
$plugin->requires = 2018051718; // Requires this Moodle version - at least 3.5 (new messsage system).
Expand Down

0 comments on commit cf773c0

Please sign in to comment.