Skip to content

Commit

Permalink
Fixed the new chat bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mleandrojr committed Apr 19, 2024
1 parent 47aca9d commit 9940961
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/action/SaveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ export default class SaveMessage extends Action {
*/
private async saveNewMessage(user: Record<string, any>, chat: Record<string, any>): Promise<void> {


console.log(chat);
const message = new Messages();
const insert = message.insert();

insert
.set("type", this.context.type)
.set("user_id", user.id)
Expand Down
5 changes: 2 additions & 3 deletions src/action/SaveUserAndChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ export default class SaveUserAndChat extends Action {

const contextUser = this.context.newChatMember || this.context.leftChatMember || this.context.user;
const user = await UserHelper.getByTelegramId(contextUser.getId());
const userId = user === null ? await UserHelper.createUser(contextUser) : user.id;
const userId = user?.id ?? await UserHelper.createUser(contextUser);

const chat = await ChatHelper.getByTelegramId(this.context.chat.getId());
const chatId = chat === null ? await ChatHelper.createChat(this.context.chat) : chat!.id;
const chatId = chat?.id ?? await ChatHelper.createChat(this.context.chat);

console.log("Chat:", chat, "ChatId:", chatId);
UserHelper.updateUser(contextUser);
ChatHelper.updateChat(this.context.chat);

Expand Down
1 change: 0 additions & 1 deletion src/command/Macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default class Macro extends Command {

const content = result[0].content;
const replyToMessage = this.context.message.getReplyToMessage();
console.log(replyToMessage);

if (replyToMessage) {
replyToMessage.reply(content, { parseMode : "HTML" });
Expand Down
24 changes: 16 additions & 8 deletions src/helper/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import Chats from "../model/Chats.js";
import ChatConfigs from "../model/ChatConfigs.js";
import Log from "./Log.js";

export default class ChatHelper {

Expand Down Expand Up @@ -102,7 +103,6 @@ export default class ChatHelper {
*/
public static async createChat(chat: Record<string, any>): Promise<any> {

console.log("Abc");
const title = chat.getTitle() || chat.getUsername() || (`${chat.getFirstName()} ${chat.getLastName()}`).trim();
const newChat = new Chats();
newChat
Expand All @@ -112,15 +112,23 @@ export default class ChatHelper {
.set("type", chat.getType())
.set("joined", 1);

const result = await newChat.execute();
const chatId = result.insertId;
try {

const newChatConfig = new ChatConfigs();
newChatConfig
.insert()
.set("chat_id", chatId);
const result = await newChat.execute();
const chatId = result.insertId;

const newChatConfig = new ChatConfigs();
newChatConfig
.insert()
.set("chat_id", chatId);

newChatConfig.execute();
await newChatConfig.execute();
return chatId;

} catch (err) {
Log.error(err);
return null;
}
}

/**
Expand Down

0 comments on commit 9940961

Please sign in to comment.