11import type { Loaded , OrderDefinition , Populate } from '@mikro-orm/postgresql' ;
22import type { Board } from '@/entities/board' ;
33import type { BoardCard } from '@/entities/board-card' ;
4- import type { BoardMember } from '@/entities/board-member' ;
54import { Comment } from '@/entities/comment' ;
65import type { User } from '@/entities/user' ;
76import { AgentService } from '@/services/agent.service' ;
@@ -16,16 +15,23 @@ export class CommentService {
1615 {
1716 board,
1817 user,
19- text,
18+ contentHtml,
19+ contentText,
2020 userTimeZone,
21- } : { board : Loaded < Board > ; user : Loaded < User , 'boardMembers' > ; text : string ; userTimeZone ?: string } ,
21+ } : {
22+ board : Loaded < Board > ;
23+ user : Loaded < User , 'boardMembers' > ;
24+ contentHtml : string ;
25+ contentText : string ;
26+ userTimeZone ?: string ;
27+ } ,
2228 ) {
23- const comment = new Comment ( { boardCard, user, text } ) ;
29+ const comment = new Comment ( { boardCard, user, contentHtml , contentText } ) ;
2430 const boardMember = user . boardMembers . find ( ( bm ) => bm . board . id === board . id ) ! ;
2531
2632 if ( ! boardCard . assignedBoardMember ) boardCard . assignToBoardMember ( boardMember ) ;
2733 boardCard . addParticipantUserId ( user . id ) ;
28- boardCard . setSnippet ( `${ user . firstName } : ${ text } ` ) ;
34+ boardCard . setSnippet ( `${ user . firstName } : ${ contentText } ` ) ;
2935 boardCard . setLastEventAt ( comment . createdAt ) ;
3036
3137 const userBoardCardReadPosition = boardCard . boardCardReadPositions . find ( ( pos ) => pos . user . id === user . id ) ! ;
@@ -35,16 +41,23 @@ export class CommentService {
3541
3642 await orm . em . flush ( ) ;
3743
38- if ( isBordlyComment ( text ) ) {
44+ if ( isBordlyComment ( contentText ) ) {
3945 const userBoardMember = await BoardMemberService . findById ( board , {
4046 boardMemberId : boardMember . id ,
4147 populate : [ 'user' , 'memory' ] ,
4248 } ) ;
43- const prompt = CommentService . bordlyPrompt ( text ) ;
44- await AgentService . runBordlyAgent ( { board, boardCardId : boardCard . id , prompt, userBoardMember, userTimeZone } ) ;
49+ const prompt = CommentService . bordlyPrompt ( contentText ) ;
50+ const updatedBoardCard = await AgentService . runBordlyAgent ( {
51+ board,
52+ boardCard,
53+ prompt,
54+ userBoardMember,
55+ userTimeZone,
56+ } ) ;
57+ return { boardCard : updatedBoardCard , comment } ;
4558 }
4659
47- return comment ;
60+ return { boardCard , comment } ;
4861 }
4962
5063 static async edit < Hint extends string = never > (
@@ -53,14 +66,16 @@ export class CommentService {
5366 board,
5467 user,
5568 commentId,
56- text,
69+ contentHtml,
70+ contentText,
5771 userTimeZone,
5872 populate,
5973 } : {
6074 board : Loaded < Board > ;
6175 user : Loaded < User , 'boardMembers' > ;
6276 commentId : string ;
63- text : string ;
77+ contentHtml : string ;
78+ contentText : string ;
6479 userTimeZone ?: string ;
6580 populate ?: Populate < Comment , Hint > ;
6681 } ,
@@ -69,26 +84,33 @@ export class CommentService {
6984 const boardMember = user . boardMembers . find ( ( bm ) => bm . board . id === board . id ) ! ;
7085 const wasLastBoardCardEvent = comment . createdAt . getTime ( ) === boardCard . lastEventAt . getTime ( ) ;
7186
72- comment . update ( { text } ) ;
87+ comment . update ( { contentHtml , contentText } ) ;
7388 orm . em . persist ( comment ) ;
7489 if ( wasLastBoardCardEvent ) {
75- boardCard . setSnippet ( `${ comment . user . firstName } : ${ text } ` ) ;
90+ boardCard . setSnippet ( `${ comment . user . firstName } : ${ contentText } ` ) ;
7691 orm . em . persist ( boardCard ) ;
7792 }
7893
7994 await orm . em . flush ( ) ;
8095
81- if ( isBordlyComment ( text ) ) {
96+ if ( isBordlyComment ( contentText ) ) {
8297 const userBoardMember = await BoardMemberService . findById ( board , {
8398 boardMemberId : boardMember . id ,
8499 populate : [ 'user' , 'memory' ] ,
85100 } ) ;
86101
87- const prompt = CommentService . bordlyPrompt ( text ) ;
88- await AgentService . runBordlyAgent ( { board, boardCardId : boardCard . id , prompt, userBoardMember, userTimeZone } ) ;
102+ const prompt = CommentService . bordlyPrompt ( contentText ) ;
103+ const updatedBoardCard = await AgentService . runBordlyAgent ( {
104+ board,
105+ boardCard,
106+ prompt,
107+ userBoardMember,
108+ userTimeZone,
109+ } ) ;
110+ return { boardCard : updatedBoardCard , comment } ;
89111 }
90112
91- return comment ;
113+ return { boardCard , comment } ;
92114 }
93115
94116 static async delete ( boardCard : BoardCard , { commentId } : { commentId : string } ) {
@@ -115,14 +137,14 @@ export class CommentService {
115137
116138 if ( lastComment && lastEmailMessage ) {
117139 if ( lastComment . createdAt . getTime ( ) > lastEmailMessage . externalCreatedAt . getTime ( ) ) {
118- boardCard . setSnippet ( `${ lastComment . user . firstName } : ${ lastComment . text } ` ) ;
140+ boardCard . setSnippet ( `${ lastComment . user . firstName } : ${ lastComment . contentText } ` ) ;
119141 boardCard . setLastEventAt ( lastComment . createdAt ) ;
120142 } else {
121143 boardCard . setSnippet ( lastEmailMessage . snippet ) ;
122144 boardCard . setLastEventAt ( lastEmailMessage . externalCreatedAt ) ;
123145 }
124146 } else if ( lastComment ) {
125- boardCard . setSnippet ( `${ lastComment . user . firstName } : ${ lastComment . text } ` ) ;
147+ boardCard . setSnippet ( `${ lastComment . user . firstName } : ${ lastComment . contentText } ` ) ;
126148 boardCard . setLastEventAt ( lastComment . createdAt ) ;
127149 } else if ( lastEmailMessage ) {
128150 boardCard . setSnippet ( lastEmailMessage . snippet ) ;
0 commit comments