| 1 | // Package conversation stores private conversations and shared task discussion. |
| 2 | // Its operations use the caller's transaction and authority callbacks. |
| 3 | package conversation |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/equipo/conversation/chatstate" |
| 7 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | type Message struct { |
| 12 | SourceRefs []team.SourceRef |
| 13 | ID, ConversationID, ThreadID, AuthorKind, AuthorID, Body string |
| 14 | Sequence, Revision int64 |
| 15 | CreatedAt time.Time |
| 16 | } |
| 17 | type Card = chatstate.Card |
| 18 | |
| 19 | type ConversationPage struct { |
| 20 | Messages []Message |
| 21 | Cards []Card |
| 22 | NextCursor string |
| 23 | Revision int64 |
| 24 | } |
| 25 | |
| 26 | type Main struct { |
| 27 | ID string `gorm:"primaryKey"` |
| 28 | TeamID string `gorm:"uniqueIndex:conversation_person,priority:1"` |
| 29 | Person string `gorm:"uniqueIndex:conversation_person,priority:2"` |
| 30 | Revision, LastSequence int64 |
| 31 | } |
| 32 | |
| 33 | func (Main) TableName() string { return "conversations" } |
| 34 | |
| 35 | type Thread struct { |
| 36 | ID string `gorm:"primaryKey"` |
| 37 | TaskID string `gorm:"uniqueIndex:conversation_task"` |
| 38 | TeamID string |
| 39 | Revision, LastSequence int64 |
| 40 | } |
| 41 | |
| 42 | func (Thread) TableName() string { return "conversation_threads" } |
| 43 | |
| 44 | type messageRecord struct { |
| 45 | SourceRefs []team.SourceRef `gorm:"serializer:json"` |
| 46 | ID string `gorm:"primaryKey"` |
| 47 | StreamID string `gorm:"uniqueIndex:conversation_sequence,priority:1"` |
| 48 | Sequence int64 `gorm:"uniqueIndex:conversation_sequence,priority:2"` |
| 49 | ConversationID, ThreadID, AuthorKind, AuthorID, Body string |
| 50 | Revision int64 |
| 51 | CreatedAt time.Time |
| 52 | } |
| 53 | |
| 54 | func (messageRecord) TableName() string { return "conversation_messages" } |
| 55 | func (r messageRecord) message() Message { |
| 56 | return Message{SourceRefs: r.SourceRefs, ID: r.ID, ConversationID: r.ConversationID, ThreadID: r.ThreadID, AuthorKind: r.AuthorKind, AuthorID: r.AuthorID, Body: r.Body, Sequence: r.Sequence, Revision: r.Revision, CreatedAt: r.CreatedAt} |
| 57 | } |
| 58 | |
| 59 | type cardRecord struct { |
| 60 | ID string `gorm:"primaryKey"` |
| 61 | StreamID string `gorm:"index:conversation_card_stream"` |
| 62 | Kind, ResourceID string |
| 63 | Sequence, Revision int64 |
| 64 | } |
| 65 | |
| 66 | func (cardRecord) TableName() string { return "conversation_cards" } |
| 67 | |
| 68 | type requestRecord struct { |
| 69 | Principal string `gorm:"primaryKey"` |
| 70 | Operation string `gorm:"primaryKey"` |
| 71 | Resource string `gorm:"primaryKey"` |
| 72 | RequestID string `gorm:"primaryKey"` |
| 73 | InputHash, Result string |
| 74 | } |
| 75 | |
| 76 | func (requestRecord) TableName() string { return "conversation_requests" } |
| 77 | |
| 78 | type routeRecord struct { |
| 79 | SourceID string `gorm:"primaryKey"` |
| 80 | TaskID, ReplyID, NoticeID string |
| 81 | } |
| 82 | |
| 83 | func (routeRecord) TableName() string { return "conversation_routes" } |
| 84 | |
| 85 | type outboxRecord struct { |
| 86 | MessageID string `gorm:"primaryKey"` |
| 87 | StreamID, Purpose string |
| 88 | } |
| 89 | |
| 90 | func (outboxRecord) TableName() string { return "conversation_outboxes" } |
| 91 | |
| 92 | type cursorRecord struct { |
| 93 | ID string `gorm:"primaryKey"` |
| 94 | Principal, StreamID string |
| 95 | After, Through, Revision int64 |
| 96 | ExpiresAt time.Time |
| 97 | } |
| 98 | |
| 99 | func (cursorRecord) TableName() string { return "conversation_cursors" } |
| 100 | |
| 101 | var Models = []any{&ProjectProposal{}, &preferenceRecord{}, &personalSettingsRecord{}, &BindingRecord{}, &TurnRecord{}, &QuestionRecord{}, &Main{}, &Thread{}, &messageRecord{}, &cardRecord{}, &requestRecord{}, &routeRecord{}, &outboxRecord{}, &cursorRecord{}} |
| 102 | |