更新chat的ui界面

This commit is contained in:
539943419 committed 2024-04-02 23:18:54 +08:00
1 parent 530e54a596
commit 709cac04f6
6 files changed
+111 -60

No files matched your search

+9 -8
View File
@@ -377,6 +377,7 @@ function createGroupTableDB(gID, verify) {
`CREATE TABLE IF NOT EXISTS ${gID} (
message TEXT NOT NULL,
type TEXT NOT NULL,
type1 TEXT NOT NULL,
sender TEXT NOT NULL,
timestamp INT NOT NULL
);`
@@ -385,11 +386,11 @@ function createGroupTableDB(gID, verify) {
}
// 插入信息
function insertMessageByGID(gID, msg, from, timestamp) {
function insertMessageByGID(gID, msg,type1, from, timestamp) {
if (!generateStmt_insertMessage_map[gID]) {
generateStmt_insertMessage_map[gID] = db.prepare(`INSERT INTO ${gID} (message,type,sender, timestamp) VALUES (?, ?, ?, ?)`);
generateStmt_insertMessage_map[gID] = db.prepare(`INSERT INTO ${gID} (message,type,type1,sender, timestamp) VALUES (?, ?, ?, ?, ?)`);
}
generateStmt_insertMessage_map[gID].run(msg, "gMsg", from, timestamp);
generateStmt_insertMessage_map[gID].run(msg, "gMsg",type1, from, timestamp);
}
function updateActiveTimestamp(gID) {
@@ -423,14 +424,14 @@ function getHistory(gID) {
return groupsMap[gID].msgHistory;
}
function broadcastMsg(gID, msg, from) {
function broadcastMsg(gID, msg,type1, from) {
const timestamp = parseInt(Date.now());
initMsgHistory(gID);
updateActiveTimestamp(gID);
insertMessageByGID(gID, msg, from, timestamp);
insertMessageByGID(gID, msg,type1, from, timestamp);
let bmsg = JSON.stringify({ type: "gMsg", gID, msg, from, timestamp });
groupsMap[gID].msgHistory.push({ type: "gMsg", msg, from, timestamp });
let bmsg = JSON.stringify({ type: `gMsg`,type1, gID, msg, from, timestamp });
groupsMap[gID].msgHistory.push({ type: `gMsg`,type1, msg, from, timestamp });
for (let socket of groupsMap[gID].member) {
socket.send(bmsg);
}
@@ -490,7 +491,7 @@ wss.on("connection", socket => {
}
} else if (type === "message") {
let gID = msg.gID;
broadcastMsg(gID, msg.msg, uuid);
broadcastMsg(gID, msg.msg,msg.type1, uuid);
} else if (type === "heartbeat") {
socket.send(JSON.stringify({ type: "sMsg", type1: "heartbeat" }));
} else if (type === "uuid") {