41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
package archiegateway
|
|
|
|
import (
|
|
"github.com/samcharles93/archie-core/internal/domain/memory"
|
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
)
|
|
|
|
// carriesPersonIdentity reports whether a platform's SenderID names a person.
|
|
//
|
|
// Web sender IDs are supplied by the authenticated UI service.
|
|
// Telegram and email carry native person identifiers.
|
|
//
|
|
// An unknown platform fails closed, so a channel added later gets global and
|
|
// agent scopes only until someone decides deliberately that it carries people.
|
|
func carriesPersonIdentity(platform string) bool {
|
|
switch platform {
|
|
case "telegram", "email", "web":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// userIdentityResolver is the composition's identity policy for a turn, keyed on
|
|
// the platform the message itself names rather than on the process that serves
|
|
// it.
|
|
//
|
|
// It was closed over a single channel name, and one Gateway Router serves every
|
|
// channel, so that name was "web" even for a Telegram turn: the allowlist above
|
|
// was real code no production call site reached with a real channel name, and
|
|
// Subject.UserID was always empty. Reading the platform off
|
|
// the inbound is what makes the policy reachable.
|
|
func userIdentityResolver() func(messaging.Inbound) (memory.IdentityID, bool) {
|
|
return func(in messaging.Inbound) (memory.IdentityID, bool) {
|
|
if !carriesPersonIdentity(in.Platform) || in.Message.SenderID == "" {
|
|
return "", false
|
|
}
|
|
return memory.IdentityID(in.Message.SenderID), true
|
|
}
|
|
}
|