summaryrefslogtreecommitdiffstats
path: root/vendor/maunium.net/go/mautrix/room.go
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
committermsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
commit032a7e0c1188d3507b8d9a9571f2446a43cf775b (patch)
tree2bd38c01bc7761a6195e426082ce7191ebc765a1 /vendor/maunium.net/go/mautrix/room.go
parent56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (diff)
downloadmatterbridge-msglm-1.26.0+0.1.0.tar.gz
matterbridge-msglm-1.26.0+0.1.0.tar.bz2
matterbridge-msglm-1.26.0+0.1.0.zip
apply https://github.com/42wim/matterbridge/pull/1864v1.26.0+0.1.0
Diffstat (limited to 'vendor/maunium.net/go/mautrix/room.go')
-rw-r--r--vendor/maunium.net/go/mautrix/room.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/maunium.net/go/mautrix/room.go b/vendor/maunium.net/go/mautrix/room.go
new file mode 100644
index 00000000..c3ddb7e6
--- /dev/null
+++ b/vendor/maunium.net/go/mautrix/room.go
@@ -0,0 +1,54 @@
+package mautrix
+
+import (
+ "maunium.net/go/mautrix/event"
+ "maunium.net/go/mautrix/id"
+)
+
+type RoomStateMap = map[event.Type]map[string]*event.Event
+
+// Room represents a single Matrix room.
+type Room struct {
+ ID id.RoomID
+ State RoomStateMap
+}
+
+// UpdateState updates the room's current state with the given Event. This will clobber events based
+// on the type/state_key combination.
+func (room Room) UpdateState(evt *event.Event) {
+ _, exists := room.State[evt.Type]
+ if !exists {
+ room.State[evt.Type] = make(map[string]*event.Event)
+ }
+ room.State[evt.Type][*evt.StateKey] = evt
+}
+
+// GetStateEvent returns the state event for the given type/state_key combo, or nil.
+func (room Room) GetStateEvent(eventType event.Type, stateKey string) *event.Event {
+ stateEventMap, _ := room.State[eventType]
+ evt, _ := stateEventMap[stateKey]
+ return evt
+}
+
+// GetMembershipState returns the membership state of the given user ID in this room. If there is
+// no entry for this member, 'leave' is returned for consistency with left users.
+func (room Room) GetMembershipState(userID id.UserID) event.Membership {
+ state := event.MembershipLeave
+ evt := room.GetStateEvent(event.StateMember, string(userID))
+ if evt != nil {
+ membership, ok := evt.Content.Raw["membership"].(string)
+ if ok {
+ state = event.Membership(membership)
+ }
+ }
+ return state
+}
+
+// NewRoom creates a new Room with the given ID
+func NewRoom(roomID id.RoomID) *Room {
+ // Init the State map and return a pointer to the Room
+ return &Room{
+ ID: roomID,
+ State: make(RoomStateMap),
+ }
+}