Skip to content

Commit

Permalink
[K6.3] Improve to get list of users of the topic to list to mentions #4
Browse files Browse the repository at this point in the history
  • Loading branch information
xillibit committed Nov 26, 2023
1 parent 01e03da commit 8ebc506
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ public static function getUserIds(array $topics, $value = 'user_id'): array
$db->setQuery($query);

try {
$results = (array) $db->loadRowList();
$results = $db->loadObjectList();
} catch (ExecutionFailureException $e) {
KunenaError::displayDatabaseError($e);
}

$list = [];

if (!empty($results)) {
foreach ($results as $result) {
$list[$result->topic_id][$result->user_id] = $result->{$value};
foreach ($results as $key => $result) {
$list[$key] = $result->user_id;
}
}

Expand Down
38 changes: 23 additions & 15 deletions src/site/src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Kunena\Forum\Libraries\Forum\KunenaForum;
use Kunena\Forum\Libraries\Forum\Message\KunenaMessageHelper;
use Kunena\Forum\Libraries\Forum\Message\Karma\KunenaKarmaHelper;
use Kunena\Forum\Libraries\Forum\Topic\User\KunenaTopicUserHelper;
use Kunena\Forum\Libraries\Log\KunenaLog;
use Kunena\Forum\Libraries\Login\KunenaLogin;
use Kunena\Forum\Libraries\Path\KunenaPath;
Expand Down Expand Up @@ -1362,32 +1363,39 @@ public function delfile()
*/
public function getusersmentions() {
$id = $this->input->getInt('topicid', 0);
$topicId = [0 => $id];

$userIdsList = KunenaTopicUserHelper::getUserIds($topicId);

$usersList = KunenaUserHelper::loadUsers($userIdsList);

header('Content-type: application/json');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$obj = new stdClass();
$obj->id = 1;
$obj->avatar = 'm_1';
$obj->fullname = 'Charles Flores';
$obj->username = 'cflores';

$myarray = [$obj

];

$response = json_encode($myarray);


$userListMentions = [];

foreach ($usersList as $key => $user) {
$obj = new stdClass();
$obj->id = $key;
//$obj->avatar = 'm_1';
$obj->fullname = $user->name;
$obj->username = $user->username;

$userListMentions[] = $obj;
}

$response = json_encode($userListMentions);

if (ob_get_length()) {
ob_end_clean();
}

echo json_encode($response);

jexit();
}
}
4 changes: 2 additions & 2 deletions src/site/template/aurelia/assets/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ jQuery(document).ready(function ($) {
on: {
instanceReady: function (event) {
CKEDITOR.plugins.clipboard.preventDefaultDropOnElement(event.editor.document);

if (event.editor.getData().length > 0)
{
$('#form_submit_button').removeAttr("disabled");
}

event.editor.on("beforeCommandExec", function (event) {
event.editor.on("beforeCommandExec", function (event) {
// Show the paste dialog for the paste buttons and right-click paste
if (event.data.name == "paste") {
event.editor._.forcePasteDialog = true;
Expand Down

0 comments on commit 8ebc506

Please sign in to comment.