core: support mention notification

This commit is contained in:
undefined committed 2021-09-20 22:42:24 +08:00
1 parent d66c161e66
commit ca00dda575
14 files changed
+67 -24

No files matched your search

@@ -40,6 +40,12 @@ const messagePage = new AutoloadPage('messagePage', (pagename) => {
<p>${i18n(msg.mdoc.content)}</p>
</div>`,
}).open();
} else if (msg.udoc._id === 1 && msg.mdoc.flag & 4) {
new VjNotification({
message: 'You received a system message, click here to view.',
duration: 15000,
action: () => window.open(`/home/messages?uid=${msg.udoc._id}`, '_blank'),
}).show();
} else {
// Is message
new VjNotification({
@@ -41,11 +41,24 @@ export default connect(mapStateToProps)(class MessagePadDialogueContentContainer
}
renderContent(msg) {
// TODO: FLAG_RICHTEXT
if (msg.from === 1) {
// Is system message
try {
const data = JSON.parse(msg.content);
return i18n(data.message, ...data.params);
const str = i18n(data.message).replace(/\{([^{}]+)\}/g, (match, key) => `%substitude%${key}%substitude%`);
const arr = str.split('%substitude%');
data.params = data.params || {};
for (let i = 1; i < arr.length; i += 2) {
if (arr[i].endsWith(':link')) {
const link = data.params[arr[i].split(':link')[0]];
if (!link) continue;
arr[i] = <a style={{ color: 'wheat' }} href={link} key={i} target="_blank" rel="noreferrer">{link}</a>;
} else {
arr[i] = <span style={{ color: 'wheat' }} key={i}>{data.params[arr[i]]}</span>;
}
}
return arr;
} catch (e) { }
return i18n(msg.content);
}
@@ -3,6 +3,7 @@ import _ from 'lodash';
import { connect } from 'react-redux';
import 'jquery-scroll-lock';
import i18n from 'vj/utils/i18n';
import ListItem from './DialogueListItemComponent';
const mapStateToProps = (state) => ({
@@ -38,7 +39,12 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MessagePadDial
<ListItem
key={dialogue._id}
userName={dialogue.udoc.uname}
summary={(_.last(dialogue.messages)?.content) || ''}
// eslint-disable-next-line no-nested-ternary
summary={_.last(dialogue.messages)
? (_.last(dialogue.messages).flag & 4)
? i18n('[Richtext message]')
: _.last(dialogue.messages).content
: ''}
faceUrl={dialogue.udoc.avatarUrl}
active={dialogue._id === this.props.activeId}
onClick={() => this.props.handleClick(dialogue._id)}
@@ -123,12 +123,10 @@ monaco.editor.registerCommand('hydro.openUserPage', (accesser, uid) => {
monaco.languages.registerCodeLensProvider('markdown', {
async provideCodeLenses(model) {
const users = model.findMatches('\\[\\]\\(/user/(\\d+)\\)', true, true, true, null, true);
const { data } = await api(`
query {
users(ids: [${users.map((i) => i.matches[1]).join(',')}]) {
_id
uname
}
const { data } = await api(gql`
users(ids: ${users.map((i) => +i.matches[1])}) {
_id
uname
}
`);
return {
@@ -172,6 +170,7 @@ monaco.languages.registerCompletionItemProvider('markdown', {
_id
uname
avatarUrl
priv
}
`, ['data', 'users']);
return {
@@ -179,8 +178,9 @@ monaco.languages.registerCompletionItemProvider('markdown', {
label: `@${i.uname} (UID=${i._id})`,
kind: monaco.languages.CompletionItemKind.Property,
documentation: { value: `![monaco_avatar](${i.avatarUrl})`, isTrusted: true },
insertText: `[](/user/${i._id}) `,
insertText: `@[](/user/${i._id}) `,
range,
sortText: i.priv === 0 ? '0' : '1',
tags: i.priv === 0 ? [1] : [],
})),
};