2026-03-18 15:36:20 +00:00
|
|
|
package text
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-05-19 15:33:57 +00:00
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/enums"
|
|
|
|
|
modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
|
|
|
|
|
querycomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/comms"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
2026-05-15 16:58:28 +00:00
|
|
|
//"github.com/rs/zerolog/log"
|
2026-03-18 15:36:20 +00:00
|
|
|
)
|
|
|
|
|
|
2026-05-15 16:58:28 +00:00
|
|
|
func EnsureInDB(ctx context.Context, txn db.Ex, contact modelcomms.Contact, dst types.E164) (err error) {
|
|
|
|
|
return ensureInDB(ctx, txn, contact, dst.PhoneString())
|
2026-03-18 15:36:20 +00:00
|
|
|
}
|
2026-05-15 16:58:28 +00:00
|
|
|
func ensureInDB(ctx context.Context, txn db.Ex, contact modelcomms.Contact, destination string) (err error) {
|
|
|
|
|
contact_phone := modelcomms.ContactPhone{
|
|
|
|
|
CanSms: true,
|
|
|
|
|
ConfirmedMessageID: nil,
|
|
|
|
|
ContactID: contact.ID,
|
|
|
|
|
E164: destination,
|
|
|
|
|
IsSubscribed: false,
|
|
|
|
|
StopMessageID: nil,
|
|
|
|
|
}
|
|
|
|
|
_, err = querycomms.ContactPhoneInsert(ctx, txn, contact_phone)
|
2026-03-18 15:36:20 +00:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
func phoneStatus(ctx context.Context, src types.E164) (enums.CommsPhonestatustype, error) {
|
|
|
|
|
phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return enums.CommsPhonestatustypeUnconfirmed, fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src.PhoneString(), err)
|
|
|
|
|
}
|
|
|
|
|
return phone.Status, nil
|
|
|
|
|
}
|