From e42603aea101fec57eed6ffb05eb20acb04aa9bd Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:43:43 +0100 Subject: [PATCH] chore: test --- src/bot/mtproto-api/workrooms.ts | 63 ++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/src/bot/mtproto-api/workrooms.ts b/src/bot/mtproto-api/workrooms.ts index 98235cd..2b1abf3 100644 --- a/src/bot/mtproto-api/workrooms.ts +++ b/src/bot/mtproto-api/workrooms.ts @@ -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({ @@ -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 }); @@ -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) {