mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
event: add utility functions for hashed policy list entities
This commit is contained in:
parent
1b77ce1d3d
commit
de5bee328b
1 changed files with 20 additions and 0 deletions
|
|
@ -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"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue