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] : [],
})),
};
+2
View File
@@ -1,5 +1,6 @@
__langname: 简体中文
'"{data}" copied to clipboard!': “{data}”已复制到剪贴板!
'[Richtext message]': '[富文本消息]'
'{} is a moderator of this domain.': '{}是这个域的管理者之一。'
'{0} comments': '{0} 条评论'
'{0} discussions': '{0} 条讨论'
@@ -873,6 +874,7 @@ You have uncompleted domain creation operation. You can click "Continue" to fini
You haven't attended this contest yet.: 您还没有参加本次比赛。
You haven't claimed this homework yet.: 您还未认领过该作业。
You need to enter the invitation code to join the domain.: 您需要输入邀请码来加入此域。
You received a system message, click here to view.: 您收到一条系统通知,点击查看。
You're not logged in.: 您没有登录。
You've already attended this contest.: 您已经参加本次比赛。
You've already claimed this homework.: 您已认领过该作业。
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.21.11",
"version": "4.22.0",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
@@ -44,7 +44,10 @@ const page = new NamedPage('home_messages', () => {
avatar: msg.udoc.avatarUrl,
message: msg.mdoc.content,
duration: 15000,
action: () => createDialog(msg.udoc),
action: () => store.dispatch({
type: 'DIALOGUES_SWITCH_TO',
payload: msg.udoc._id,
}),
}).show();
};
+1 -1
View File
@@ -15,7 +15,7 @@ export default async (q: string, path: string[] = []) => {
export const gql = (
pieces: TemplateStringsArray,
...templates: (string | number)[]
...templates: (string | number | string[] | number[])[]
) => {
let res = '';
for (let i = 0; i < pieces.length; i++) {
+1 -4
View File
@@ -1,10 +1,7 @@
import substitute from './substitute';
export default function i18n(str, ...params) {
if (window.LOCALES && window.LOCALES[str]) {
return substitute(window.LOCALES[str], params);
}
return substitute(str, params);
return substitute(window.LOCALES?.[str] || str, params);
}
window.Hydro.utils.i18n = i18n;