Skip to content

Commit c425752

Browse files
authored
fix: pictique messages vanishing (#383)
1 parent 9e1ca1b commit c425752

File tree

3 files changed

+857
-381
lines changed

3 files changed

+857
-381
lines changed

platforms/pictique-api/src/services/MessageService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export class MessageService {
77
private chatRepository = AppDataSource.getRepository(Chat);
88

99
async findById(id: string): Promise<Message | null> {
10-
return await this.messageRepository.findOneBy({ id });
10+
return await this.messageRepository.findOne({
11+
where: { id },
12+
relations: ["chat", "sender"]
13+
});
1114
}
1215

1316
async createMessage(senderId: string | null, chatId: string, text: string, isSystemMessage: boolean = false): Promise<Message> {

platforms/pictique-api/src/web3adapter/watchers/subscriber.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ export class PostgresSubscriber implements EntitySubscriberInterface {
8484
enrichedEntity.author = author;
8585
}
8686

87+
// For messages, enrich sender and chat relations
88+
if (entity.sender && entity.sender.id) {
89+
const sender = await AppDataSource.getRepository(
90+
"User"
91+
).findOne({ where: { id: entity.sender.id } });
92+
enrichedEntity.sender = sender;
93+
}
94+
95+
if (entity.chat && entity.chat.id) {
96+
const chat = await AppDataSource.getRepository(
97+
"Chat"
98+
).findOne({
99+
where: { id: entity.chat.id },
100+
relations: ["participants", "messages"]
101+
});
102+
enrichedEntity.chat = chat;
103+
}
104+
87105
return this.entityToPlain(enrichedEntity);
88106
} catch (error) {
89107
console.error("Error loading relations:", error);

0 commit comments

Comments
 (0)