aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/tables/interface.go
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-09-07 12:38:09 +0100
committerGitHub <noreply@github.com>2020-09-07 12:38:09 +0100
commit79137599217808d9f9585628408a6c2aa26ab11d (patch)
tree6b7aa04541b563767ddd0ca04c873c634127678c /roomserver/storage/tables/interface.go
parent895ead804893191b34fd52a549b22331997d45f7 (diff)
Remove QueryBulkStateContent from current state server (#1404)
* Remove QueryBulkStateContent from current state server Expected fail due to db impl not existing * Implement query bulk state content * Fix up rejecting invites over federation * Fix bulk content marshalling
Diffstat (limited to 'roomserver/storage/tables/interface.go')
-rw-r--r--roomserver/storage/tables/interface.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/roomserver/storage/tables/interface.go b/roomserver/storage/tables/interface.go
index a142f2b1..adb06212 100644
--- a/roomserver/storage/tables/interface.go
+++ b/roomserver/storage/tables/interface.go
@@ -6,6 +6,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/tidwall/gjson"
)
type EventJSONPair struct {
@@ -155,3 +156,45 @@ type Redactions interface {
// successfully redacted the event JSON.
MarkRedactionValidated(ctx context.Context, txn *sql.Tx, redactionEventID string, validated bool) error
}
+
+// StrippedEvent represents a stripped event for returning extracted content values.
+type StrippedEvent struct {
+ RoomID string
+ EventType string
+ StateKey string
+ ContentValue string
+}
+
+// ExtractContentValue from the given state event. For example, given an m.room.name event with:
+// content: { name: "Foo" }
+// this returns "Foo".
+func ExtractContentValue(ev *gomatrixserverlib.HeaderedEvent) string {
+ content := ev.Content()
+ key := ""
+ switch ev.Type() {
+ case gomatrixserverlib.MRoomCreate:
+ key = "creator"
+ case gomatrixserverlib.MRoomCanonicalAlias:
+ key = "alias"
+ case gomatrixserverlib.MRoomHistoryVisibility:
+ key = "history_visibility"
+ case gomatrixserverlib.MRoomJoinRules:
+ key = "join_rule"
+ case gomatrixserverlib.MRoomMember:
+ key = "membership"
+ case gomatrixserverlib.MRoomName:
+ key = "name"
+ case "m.room.avatar":
+ key = "url"
+ case "m.room.topic":
+ key = "topic"
+ case "m.room.guest_access":
+ key = "guest_access"
+ }
+ result := gjson.GetBytes(content, key)
+ if !result.Exists() {
+ return ""
+ }
+ // this returns the empty string if this is not a string type
+ return result.Str
+}