MDL-57394 mod_chat: Move get session messages code to new function

This commit is contained in:
Juan Leyva 2017-09-22 16:12:21 +02:00
parent 26b4e8580d
commit 2971d8421c
4 changed files with 43 additions and 29 deletions

View file

@ -681,16 +681,8 @@ class mod_chat_external extends external_api {
}
}
// If the user is allocated to a group, only show messages from people in the same group, or no group.
$queryparams = array('chatid' => $chat->id);
if ($groupid) {
$groupselect = " AND (groupid = :groupid OR groupid = 0)";
$queryparams['groupid'] = $groupid;
} else {
$groupselect = "";
}
if ($messages = $DB->get_records_select('chat_messages', "chatid = :chatid $groupselect", $queryparams, "timestamp DESC")) {
$messages = chat_get_session_messages($chat->id, $groupid, 0, 0, 'timestamp DESC');
if ($messages) {
$chatsessions = chat_get_sessions($messages, $params['showall']);
// Format sessions for external.
foreach ($chatsessions as $session) {