-
-
Notifications
You must be signed in to change notification settings - Fork 880
Expand file tree
/
Copy pathtextFormatter.js
More file actions
51 lines (39 loc) · 1.52 KB
/
Copy pathtextFormatter.js
File metadata and controls
51 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import app from 'flarum/forum/app';
import username from 'flarum/common/helpers/username';
import extractText from 'flarum/common/utils/extractText';
import isDark from 'flarum/common/utils/isDark';
export function filterUserMentions(tag) {
let user;
if (app.forum.attribute('allowUsernameMentionFormat') && tag.hasAttribute('username'))
user = app.store.getBy('users', 'username', tag.getAttribute('username'));
else if (tag.hasAttribute('id')) user = app.store.getById('users', tag.getAttribute('id'));
if (user) {
tag.setAttribute('id', user.id());
tag.setAttribute('slug', user.slug());
tag.setAttribute('displayname', extractText(username(user)));
return true;
}
tag.invalidate();
}
export function filterPostMentions(tag) {
const post = app.store.getById('posts', tag.getAttribute('id'));
if (post) {
tag.setAttribute('discussionid', post.discussion().id());
tag.setAttribute('number', post.number());
tag.setAttribute('displayname', extractText(username(post.user())));
return true;
}
}
export function filterGroupMentions(tag) {
if (app.session?.user?.canMentionGroups()) {
const group = app.store.getById('groups', tag.getAttribute('id'));
if (group) {
tag.setAttribute('groupname', extractText(group.namePlural()));
tag.setAttribute('icon', group.icon());
tag.setAttribute('color', group.color());
tag.setAttribute('class', isDark(group.color()) ? 'GroupMention--light' : 'GroupMention--dark');
return true;
}
}
tag.invalidate();
}