event: add utility functions for hashed policy list entities
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
Tulir Asokan 2025-03-13 02:08:07 +02:00
commit de5bee328b

View file

@ -7,6 +7,8 @@
package event
import (
"encoding/base64"
"maunium.net/go/mautrix/id"
)
@ -215,6 +217,17 @@ type PolicyHashes struct {
SHA256 string `json:"sha256"`
}
func (ph *PolicyHashes) DecodeSHA256() *[32]byte {
if ph == nil || ph.SHA256 == "" {
return nil
}
decoded, _ := base64.StdEncoding.DecodeString(ph.SHA256)
if len(decoded) == 32 {
return (*[32]byte)(decoded)
}
return nil
}
// ModPolicyContent represents the content of a m.room.rule.user, m.room.rule.room, and m.room.rule.server state event.
// https://spec.matrix.org/v1.2/client-server-api/#moderation-policy-lists
type ModPolicyContent struct {
@ -224,6 +237,13 @@ type ModPolicyContent struct {
UnstableHashes *PolicyHashes `json:"org.matrix.msc4205.hashes,omitempty"`
}
func (mpc *ModPolicyContent) EntityOrHash() string {
if mpc.UnstableHashes != nil && mpc.UnstableHashes.SHA256 != "" {
return mpc.UnstableHashes.SHA256
}
return mpc.Entity
}
// Deprecated: MSC2716 has been abandoned
type InsertionMarkerContent struct {
InsertionID id.EventID `json:"org.matrix.msc2716.marker.insertion"`