Skip to content

Commit 274d7e2

Browse files
feat: display correct username and use ISearch to search users
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 609c607 commit 274d7e2

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

lib/Controller/UserApiController.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
namespace OCA\Text\Controller;
44

55
use \OCP\AppFramework\ApiController;
6+
use OCP\Collaboration\Collaborators\ISearch;
67
use \OCP\IRequest;
7-
use \OCP\IUserManager;
8+
use OCP\Share\IShare;
89

910
class UserApiController extends ApiController {
1011

11-
protected IUserManager $userManager;
12+
protected ISearch $collaboratorSearch;
1213

13-
public function __construct($appName, IRequest $request, IUserManager $userManager) {
14+
public function __construct($appName, IRequest $request, ISearch $ISearch) {
1415
parent::__construct($appName, $request);
1516

16-
$this->userManager = $userManager;
17+
$this->collaboratorSearch = $ISearch;
1718
}
1819

1920
/**
2021
* @param string $filter
2122
*/
22-
public function index(string $filter) {
23-
$result = [];
24-
25-
$users = $this->userManager->search($filter, 5);
26-
foreach ($users as $user) {
27-
$result[$user->getUID()] = $user->getDisplayName();
23+
public function index(string $filter, int $limit = 5) {
24+
$users = [];
25+
[$result] = $this->collaboratorSearch->search($filter, [IShare::TYPE_USER], false, $limit, 0);
26+
27+
foreach ($result['users'] as ['label' => $label, 'value' => $value]) {
28+
if (isset($value['shareWith'])) {
29+
$id = $value['shareWith'];
30+
$users[$id] = $label;
31+
}
2832
}
2933

30-
return $result;
34+
return $users;
3135
}
3236

3337
}

src/extensions/Mention.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default TipTapMention.extend({
2121

2222
toMarkdown(state, node) {
2323
state.write(' ')
24-
state.write(`@[${node.attrs.id}](mention://user/${node.attrs.id})`)
24+
state.write(`@[${node.attrs.id}](mention://user/${node.attrs.label})`)
2525
state.write(' ')
2626
},
2727
})

src/extensions/Mention.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<NodeViewWrapper as="span" class="mention" contenteditable="false">
3-
<UserBubble :user="node.attrs.id" :display-name="node.attrs.id.trim()">
4-
@{{ node.attrs.id.trim() }}
3+
<UserBubble :user="node.attrs.id" :display-name="username" class="mention-user-bubble">
4+
@{{ username }}
55
</UserBubble>
66
</NodeViewWrapper>
77
</template>
@@ -27,11 +27,23 @@ export default {
2727
required: true,
2828
},
2929
},
30+
data() {
31+
return {
32+
username: this.node.attrs.label
33+
}
34+
}
3035
}
3136
</script>
3237
<style scoped>
3338
/* This is required to properly render the bubble text (which seems linke a browser bug) */
3439
.text-editor__wrapper div.ProseMirror .mention[contenteditable=false] :deep(*) {
3540
-webkit-user-modify: read-only !important;
3641
}
42+
43+
.mention-user-bubble /deep/ .user-bubble__content .user-bubble__title {
44+
position: relative !important;
45+
top: -20px !important;
46+
left: -60px !important;
47+
height: 40px;
48+
}
3749
</style>

0 commit comments

Comments
 (0)