oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package ownermode
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/planning"
5 "errors"
6 "fmt"
7 "gorm.io/gorm"
8)
9
10func HumanNote(tx *gorm.DB, conversation, note string, emit func(string, string) error) error {
11 var count int64
12 if err := tx.Table("conversation_messages").Where("conversation_id=? AND author_kind='system' AND body=?", conversation, note).Count(&count).Error; err != nil {
13 return err
14 }
15 if count > 0 {
16 return nil
17 }
18 return emit(conversation, note)
19}
20func LoginNotes(tx *gorm.DB, person, teamID string, decode func(*planning.ConnectionRecord) error, copy func(string) string, emit func(string, string) error) error {
21 connections, _, err := OwnConnections(tx, person, teamID)
22 if err != nil {
23 return err
24 }
25 var main struct{ ID string }
26 if err = tx.Table("conversations").Where("person=? AND team_id=?", person, teamID).Take(&main).Error; err != nil {
27 if errors.Is(err, gorm.ErrRecordNotFound) {
28 return nil
29 }
30 return err
31 }
32 for _, c := range connections {
33 if err = decode(&c); err != nil {
34 return err
35 }
36 for _, r := range c.Reports {
37 if r.UnavailableReason != "account.sign_in_again" || r.SignInCommand == "" {
38 continue
39 }
40 label := c.Label
41 if label == "" {
42 label = c.LocalID
43 }
44 if err = HumanNote(tx, main.ID, fmt.Sprintf(copy("coordinator.login_required"), label, r.SignInCommand), emit); err != nil {
45 return err
46 }
47 }
48 }
49 return nil
50}
51