Skip to content

Commit

Permalink
[change] - メンションするユーザーIdの重複を無くすように (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
NfoAlex committed Aug 5, 2024
1 parent e3e8dcc commit a66addb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/actionHandler/Message/saveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ async function checkAndAddToInbox(
//マッチ結果
const matchResult:RegExpMatchArray|null = content.match(MentionRegex);
//実際に通知をするユーザーId配列
const userIdMentioning:string[] = [];
//const userIdMentioning:string[] = [];
const userIdMentioning:string[] = Array.from(new Set(matchResult));
//処理を終えて"@<>"を取り除いたユーザーId配列
const userIdMentioningProcessed:string[] = [];

console.log("saveMessage :: checkAndAddToInbox : マッチ結果->", matchResult, " フィルター結果->", userIdMentioning);

//そもそもマッチが無いなら停止
if (matchResult === null) return null;
Expand All @@ -160,7 +165,7 @@ async function checkAndAddToInbox(
const dbUser = new sqlite3.Database("./records/USER.db");

//ユーザーがメンションされているなら対象の人のInboxに通知を追加
for (const targetUserId of matchResult) {
for (const targetUserId of userIdMentioning) {
try {

//メンションクエリーから@<>を削除してユーザーIdを抽出
Expand Down Expand Up @@ -192,14 +197,14 @@ async function checkAndAddToInbox(
);

//実際に通知を行うユーザーId配列へ追加
userIdMentioning.push(userIdFormatted);
userIdMentioningProcessed.push(userIdFormatted);

} catch(e) {
console.log("savemessage :: checkAndAddToInbox : エラー->", e);
return null;
}
}

//メンションするユーザーId配列を返す
return userIdMentioning;
//処理を終えてメンションするユーザーId配列を返す
return userIdMentioningProcessed;
}

0 comments on commit a66addb

Please sign in to comment.