Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 8, 2024
1 parent e89a5da commit e42603a
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,26 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent
throw new Error("Failed to fetch chat");
}

const chatFull = fetchChat.fullChat as Api.ChatFull
const participants = chatFull.participants as Api.ChatParticipants;
// const chatFull = fetchChat.fullChat as Api.ChatFull
// const participants = chatFull.participants as Api.ChatParticipants;

// for (const participant of participants.participants) {
// if (participant instanceof mtProto.api.ChatParticipant) {
// await mtProto.client.invoke(
// new mtProto.api.messages.DeleteChatUser({
// chatId: chat.chatId,
// userId: participant.userId,
// })
// );
// }
// }

for (const participant of participants.participants) {
if (participant instanceof mtProto.api.ChatParticipant) {
await mtProto.client.invoke(
new mtProto.api.messages.DeleteChatUser({
chatId: chat.chatId,
userId: participant.userId,
})
);
}
}
await mtProto.client.invoke(
new mtProto.api.messages.DeleteChatUser({
chatId: chat.chatId,
userId: bigInt(0),
})
);

await mtProto.client.invoke(
new mtProto.api.messages.SendMessage({
Expand All @@ -101,6 +108,8 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent
})
);

await chats.updateChatStatus("closed", payload.issue.node_id);

return { status: 200, reason: "chat_closed" };
} catch (er) {
context.logger.error("Failed to close chat", { er });
Expand All @@ -115,10 +124,34 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
const mtProto = new MtProto(context);
await mtProto.initialize();

context.logger.info("Reopening chat with name: ", { chatName: payload.issue.title });
const chat = await chats.getChatByTaskNodeId(payload.issue.node_id);

const fetchChat = await mtProto.client.invoke(
new mtProto.api.messages.GetFullChat({
chatId: chat.chatId,
})
);

if (!fetchChat) {
throw new Error("Failed to fetch chat");
}

const chatFull = fetchChat.fullChat as Api.ChatFull
const participants = chatFull.participants as Api.ChatParticipants;

for (const participant of participants.participants) {
if (participant instanceof mtProto.api.ChatParticipant) {
await mtProto.client.invoke(
new mtProto.api.messages.AddChatUser({
chatId: chat.chatId,
userId: participant.userId,
fwdLimit: 50,
})
);
}
}

/**
* TODO: Are we re-opening the old chat or creating a new one?
*/

return { status: 200, reason: "chat_reopened" };
} catch (er) {
Expand Down

0 comments on commit e42603a

Please sign in to comment.