mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add space stuff. Fixes #53
This commit is contained in:
parent
d5c25a5793
commit
8916ec32ce
3 changed files with 45 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2020 Tulir Asokan
|
||||
// Copyright (c) 2021 Tulir Asokan
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
|
@ -32,6 +32,8 @@ var TypeMap = map[Type]reflect.Type{
|
|||
StateEncryption: reflect.TypeOf(EncryptionEventContent{}),
|
||||
StateBridge: reflect.TypeOf(BridgeEventContent{}),
|
||||
StateHalfShotBridge: reflect.TypeOf(BridgeEventContent{}),
|
||||
StateSpaceParent: reflect.TypeOf(SpaceParentEventContent{}),
|
||||
StateSpaceChild: reflect.TypeOf(SpaceChildEventContent{}),
|
||||
|
||||
EventMessage: reflect.TypeOf(MessageEventContent{}),
|
||||
EventSticker: reflect.TypeOf(MessageEventContent{}),
|
||||
|
|
@ -184,6 +186,9 @@ func init() {
|
|||
gob.Register(&PowerLevelsEventContent{})
|
||||
gob.Register(&CanonicalAliasEventContent{})
|
||||
gob.Register(&EncryptionEventContent{})
|
||||
gob.Register(&BridgeEventContent{})
|
||||
gob.Register(&SpaceChildEventContent{})
|
||||
gob.Register(&SpaceParentEventContent{})
|
||||
gob.Register(&RoomNameEventContent{})
|
||||
gob.Register(&RoomAvatarEventContent{})
|
||||
gob.Register(&TopicEventContent{})
|
||||
|
|
@ -311,6 +316,20 @@ func (content *Content) AsBridge() *BridgeEventContent {
|
|||
}
|
||||
return casted
|
||||
}
|
||||
func (content *Content) AsSpaceChild() *SpaceChildEventContent {
|
||||
casted, ok := content.Parsed.(*SpaceChildEventContent)
|
||||
if !ok {
|
||||
return &SpaceChildEventContent{}
|
||||
}
|
||||
return casted
|
||||
}
|
||||
func (content *Content) AsSpaceParent() *SpaceParentEventContent {
|
||||
casted, ok := content.Parsed.(*SpaceParentEventContent)
|
||||
if !ok {
|
||||
return &SpaceParentEventContent{}
|
||||
}
|
||||
return casted
|
||||
}
|
||||
func (content *Content) AsMessage() *MessageEventContent {
|
||||
casted, ok := content.Parsed.(*MessageEventContent)
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2020 Tulir Asokan
|
||||
// Copyright (c) 2021 Tulir Asokan
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
|
@ -45,7 +45,8 @@ type TombstoneEventContent struct {
|
|||
// CreateEventContent represents the content of a m.room.create state event.
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-create
|
||||
type CreateEventContent struct {
|
||||
Creator id.UserID `json:"creator"`
|
||||
Type RoomType `json:"type,omitempty"`
|
||||
Creator id.UserID `json:"creator,omitempty"`
|
||||
Federate bool `json:"m.federate,omitempty"`
|
||||
RoomVersion string `json:"version,omitempty"`
|
||||
Predecessor struct {
|
||||
|
|
@ -125,3 +126,13 @@ type BridgeEventContent struct {
|
|||
Network *BridgeInfoSection `json:"network,omitempty"`
|
||||
Channel BridgeInfoSection `json:"channel"`
|
||||
}
|
||||
|
||||
type SpaceChildEventContent struct {
|
||||
Via []string `json:"via,omitempty"`
|
||||
Order string `json:"order,omitempty"`
|
||||
}
|
||||
|
||||
type SpaceParentEventContent struct {
|
||||
Via []string `json:"via,omitempty"`
|
||||
Canonical bool `json:"canonical,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2020 Tulir Asokan
|
||||
// Copyright (c) 2021 Tulir Asokan
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
|
@ -12,6 +12,13 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type RoomType string
|
||||
|
||||
const (
|
||||
RoomTypeDefault RoomType = ""
|
||||
RoomTypeSpace RoomType = "m.space"
|
||||
)
|
||||
|
||||
type TypeClass int
|
||||
|
||||
func (tc TypeClass) Name() string {
|
||||
|
|
@ -101,7 +108,8 @@ func (et *Type) GuessClass() TypeClass {
|
|||
switch et.Type {
|
||||
case StateAliases.Type, StateCanonicalAlias.Type, StateCreate.Type, StateJoinRules.Type, StateMember.Type,
|
||||
StatePowerLevels.Type, StateRoomName.Type, StateRoomAvatar.Type, StateTopic.Type, StatePinnedEvents.Type,
|
||||
StateTombstone.Type, StateEncryption.Type, StateBridge.Type, StateHalfShotBridge.Type:
|
||||
StateTombstone.Type, StateEncryption.Type, StateBridge.Type, StateHalfShotBridge.Type, StateSpaceParent.Type,
|
||||
StateSpaceChild.Type:
|
||||
return StateEventType
|
||||
case EphemeralEventReceipt.Type, EphemeralEventTyping.Type, EphemeralEventPresence.Type:
|
||||
return EphemeralEventType
|
||||
|
|
@ -171,6 +179,8 @@ var (
|
|||
StateEncryption = Type{"m.room.encryption", StateEventType}
|
||||
StateBridge = Type{"m.bridge", StateEventType}
|
||||
StateHalfShotBridge = Type{"uk.half-shot.bridge", StateEventType}
|
||||
StateSpaceChild = Type{"m.space.child", StateEventType}
|
||||
StateSpaceParent = Type{"m.space.parent", StateEventType}
|
||||
)
|
||||
|
||||
// Message events
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue