| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/equipo/conversation" |
| 8 | "amadan.net/oficina/equipo/internal/equipo/kernel" |
| 9 | "gorm.io/gorm" |
| 10 | ) |
| 11 | |
| 12 | type Mutation = kernel.Mutation |
| 13 | type Message = conversation.Message |
| 14 | type Card = conversation.Card |
| 15 | type ConversationPage = conversation.ConversationPage |
| 16 | |
| 17 | //lint:ignore ST1005 User-facing errors preserve the pending sentence in copy.go. |
| 18 | var ErrCursorExpired = errors.New(copyConversationCursorExpired) |
| 19 | |
| 20 | func conversationAuthority(tx *gorm.DB, actor Actor) (string, error) { |
| 21 | if _, err := currentRunnerMember(tx, actor.Address); err != nil { |
| 22 | return "", err |
| 23 | } |
| 24 | var instance Team |
| 25 | if err := tx.First(&instance).Error; err != nil { |
| 26 | return "", storeError(err) |
| 27 | } |
| 28 | return instance.ID, nil |
| 29 | } |
| 30 | func conversationAt(tx *gorm.DB) *conversation.Store { |
| 31 | return conversation.New(tx, conversation.Dependencies{ |
| 32 | Authorize: conversationAuthority, CoordinatorAudit: coordinatorAudit, |
| 33 | Task: conversation.TaskLookup(conversationAuthority, ErrNotFound), |
| 34 | Audit: appendAudit, NotFound: ErrNotFound, Conflict: ErrConflict, Invalid: ErrInvalid, CursorExpired: ErrCursorExpired, RoutedCopy: pageCopy["conversation.routed"], ProposedCopy: copyText("plan.proposed"), |
| 35 | }) |
| 36 | } |
| 37 | func (s *Store) Conversation(ctx context.Context, a Actor, cursor string, limit int) (ConversationPage, error) { |
| 38 | return s.coordinatorApplication().ConversationPage(ctx, a, cursor, limit) |
| 39 | } |
| 40 | func (s *Store) SendMessage(ctx context.Context, a Actor, thread, body string, m Mutation) (Message, error) { |
| 41 | return s.coordinatorApplication().SendMessage(ctx, a, thread, body, m) |
| 42 | } |
| 43 | func (s *Store) TaskThread(ctx context.Context, a Actor, task, cursor string, limit int) (ConversationPage, error) { |
| 44 | return s.coordinatorApplication().TaskThread(ctx, a, task, cursor, limit) |
| 45 | } |
| 46 | func (s *Store) RouteMessage(ctx context.Context, a Actor, message, task string, m Mutation) (Message, error) { |
| 47 | return s.coordinatorApplication().RouteMessage(ctx, a, message, task, m) |
| 48 | } |
| 49 | |