aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-09-03 17:20:54 +0100
committerGitHub <noreply@github.com>2020-09-03 17:20:54 +0100
commitb20386123e0cbdc53016231f0087d0047b5667e9 (patch)
treef037957006b0295709be9890c22fdb4563a1d2be /roomserver/storage/shared
parent6150de6cb3611ffc61ce10ed6714f65e51e38e78 (diff)
Move currentstateserver API to roomserver (#1387)
* Move currentstateserver API to roomserver Stub out DB functions for now, nothing uses the roomserver version yet. * Allow it to startup * Implement some current-state-server storage interface functions * Add missing package
Diffstat (limited to 'roomserver/storage/shared')
-rw-r--r--roomserver/storage/shared/storage.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 6e0ebd2c..5c447d66 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
+ csstables "github.com/matrix-org/dendrite/currentstateserver/storage/tables"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -711,3 +712,82 @@ func (d *Database) loadEvent(ctx context.Context, eventID string) *types.Event {
}
return &evs[0]
}
+
+// GetStateEvent returns the current state event of a given type for a given room with a given state key
+// If no event could be found, returns nil
+// If there was an issue during the retrieval, returns an error
+func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error) {
+ /*
+ roomInfo, err := d.RoomInfo(ctx, roomID)
+ if err != nil {
+ return nil, err
+ }
+ eventTypeNID, err := d.EventTypesTable.SelectEventTypeNID(ctx, nil, evType)
+ if err != nil {
+ return nil, err
+ }
+ stateKeyNID, err := d.EventStateKeysTable.SelectEventStateKeyNID(ctx, nil, stateKey)
+ if err != nil {
+ return nil, err
+ }
+ blockNIDs, err := d.StateSnapshotTable.BulkSelectStateBlockNIDs(ctx, []types.StateSnapshotNID{roomInfo.StateSnapshotNID})
+ if err != nil {
+ return nil, err
+ }
+ */
+ return nil, nil
+}
+
+// GetRoomsByMembership returns a list of room IDs matching the provided membership and user ID (as state_key).
+func (d *Database) GetRoomsByMembership(ctx context.Context, userID, membership string) ([]string, error) {
+ var membershipState tables.MembershipState
+ switch membership {
+ case "join":
+ membershipState = tables.MembershipStateJoin
+ case "invite":
+ membershipState = tables.MembershipStateInvite
+ case "leave":
+ membershipState = tables.MembershipStateLeaveOrBan
+ case "ban":
+ membershipState = tables.MembershipStateLeaveOrBan
+ default:
+ return nil, fmt.Errorf("GetRoomsByMembership: invalid membership %s", membership)
+ }
+ stateKeyNID, err := d.EventStateKeysTable.SelectEventStateKeyNID(ctx, nil, userID)
+ if err != nil {
+ return nil, fmt.Errorf("GetRoomsByMembership: cannot map user ID to state key NID: %w", err)
+ }
+ roomNIDs, err := d.MembershipTable.SelectRoomsWithMembership(ctx, stateKeyNID, membershipState)
+ if err != nil {
+ return nil, err
+ }
+ roomIDs, err := d.RoomsTable.BulkSelectRoomIDs(ctx, roomNIDs)
+ if err != nil {
+ return nil, err
+ }
+ if len(roomIDs) != len(roomNIDs) {
+ return nil, fmt.Errorf("GetRoomsByMembership: missing room IDs, got %d want %d", len(roomIDs), len(roomNIDs))
+ }
+ return roomIDs, nil
+}
+
+// GetBulkStateContent returns all state events which match a given room ID and a given state key tuple. Both must be satisfied for a match.
+// If a tuple has the StateKey of '*' and allowWildcards=true then all state events with the EventType should be returned.
+func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tuples []gomatrixserverlib.StateKeyTuple, allowWildcards bool) ([]csstables.StrippedEvent, error) {
+ return nil, fmt.Errorf("not implemented yet")
+}
+
+// JoinedUsersSetInRooms returns all joined users in the rooms given, along with the count of how many times they appear.
+func (d *Database) JoinedUsersSetInRooms(ctx context.Context, roomIDs []string) (map[string]int, error) {
+ return nil, fmt.Errorf("not implemented yet")
+}
+
+// GetKnownUsers searches all users that userID knows about.
+func (d *Database) GetKnownUsers(ctx context.Context, userID, searchString string, limit int) ([]string, error) {
+ return nil, fmt.Errorf("not implemented yet")
+}
+
+// GetKnownRooms returns a list of all rooms we know about.
+func (d *Database) GetKnownRooms(ctx context.Context) ([]string, error) {
+ return d.RoomsTable.SelectRoomIDs(ctx)
+}