Files
sm-user-plugin/classes/events.go
Jakub Zych 15b19c7021 feat(19-04): add users.handle, HandleGenerator and user.Created
Generate a unique mention handle on API register and admin create, and fire user.Created from both paths so listeners run in the same write.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 21:44:59 +02:00

44 lines
1.3 KiB
Go

package classes
import (
"git.golem15.com/golem15/sm-user-plugin/models"
"gorm.io/gorm"
)
// CreatedEventName is the festival name of CreatedEvent (D-13 / RESEARCH A6).
const CreatedEventName = "user.Created"
// GetApiArrayEvent is the fire-and-collect payload other plugins extend.
type GetApiArrayEvent struct {
User *models.User
data map[string]any
}
// Collected returns the map listeners merge into the user payload.
func (e *GetApiArrayEvent) Collected() map[string]any {
if e.data == nil {
e.data = map[string]any{}
}
return e.data
}
// RegisterEvent is fired after a user row is created (Winter's
// golem15.user.register).
type RegisterEvent struct {
User *models.User
// Payload is a copy of the register input, mirroring the data array
// Winter passes with golem15.user.register, so a listener can read
// extra keys a client sent (an invitation token, for example).
// password and password_confirmation are never included, in plaintext
// or hashed. Listeners must treat it as read-only input.
Payload map[string]any
}
// CreatedEvent fires from every user create path (API register and admin
// create) so listeners can run inside the same write, including handle
// generation (D-13, D-15). Tx is the create transaction when there is one.
type CreatedEvent struct {
User *models.User
Tx *gorm.DB
}