Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix: get user by display name #4196

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/Controller/MentionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Notification\IManager;

class MentionController extends Controller {
Expand All @@ -25,6 +26,7 @@ public function __construct(
private IRootFolder $rootFolder,
private IManager $manager,
private ITimeFactory $timeFactory,
private IUserManager $userManager,
private ?string $userId,
) {
parent::__construct($appName, $request);
Expand All @@ -39,14 +41,22 @@ public function mention(int $fileId, string $mention): DataResponse {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

$userFolder = $this->rootFolder->getUserFolder($mention);
// Reverse the array of users to pop off the first user later
$userResults = array_reverse($this->userManager->searchDisplayName($mention, 1));
if (count($userResults) < 1) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

// Get the first user returned in the array
$user = array_pop($userResults);
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$file = $userFolder->getById($fileId)[0];
if ($file === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}

$notification = $this->manager->createNotification();
$notification->setUser($mention)
$notification->setUser($user->getUID())
->setApp(Application::APPNAME)
->setSubject(Notifier::TYPE_MENTIONED, [
Notifier::SUBJECT_MENTIONED_SOURCE_USER => $this->userId,
Expand All @@ -58,7 +68,6 @@ public function mention(int $fileId, string $mention): DataResponse {
$notification->setDateTime(\DateTime::createFromImmutable($this->timeFactory->now()));
$this->manager->notify($notification);
return new DataResponse([], Http::STATUS_OK);

}

return new DataResponse([], Http::STATUS_NOT_FOUND);
Expand Down
Loading