Compare commits
5 Commits
7689ec590a
...
095b454539
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
095b454539 | ||
|
|
cbdccfb5a7 | ||
|
|
32719b45ea | ||
|
|
b32f60d94d | ||
|
|
d524304b29 |
@@ -41,7 +41,7 @@ class Client {
|
||||
if (re.code != 200) {
|
||||
if (re.code == -1) {
|
||||
auth()
|
||||
} else if (re.code != 401) {
|
||||
} else if (re.code != 401 && re.code != 400) {
|
||||
const s2 = checkApiSuccessOrSncakbar(re, "重新验证失败")
|
||||
s2!.autoCloseDelay = 0
|
||||
s2!.action = "重试"
|
||||
@@ -98,7 +98,7 @@ class Client {
|
||||
// 错误处理
|
||||
if (err) return resolve({
|
||||
code: -1,
|
||||
msg: err.message.indexOf("timed out") != -1 ? "請求超時" : err.message,
|
||||
msg: err.message.indexOf("timed out") != -1 ? "请求超时" : err.message,
|
||||
})
|
||||
// 在特殊的方法之中, 不予进行: 令牌刷新并重试
|
||||
// 附带 retry 次数限制
|
||||
|
||||
18
client/ui/TextFieldCustom.tsx
Normal file
18
client/ui/TextFieldCustom.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from 'react'
|
||||
import { $, TextField } from "mdui"
|
||||
|
||||
interface Args extends React.HTMLAttributes<TextField & HTMLElement> {
|
||||
|
||||
}
|
||||
|
||||
export default function TextFieldCustom({ ...prop }: Args) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const textField = React.useRef<any>(null)
|
||||
|
||||
React.useEffect(() => {
|
||||
const shadow = (textField.current as TextField).shadowRoot
|
||||
// $(shadow).find('textarea')
|
||||
})
|
||||
|
||||
return <mdui-text-field {...prop} ref={textField}></mdui-text-field>
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import DataCaches from "../../api/DataCaches.ts"
|
||||
import { snackbar } from "../snackbar.ts"
|
||||
|
||||
customElements.define('chat-mention', class extends HTMLElement {
|
||||
declare span: HTMLSpanElement
|
||||
declare link: HTMLAnchorElement
|
||||
static observedAttributes = ['user-id']
|
||||
constructor() {
|
||||
super()
|
||||
@@ -13,10 +13,11 @@ customElements.define('chat-mention', class extends HTMLElement {
|
||||
connectedCallback() {
|
||||
const shadow = this.shadowRoot as ShadowRoot
|
||||
|
||||
this.span = document.createElement('span')
|
||||
this.span.style.fontSynthesis = 'style weight'
|
||||
this.span.style.color = 'rgb(var(--mdui-color-primary))'
|
||||
shadow.appendChild(this.span)
|
||||
this.link = document.createElement('a')
|
||||
this.link.style.fontSynthesis = 'style weight'
|
||||
this.link.style.color = 'rgb(var(--mdui-color-primary))'
|
||||
this.link.href = 'javascript:void(0)'
|
||||
shadow.appendChild(this.link)
|
||||
|
||||
this.update()
|
||||
}
|
||||
@@ -24,33 +25,36 @@ customElements.define('chat-mention', class extends HTMLElement {
|
||||
this.update()
|
||||
}
|
||||
async update() {
|
||||
if (this.span == null) return
|
||||
if (this.link == null) return
|
||||
|
||||
const userId = $(this).attr('user-id')
|
||||
const chatId = $(this).attr('chat-id')
|
||||
const text = $(this).attr('text')
|
||||
this.span.style.fontStyle = ''
|
||||
this.link.style.fontStyle = ''
|
||||
if (chatId) {
|
||||
const chat = await DataCaches.getChatInfo(chatId)
|
||||
this.span.textContent = chat?.title
|
||||
this.span.onclick = () => {
|
||||
this.link.textContent = chat?.title
|
||||
this.link.onclick = (e) => {
|
||||
e.stopPropagation()
|
||||
// deno-lint-ignore no-window
|
||||
window.openChatInfoDialog(chat)
|
||||
}
|
||||
} else if (userId) {
|
||||
const user = await DataCaches.getUserProfile(userId)
|
||||
this.span.textContent = user?.nickname
|
||||
this.span.onclick = () => {
|
||||
this.link.textContent = user?.nickname
|
||||
this.link.onclick = (e) => {
|
||||
e.stopPropagation()
|
||||
// deno-lint-ignore no-window
|
||||
window.openUserInfoDialog(user)
|
||||
}
|
||||
}
|
||||
|
||||
text && (this.span.textContent = text)
|
||||
text && (this.link.textContent = text)
|
||||
if (!(userId || chatId)) {
|
||||
this.span.textContent = "无效的提及"
|
||||
this.span.style.fontStyle = 'italic'
|
||||
this.span.onclick = () => {
|
||||
this.link.textContent = "无效的提及"
|
||||
this.link.style.fontStyle = 'italic'
|
||||
this.link.onclick = (e) => {
|
||||
e.stopPropagation()
|
||||
snackbar({
|
||||
message: "该提及没有指定用户或者对话!",
|
||||
placement: 'top',
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default function isMobileUI() {
|
||||
return new URL(location.href).searchParams.get('mobile') == 'true'
|
||||
return new URL(location.href).searchParams.get('mobile') == 'true' || /Mobi|Android|iPhone/i.test(navigator.userAgent)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export default function ContactsList({
|
||||
token: data.access_token,
|
||||
})
|
||||
if (re.code != 200) {
|
||||
if (re.code != 401) checkApiSuccessOrSncakbar(re, "获取收藏对话列表失败")
|
||||
if (re.code != 401 && re.code != 400) checkApiSuccessOrSncakbar(re, "获取收藏对话列表失败")
|
||||
return
|
||||
}
|
||||
const ls = re.data!.contacts_list as Chat[]
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function RecentsList({
|
||||
token: data.access_token,
|
||||
})
|
||||
if (re.code != 200) {
|
||||
if (re.code != 401) checkApiSuccessOrSncakbar(re, "获取最近对话列表失败")
|
||||
if (re.code != 401 && re.code != 400) checkApiSuccessOrSncakbar(re, "获取最近对话列表失败")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ interface SnackbarOptions extends Options {
|
||||
export function checkApiSuccessOrSncakbar(re: ApiCallbackMessage, msg_ahead: string, opinions_override: Options = {}): Snackbar | null {
|
||||
return re.code != 200 ? snackbar(
|
||||
Object.assign({
|
||||
message: `${msg_ahead}: ${re.msg.indexOf("Failed to fetch") != -1
|
||||
message: `${msg_ahead}: ${re.msg.indexOf("fetch") != -1
|
||||
? "HTTP 请求失败"
|
||||
: re.msg
|
||||
} [${re.code}]`,
|
||||
|
||||
Reference in New Issue
Block a user