Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: edit workroom desc, no error comment on chat_not_found #28

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bot/mtproto-api/workrooms/close-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent
const dbChat = await storage.retrieveChatByTaskNodeId(payload.issue.node_id);

if (!dbChat) {
return { status: 500, reason: "chat_not_found" };
logger.error("Chat not found in database", { chatName: payload.issue.title });
return { status: 200, reason: "chat_not_found" };
}

logger.info("Chat found: ", { dbChat });
Expand Down
33 changes: 23 additions & 10 deletions src/bot/mtproto-api/workrooms/create-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,31 @@ export async function createChat(context: Context<"issues.assigned", SupportedEv
} else {
throw new Error(logger.error(`Failed to create chat invite link for the workroom: ${chatName}`).logMessage.raw);
}
}

const isBotPromotedToAdmin = await mtProto.client.invoke(
new mtProto.api.messages.EditChatAdmin({
chatId: chatIdBigInt,
isAdmin: true,
userId: botIdString,
})
);
// edit chat description
try {
await mtProto.client.invoke(
new mtProto.api.messages.EditChatAbout({
peer: new mtProto.api.InputPeerChat({ chatId: chatIdBigInt }),
about: `${payload.issue.html_url}`,
})
);
} catch (er) {
logger.error("Error in editing chat description: ", { er });
return { status: 500, reason: "chat_create_failed", content: { error: er } };
}

if (!isBotPromotedToAdmin) {
throw new Error("Failed to promote bot to admin");
const isBotPromotedToAdmin = await mtProto.client.invoke(
new mtProto.api.messages.EditChatAdmin({
chatId: chatIdBigInt,
isAdmin: true,
userId: botIdString,
})
);

if (!isBotPromotedToAdmin) {
throw new Error("Failed to promote bot to admin");
}
}
} catch (er) {
logger.error("Error in creating chat: ", { er });
Expand Down
5 changes: 4 additions & 1 deletion src/bot/mtproto-api/workrooms/reopen-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export async function reopenChat(context: Context<"issues.reopened", SupportedEv
const dbChat = await storage.retrieveChatByTaskNodeId(payload.issue.node_id);

if (!dbChat) {
return { status: 500, reason: "chat_not_found" };
logger.error("Chat not found in database", { chatName: payload.issue.title });
// no need to create one if it doesn't exist, this really only affects backwards compatibility
return { status: 200, reason: "chat_not_found" };
}

const chatIdBigInt = bigInt(dbChat.chat_id);

const fetchedChat = await mtProto.client.invoke(
Expand Down
Loading