mautrix-go/event/delayed.go
Toni Spets 22ea75db96
Some checks failed
Go / Lint (latest) (push) Has been cancelled
Go / Build (old, libolm) (push) Has been cancelled
Go / Build (latest, libolm) (push) Has been cancelled
Go / Build (old, goolm) (push) Has been cancelled
Go / Build (latest, goolm) (push) Has been cancelled
client,event: MSC4140: Delayed events
Includes transparent migration from deprecated MSC fields still used
in Synapse to later revision.
2025-10-14 14:22:47 +03:00

70 lines
1.7 KiB
Go

package event
import (
"encoding/json"
"go.mau.fi/util/jsontime"
"maunium.net/go/mautrix/id"
)
type ScheduledDelayedEvent struct {
DelayID id.DelayID `json:"delay_id"`
RoomID id.RoomID `json:"room_id"`
Type Type `json:"type"`
StateKey *string `json:"state_key,omitempty"`
Delay int64 `json:"delay"`
RunningSince jsontime.UnixMilli `json:"running_since"`
Content Content `json:"content"`
}
func (e ScheduledDelayedEvent) AsEvent(eventID id.EventID, ts jsontime.UnixMilli) (*Event, error) {
evt := &Event{
ID: eventID,
RoomID: e.RoomID,
Type: e.Type,
StateKey: e.StateKey,
Content: e.Content,
Timestamp: ts.UnixMilli(),
}
return evt, evt.Content.ParseRaw(evt.Type)
}
type FinalisedDelayedEvent struct {
DelayedEvent *ScheduledDelayedEvent `json:"scheduled_event"`
Outcome DelayOutcome `json:"outcome"`
Reason DelayReason `json:"reason"`
Error json.RawMessage `json:"error,omitempty"`
EventID id.EventID `json:"event_id,omitempty"`
Timestamp jsontime.UnixMilli `json:"origin_server_ts"`
}
type DelayStatus string
var (
DelayStatusScheduled DelayStatus = "scheduled"
DelayStatusFinalised DelayStatus = "finalised"
)
type DelayAction string
var (
DelayActionSend DelayAction = "send"
DelayActionCancel DelayAction = "cancel"
DelayActionRestart DelayAction = "restart"
)
type DelayOutcome string
var (
DelayOutcomeSend DelayOutcome = "send"
DelayOutcomeCancel DelayOutcome = "cancel"
)
type DelayReason string
var (
DelayReasonAction DelayReason = "action"
DelayReasonError DelayReason = "error"
DelayReasonDelay DelayReason = "delay"
)