diff --git a/package-lock.json b/package-lock.json index 924f0ecd..efd222cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -180,9 +180,9 @@ } }, "node_modules/@types/express-serve-static-core": { - "version": "4.19.3", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.3.tgz", - "integrity": "sha512-KOzM7MhcBFlmnlr/fzISFF5vGWVSvN6fTd4T+ExOt08bA/dA5kpSzY52nMsI1KDFmUREpJelPYyuslLRSjjgCg==", + "version": "4.19.5", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.5.tgz", + "integrity": "sha512-y6W03tvrACO72aijJ5uF02FRq5cgDR9lUxddQ8vyF+GvmjJQqbzDcJngEjURc+ZsG31VI3hODNZJ2URj86pzmg==", "dev": true, "dependencies": { "@types/node": "*", @@ -213,9 +213,9 @@ } }, "node_modules/@types/node": { - "version": "20.14.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.1.tgz", - "integrity": "sha512-T2MzSGEu+ysB/FkWfqmhV3PLyQlowdptmmgD20C6QxsS8Fmv5SjpZ1ayXaEC0S21/h5UJ9iA6W/5vSNU5l00OA==", + "version": "20.14.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.7.tgz", + "integrity": "sha512-uTr2m2IbJJucF3KUxgnGOZvYbN0QgkGyWxG6973HCpMYFy2KfcgYuIwkJQMQkt1VbBMlvWRbpshFTLxnxCZjKQ==", "dependencies": { "undici-types": "~5.26.4" } @@ -272,9 +272,9 @@ } }, "node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -284,10 +284,13 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", "dev": true, + "dependencies": { + "acorn": "^8.11.0" + }, "engines": { "node": ">=0.4.0" } @@ -979,9 +982,9 @@ } }, "node_modules/engine.io": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz", - "integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==", + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.5.tgz", + "integrity": "sha512-C5Pn8Wk+1vKBoHghJODM63yk8MvrO9EWZUfkAt5HAqIgPE4/8FF0PEGHXtEd40l223+cE5ABWuPzm38PHFXfMA==", "dependencies": { "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", @@ -992,7 +995,7 @@ "cors": "~2.8.5", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0" + "ws": "~8.17.1" }, "engines": { "node": ">=10.2.0" @@ -1865,9 +1868,9 @@ } }, "node_modules/node-abi": { - "version": "3.63.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.63.0.tgz", - "integrity": "sha512-vAszCsOUrUxjGAmdnM/pq7gUgie0IRteCQMX6d4A534fQCR93EJU5qgzBvU6EkFfK27s0T3HEV3BOyJIr7OMYw==", + "version": "3.65.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.65.0.tgz", + "integrity": "sha512-ThjYBfoDNr08AWx6hGaRbfPwxKV9kVzAzOzlLKbk2CuqXE2xnCh+cbAGnwM3t8Lq4v9rUB7VfondlkBckcJrVA==", "dependencies": { "semver": "^7.3.5" }, @@ -2432,12 +2435,12 @@ } }, "node_modules/socket.io-adapter": { - "version": "2.5.4", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz", - "integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", + "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", "dependencies": { "debug": "~4.3.4", - "ws": "~8.11.0" + "ws": "~8.17.1" } }, "node_modules/socket.io-adapter/node_modules/debug": { @@ -2829,9 +2832,9 @@ "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -2842,9 +2845,9 @@ } }, "node_modules/undici": { - "version": "6.18.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.18.2.tgz", - "integrity": "sha512-o/MQLTwRm9IVhOqhZ0NQ9oXax1ygPjw6Vs+Vq/4QRjbOAC3B1GCHy7TYxxbExKlb7bzDRzt9vBWU6BDz0RFfYg==", + "version": "6.19.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.2.tgz", + "integrity": "sha512-JfjKqIauur3Q6biAtHJ564e3bWa8VvT+7cSiOJHFbX4Erv6CLGDpg8z+Fmg/1OI/47RA+GI2QZaF48SSaLvyBA==", "engines": { "node": ">=18.17" } @@ -2945,15 +2948,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "utf-8-validate": ">=5.0.2" }, "peerDependenciesMeta": { "bufferutil": { diff --git a/src/actionHandler/Message/fetchHistory.ts b/src/actionHandler/Message/fetchHistory.ts index 2fc38973..6370e690 100644 --- a/src/actionHandler/Message/fetchHistory.ts +++ b/src/actionHandler/Message/fetchHistory.ts @@ -6,7 +6,8 @@ import { IMessage, IMessageBeforeParsing } from "../../type/Message"; export default async function fetchHistory( channelId: string, fetchingPosition: { - positionMessageId: string + positionMessageId?: string + positionMessageTime?: string includeThisPosition: boolean, fetchDirection: "older"|"newer" } @@ -25,9 +26,23 @@ export default async function fetchHistory( let positionIndex:number = 0; //メッセージ位置の設定、指定がないなら0 - if (fetchingPosition.positionMessageId !== "") { + if ( + ( //Idの指定があるか? + fetchingPosition.positionMessageId !== "" && fetchingPosition.positionMessageId !== undefined + ) + || + ( //または時間の指定があるか? + fetchingPosition.positionMessageTime !== "" && fetchingPosition.positionMessageTime !== undefined + ) + ) { //メッセージのインデックス番号を計算する - const positionTemp = await calcPositionOfMessage(channelId, fetchingPosition.positionMessageId); + const positionTemp = await calcPositionOfMessage( + channelId, + { + messageId: fetchingPosition.positionMessageId, + time: fetchingPosition.positionMessageTime + } + ); //結果に応じて値設定 if (positionTemp === null) { @@ -57,7 +72,7 @@ export default async function fetchHistory( `, (err:Error, length:[{"COUNT(*)":number}]) => { if (err) { - console.log("fetchHistory :: db(historyLength) : エラー->", err); + console.log("fetchHistory :: db(履歴の長さ取得) : エラー->", err); resolve(null); return; } else { @@ -97,7 +112,7 @@ export default async function fetchHistory( `, (err:Error, history:IMessageBeforeParsing[]) => { if (err) { - console.log("fetchHistory :: db : エラー->", err); + console.log("fetchHistory :: db(履歴取得) : エラー->", err); resolve(null); return; } else { @@ -171,11 +186,33 @@ export default async function fetchHistory( } //メッセージの位置を取得 -async function calcPositionOfMessage(channelId:string, messageId:string) -:Promise { +async function calcPositionOfMessage( + channelId:string, + messagePos: { + messageId?: string, + time?: string + } +):Promise { return await new Promise((resolve) => { try { + //位置計算に使うメッセージ情報 + let calcMode:"messageId"|"time" = "messageId"; + //引数に時間があるかで使う情報切り替え + if (messagePos.time !== undefined) { + calcMode = "time"; + } + + //console.log("fetchHistory :: calcPositionOfMessage : calcMode->", calcMode); + + //検索に使うSQL構文を選択(時間かメッセIdか) + const searchQuery = calcMode==="messageId" + ? + "messageId = '" + messagePos.messageId + "'" + : + "time = '" + messagePos.time + "'" + + //該当メッセージの位置取得 db.all( ` WITH NumberedRows AS ( @@ -190,11 +227,11 @@ async function calcPositionOfMessage(channelId:string, messageId:string) FROM NumberedRows WHERE - messageId = '` + messageId + `'; + ${searchQuery}; `, (err:Error, messageWithIndex:any) => { if (err) { - console.log("fetchHistory :: db : エラー->", err); + console.log("fetchHistory :: db(メッセ位置計算) : エラー->", err); resolve(null); return; } else { diff --git a/src/actionHandler/Message/getMessageReadId.ts b/src/actionHandler/Message/getMessageReadId.ts deleted file mode 100644 index ab8476ac..00000000 --- a/src/actionHandler/Message/getMessageReadId.ts +++ /dev/null @@ -1,42 +0,0 @@ -import sqlite3 from "sqlite3"; -import type { IMessageReadId } from "../../type/Message"; -const db = new sqlite3.Database("./records/USER.db"); - -//メッセージの最終既読IdをJSONで取得 -export default async function getMessageReadId(userId:string) -:Promise { - try { - - return new Promise((resolve) => { - db.all( - ` - SELECT messageReadId FROM USERS_SAVES - WHERE userId='` + userId + `' - `, - (err:Error, messageReadIdBeforeParsed:[{messageReadId:any}]) => { - if (err) { - console.log("getMessageReadId :: db : エラー->", err); - resolve(null); - return; - } else { - //console.log("getMessageReadId :: db : data->", messageReadIdBeforeParsed); - //パースして返す - const messageReadId:IMessageReadId = - JSON.parse( - messageReadIdBeforeParsed[0]['messageReadId'] - ); - - resolve(messageReadId); - return; - } - } - ); - }); - - } catch(e) { - - console.log("getMessageReadId :: エラー->", e); - return null; - - } -} diff --git a/src/actionHandler/Message/getMessageReadTime.ts b/src/actionHandler/Message/getMessageReadTime.ts new file mode 100644 index 00000000..d0ca15ba --- /dev/null +++ b/src/actionHandler/Message/getMessageReadTime.ts @@ -0,0 +1,42 @@ +import sqlite3 from "sqlite3"; +import type { IMessageReadTime } from "../../type/Message"; +const db = new sqlite3.Database("./records/USER.db"); + +//メッセージの最終既読時間をJSONで取得 +export default async function getMessageReadTime(userId:string) +:Promise { + try { + + return new Promise((resolve) => { + db.all( + ` + SELECT messageReadTime FROM USERS_SAVES + WHERE userId='` + userId + `' + `, + (err:Error, messageReadTimeBeforeParsed:[{messageReadTime:string}]) => { + if (err) { + console.log("getMessageReadTime :: db : エラー->", err); + resolve(null); + return; + } else { + //console.log("getMessageReadTime :: db : data->", messageReadTimeBeforeParsed); + //パースして返す + const messageReadTime:IMessageReadTime = + JSON.parse( + messageReadTimeBeforeParsed[0]['messageReadTime'] + ); + + resolve(messageReadTime); + return; + } + } + ); + }); + + } catch(e) { + + console.log("getMessageReadTime :: エラー->", e); + return null; + + } +} diff --git a/src/actionHandler/Message/setMessageReadId.ts b/src/actionHandler/Message/setMessageReadId.ts deleted file mode 100644 index d00a24dd..00000000 --- a/src/actionHandler/Message/setMessageReadId.ts +++ /dev/null @@ -1,51 +0,0 @@ -import sqlite3 from "sqlite3"; -import type { IMessageReadId } from "../../type/Message"; -const db = new sqlite3.Database("./records/USER.db"); - -import getMessageReadId from "./getMessageReadId"; - -export default async function setMessageReadId( - userId: string, - channelId: string, - messageId: string -):Promise { - try { - - //メッセージ既読Idの読み取り - const messageReadId:IMessageReadId|null = await getMessageReadId(userId); - //取得できなかったら失敗と返す - if (messageReadId===null) return false; - - //データを更新する - messageReadId[channelId] = messageId; - - //DBへの書き込み処理 - return new Promise((resolve) => { - db.run( - ` - UPDATE USERS_SAVES SET - messageReadId=? - WHERE userId='` + userId + `' - `, - JSON.stringify(messageReadId), - (err:Error) => { - if (err) { - console.log("setMessageReadId :: db : エラー->", err); - resolve(false); - return; - } else { - //console.log("setMessageReadId :: db : 成功 messageReadTime->", messageReadId); - resolve(true); - return; - } - } - ); - }); - - } catch(e) { - - console.log("setMessageReadId :: エラー->", e); - return false; - - } -} diff --git a/src/actionHandler/Message/setMessageReadTime.ts b/src/actionHandler/Message/setMessageReadTime.ts new file mode 100644 index 00000000..abe72fb6 --- /dev/null +++ b/src/actionHandler/Message/setMessageReadTime.ts @@ -0,0 +1,51 @@ +import sqlite3 from "sqlite3"; +import type { IMessageReadTime } from "../../type/Message"; +const db = new sqlite3.Database("./records/USER.db"); + +import getMessageReadTime from "./getMessageReadTime"; + +export default async function setMessageReadTime( + userId: string, + channelId: string, + messageTime: string +):Promise { + try { + + //メッセージ既読時間の読み取り + const messageReadTime:IMessageReadTime|null = await getMessageReadTime(userId); + //取得できなかったら失敗と返す + if (messageReadTime===null) return false; + + //データを更新する + messageReadTime[channelId] = messageTime; + + //DBへの書き込み処理 + return new Promise((resolve) => { + db.run( + ` + UPDATE USERS_SAVES SET + messageReadTime=? + WHERE userId='` + userId + `' + `, + JSON.stringify(messageReadTime), + (err:Error) => { + if (err) { + console.log("setMessageReadTime :: db : エラー->", err); + resolve(false); + return; + } else { + //console.log("setMessageReadTime :: db : 成功 messageReadTime->", messageReadTime); + resolve(true); + return; + } + } + ); + }); + + } catch(e) { + + console.log("setMessageReadTime :: エラー->", e); + return false; + + } +} diff --git a/src/db/InitUser.ts b/src/db/InitUser.ts index 36b88938..24ef4ee7 100644 --- a/src/db/InitUser.ts +++ b/src/db/InitUser.ts @@ -2,10 +2,12 @@ import sqlite3 from "sqlite3"; const db = new sqlite3.Database("./records/USER.db"); import migration20240612 from "./migration/User/20240612"; +import migration20240618 from "./migration/User/20240618"; db.serialize(() => { //migration migration20240612(); //inboxカラム追加 + migration20240618(); //messageReadIdからmessageReadTimeへ //ユーザー基本情報を保存するUSERS_INFOテーブルを無ければ作成 db.run(`create table if not exists USERS_INFO( diff --git a/src/db/migration/User/20240618.ts b/src/db/migration/User/20240618.ts new file mode 100644 index 00000000..9763586c --- /dev/null +++ b/src/db/migration/User/20240618.ts @@ -0,0 +1,74 @@ +import sqlite3 from "sqlite3"; +const db = new sqlite3.Database("./records/USER.db"); + +/** + * USERS_SAVEのmessageReadIdをmessageReadTimeへ名前変更 + */ +export default async function migration20240618() { + db.serialize(() => { + //messageReadTimeカラムがあるか調べてこの処理を続けるか判別して止める + db.all( + ` + PRAGMA table_info(USERS_SAVES) + `, + (err:Error, tableInfo:{cid:number, name:string}[]) => { + if (err) { + console.log("err->", err); + } else { + //console.log("migration(20240618) :: tableInfo->", tableInfo); + for (let column of tableInfo) { + //もしmessageReadTimeがカラムがすでにあるなら処理をここで止める + if (column.name === "messageReadTime") { + return; + } + } + } + } + ); + + //新しくテーブルを作成するため古いテーブルの名前を変更(USERS_SAVES -> USERS_SAVES_TEMP) + db.all( + ` + ALTER TABLE USERS_SAVES RENAME TO USERS_SAVES_TEMP + `, + (err:Error, tables:[{name:string}]) => { + if (err) { + console.log("migration(20240618) :: エラー!->", err); + } + return; + } + ); + + //新しくUSERS_SAVEを作る + db.run(`CREATE TABLE USERS_SAVES( + userId TEXT PRIMARY KEY, + messageReadTime TEXT DEFAULT '{}', + channelOrder TEXT DEFAULT '{}', + inbox TEXT DEFAULT '{ "mention": {}, "event": {} }', + FOREIGN KEY(userId) REFERENCES USERS_INFO(userId) + )`); + + //USERS_SAVES_TEMPから今作ったUSERS_SAVESへコピー + db.run( + ` + INSERT INTO USERS_SAVES(userId, channelOrder, inbox) + SELECT userId, ChannelOrder, inbox FROM USERS_SAVES_TEMP + ` + ) + + //古いUSERS_SAVESテーブル削除 + db.all( + ` + DROP TABLE USERS_SAVES_TEMP + `, + (err:Error, tables:[{name:string}]) => { + if (err) { + console.log("migration(20240618) :: エラー!->", err); + } + return; + } + ); + + db.close(); + }); +} diff --git a/src/socketHandler/Message.ts b/src/socketHandler/Message.ts index c7893e42..27b2cf78 100644 --- a/src/socketHandler/Message.ts +++ b/src/socketHandler/Message.ts @@ -4,13 +4,13 @@ import saveMessage from "../actionHandler/Message/saveMessage"; import fetchHistory from "../actionHandler/Message/fetchHistory"; import reactMessage from "../actionHandler/Message/reactMessage"; import fetchMessage from "../actionHandler/Message/fetchMessage"; -import setMessageReadTime from "../actionHandler/Message/setMessageReadId"; -import getMessageReadId from "../actionHandler/Message/getMessageReadId"; +import setMessageReadTime from "../actionHandler/Message/setMessageReadTime"; +import getMessageReadTime from "../actionHandler/Message/getMessageReadTime"; import deleteMessage from "../actionHandler/Message/deleteMessage"; import genLinkPreview from "../util/genLinkPreview"; import type IRequestSender from "../type/requestSender"; -import type { IMessage, IMessageReadId } from "../type/Message"; +import type { IMessage, IMessageReadTime } from "../type/Message"; module.exports = (io:Server) => { io.on("connection", (socket:Socket) => { @@ -152,7 +152,8 @@ module.exports = (io:Server) => { RequestSender: IRequestSender, channelId: string, fetchingPosition: { - positionMessageId: string, + positionMessageId?: string, + positionMessageTime?: string, includeThisPosition: boolean, fetchDirection: "older"|"newer", } @@ -178,6 +179,7 @@ module.exports = (io:Server) => { atTop: boolean, atEnd: boolean }|null = await fetchHistory(dat.channelId, dat.fetchingPosition); + //データを送信 socket.emit( "RESULT::fetchHistory", @@ -241,64 +243,70 @@ module.exports = (io:Server) => { } }); - //メッセージの最終既読メッセIDを保存する - socket.on("setMessageReadId", async ( + //メッセージの最終既読メッセ時間を保存する + socket.on("setMessageReadTime", async ( dat: { RequestSender: IRequestSender, channelId: string, - messageId: string + messageTime: string }) => { //セッション認証 if (!(await checkSession(dat.RequestSender))) { - socket.emit("RESULT::setMessageReadId", { result:"ERROR_SESSION_ERROR", data:null }); + socket.emit("RESULT::setMessageReadTime", { result:"ERROR_SESSION_ERROR", data:null }); return; } try { - //最新既読Id書き込み - const setMessageReadIdResult:boolean = await setMessageReadTime( + //もし時間の値がDate型に使えないならエラーとして返す + if (isNaN(new Date(dat.messageTime).valueOf())) { + socket.emit("RESULT::setMessageReadTime", { result:"ERROR_TIME_CANNOT_VALIDATE", data:null }); + return; + } + + //最新既読時間書き込み + const setMessageReadTimeResult:boolean = await setMessageReadTime( dat.RequestSender.userId, dat.channelId, - dat.messageId + dat.messageTime ); //結果に応じてboolを送信 - if (setMessageReadIdResult) { - socket.emit("RESULT::setMessageReadId", { result:"SUCCESS", data:true}); + if (setMessageReadTimeResult) { + socket.emit("RESULT::setMessageReadTime", { result:"SUCCESS", data:true}); } else { - socket.emit("RESULT::setMessageReadId", { result:"ERROR_DB_THING", data:false}); + socket.emit("RESULT::setMessageReadTime", { result:"ERROR_DB_THING", data:false}); } } catch(e) { - console.log("Message :: socket(setMessageReadId) : エラー->", e); - socket.emit("RESULT::setMessageReadId", { result:"ERROR_DB_thing", data:null }); + console.log("Message :: socket(setMessageReadTime) : エラー->", e); + socket.emit("RESULT::setMessageReadTime", { result:"ERROR_DB_thing", data:null }); } }); - //チャンネルの既読状態を取得 - socket.on("getMessageReadId", async ( + //チャンネルの既読時間を取得 + socket.on("getMessageReadTime", async ( dat: { RequestSender: IRequestSender } ) => { //セッション認証 if (!(await checkSession(dat.RequestSender))) { - socket.emit("RESULT::getMessageReadId", { result:"ERROR_SESSION_ERROR", data:null }); + socket.emit("RESULT::getMessageReadTime", { result:"ERROR_SESSION_ERROR", data:null }); return; } try { //既読状態取得 - const getMessageReadIdResult:IMessageReadId|null = await getMessageReadId(dat.RequestSender.userId); + const getMessageReadTimeResult:IMessageReadTime|null = await getMessageReadTime(dat.RequestSender.userId); //nullじゃないならデータを送信 - if (getMessageReadIdResult !== null) { - socket.emit("RESULT::getMessageReadId", { result:"SUCCESS", data:getMessageReadIdResult }); + if (getMessageReadTimeResult !== null) { + socket.emit("RESULT::getMessageReadTime", { result:"SUCCESS", data:getMessageReadTimeResult }); } else { - socket.emit("RESULT::getMessageReadId", { result:"ERROR_DB_THING", data:null }); + socket.emit("RESULT::getMessageReadTime", { result:"ERROR_DB_THING", data:null }); } } catch(e) { - socket.emit("RESULT::getMessageReadId", { result:"ERROR_DB_THING", data:null }); - console.log("Message :: socket(getMessageReadId) : エラー->", e); + socket.emit("RESULT::getMessageReadTime", { result:"ERROR_DB_THING", data:null }); + console.log("Message :: socket(getMessageReadTime) : エラー->", e); } }); diff --git a/src/type/Message.ts b/src/type/Message.ts index 6be40eaf..02e94218 100644 --- a/src/type/Message.ts +++ b/src/type/Message.ts @@ -42,7 +42,8 @@ export interface IMessage { } } -//最終既読メッセージのId -export interface IMessageReadId { +//最終既読メッセージの時間 +export interface IMessageReadTime { [key: string]: string } +