use proper thread IDs on metadata save and error reporting

This commit is contained in:
Aine
2023-09-27 15:07:55 +03:00
parent 816db6f409
commit 7fbb279830
3 changed files with 39 additions and 5 deletions

View File

@@ -5,12 +5,14 @@ import (
"github.com/getsentry/sentry-go"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
type ctxkey int
const (
ctxEvent ctxkey = iota
ctxEvent ctxkey = iota
ctxThreadID ctxkey = iota
)
func newContext(evt *event.Event) context.Context {
@@ -49,3 +51,21 @@ func eventToContext(ctx context.Context, evt *event.Event) context.Context {
return ctx
}
func threadIDToContext(ctx context.Context, threadID id.EventID) context.Context {
return context.WithValue(ctx, ctxThreadID, threadID)
}
func threadIDFromContext(ctx context.Context) id.EventID {
v := ctx.Value(ctxThreadID)
if v == nil {
return ""
}
threadID, ok := v.(id.EventID)
if !ok {
return ""
}
return threadID
}