fix: Chat 中的列命名错误
* avatar avatar_file_hash
This commit is contained in:
@@ -10,6 +10,8 @@ import User from "./User.ts"
|
|||||||
import ChatType from "./ChatType.ts"
|
import ChatType from "./ChatType.ts"
|
||||||
import UserChatLinker from "./UserChatLinker.ts"
|
import UserChatLinker from "./UserChatLinker.ts"
|
||||||
import DataWrongError from '../api/DataWrongError.ts'
|
import DataWrongError from '../api/DataWrongError.ts'
|
||||||
|
import { Buffer } from "node:buffer"
|
||||||
|
import FileManager from "./FileManager.ts"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chat.ts - Wrapper and manager
|
* Chat.ts - Wrapper and manager
|
||||||
@@ -26,7 +28,7 @@ export default class Chat {
|
|||||||
/* 类型 */ type TEXT NOT NULL,
|
/* 类型 */ type TEXT NOT NULL,
|
||||||
/* ID */ id TEXT NOT NULL,
|
/* ID */ id TEXT NOT NULL,
|
||||||
/* 标题 */ title TEXT,
|
/* 标题 */ title TEXT,
|
||||||
/* 头像 */ avatar BLOB,
|
/* 头像 */ avatar_file_hash BLOB,
|
||||||
/* 设置 */ settings TEXT NOT NULL
|
/* 设置 */ settings TEXT NOT NULL
|
||||||
);
|
);
|
||||||
`)
|
`)
|
||||||
@@ -56,7 +58,7 @@ export default class Chat {
|
|||||||
type,
|
type,
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
avatar,
|
avatar_file_hash,
|
||||||
settings
|
settings
|
||||||
) VALUES (?, ?, ?, ?, ?);`).run(
|
) VALUES (?, ?, ?, ?, ?);`).run(
|
||||||
type,
|
type,
|
||||||
@@ -95,8 +97,8 @@ export default class Chat {
|
|||||||
protected getJoinRequestsTableName() {
|
protected getJoinRequestsTableName() {
|
||||||
return 'join_requests_' + this.bean.id.replaceAll('-', '_')
|
return 'join_requests_' + this.bean.id.replaceAll('-', '_')
|
||||||
}
|
}
|
||||||
setAttr(key: string, value: SQLInputValue): void {
|
setAttr(key: string, value: SQLInputValue) {
|
||||||
Chat.database.prepare(`UPDATE Chat SET ${key} = ? WHERE id = ?`).run(value, this.bean.id)
|
Chat.database.prepare(`UPDATE Chat SET ${key} = ? WHERE count = ?`).run(value, this.bean.count)
|
||||||
this.bean[key] = value
|
this.bean[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +200,14 @@ export default class Chat {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
getId() {
|
||||||
|
return this.bean.id
|
||||||
|
}
|
||||||
|
setId(id: string) {
|
||||||
|
if (Chat.findAllChatBeansByCondition('id = ?', id).length > 0)
|
||||||
|
throw new DataWrongError(`对话ID ${id} 已被使用`)
|
||||||
|
this.setAttr("id", id)
|
||||||
|
}
|
||||||
setTitle(title: string) {
|
setTitle(title: string) {
|
||||||
if (this.bean.type == 'private')
|
if (this.bean.type == 'private')
|
||||||
throw new Error('不允许对私聊进行命名')
|
throw new Error('不允许对私聊进行命名')
|
||||||
@@ -211,4 +221,7 @@ export default class Chat {
|
|||||||
if (this.bean.type == 'group') return this.bean.avatar_file_hash
|
if (this.bean.type == 'group') return this.bean.avatar_file_hash
|
||||||
if (this.bean.type == 'private') return this.getAnotherUserForPrivate(userMySelf as User)?.getAvatarFileHash()
|
if (this.bean.type == 'private') return this.getAnotherUserForPrivate(userMySelf as User)?.getAvatarFileHash()
|
||||||
}
|
}
|
||||||
|
async setAvatar(avatar: Buffer) {
|
||||||
|
this.setAttr("avatar_file_hash", (await FileManager.uploadFile(`avatar_chat_${this.bean.count}`, avatar)).getHash())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import ChatType from "./ChatType.ts"
|
import ChatType from "./ChatType.ts"
|
||||||
|
|
||||||
export default class ChatBean {
|
export default class ChatBean {
|
||||||
|
declare count: number
|
||||||
declare type: ChatType
|
declare type: ChatType
|
||||||
declare id: string
|
declare id: string
|
||||||
declare title?: string
|
declare title?: string
|
||||||
|
|||||||
Reference in New Issue
Block a user