oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package chat
2
3import (
4 "context"
5 "errors"
6 "strings"
7
8 "amadan.net/oficina/equipo/internal/wire"
9 "gorm.io/gorm"
10)
11
12// DeviceCard reads one Coordinator card without the snapshot's newest-50
13// window. c_ is reserved for thin cards; legacy ids never fall through here.
14func (s *Store) DeviceCard(ctx context.Context, person, credential, id string) (out wire.Card, err error) {
15 if !strings.HasPrefix(id, "c_") {
16 return out, ErrNotFound
17 }
18 err = s.read(ctx, func(tx *gorm.DB) error {
19 if s.authority.CurrentPerson(ctx, tx) != nil {
20 return ErrNotFound
21 }
22 if s.pushCurrent(tx, person, credential) != nil {
23 return ErrNotFound
24 }
25 var c cardRecord
26 if err := tx.Where("id = ? AND person = ? AND (held IS NULL OR held = ?) AND coalesce(lane, '') = ?", id, person, false, wire.LaneCoordinator).Take(&c).Error; errors.Is(err, gorm.ErrRecordNotFound) {
27 return ErrNotFound
28 } else if err != nil {
29 return err
30 }
31 out, err = (&txn{s: s, db: tx, viewer: person}).cardView(c)
32 return err
33 })
34 return
35}
36