2017-04-20 23:40:52 +01:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
2020-02-05 18:06:39 +00:00
|
|
|
// Copyright 2018 New Vector Ltd
|
|
|
|
// Copyright 2019-2020 The Matrix.org Foundation C.I.C.
|
2017-04-20 23:40:52 +01:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-03-06 14:29:39 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-05-31 17:33:49 +01:00
|
|
|
"context"
|
2020-09-03 17:20:54 +01:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2017-07-12 14:13:10 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-19 15:50:33 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2023-06-06 14:16:55 +01:00
|
|
|
"github.com/matrix-org/util"
|
2022-10-27 13:40:35 +01:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
2023-04-27 12:54:20 +01:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
2023-04-04 18:16:53 +01:00
|
|
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
2017-03-06 14:29:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// QueryLatestEventsAndStateRequest is a request to QueryLatestEventsAndState
|
|
|
|
type QueryLatestEventsAndStateRequest struct {
|
2017-05-30 17:44:31 +01:00
|
|
|
// The room ID to query the latest events for.
|
2017-07-12 14:13:10 +01:00
|
|
|
RoomID string `json:"room_id"`
|
2017-03-06 14:29:39 +00:00
|
|
|
// The state key tuples to fetch from the room current state.
|
2020-05-05 15:48:37 +01:00
|
|
|
// If this list is empty or nil then *ALL* current state events are returned.
|
2017-07-12 14:13:10 +01:00
|
|
|
StateToFetch []gomatrixserverlib.StateKeyTuple `json:"state_to_fetch"`
|
2017-03-06 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryLatestEventsAndStateResponse is a response to QueryLatestEventsAndState
|
2017-06-27 15:28:44 +01:00
|
|
|
// This is used when sending events to set the prev_events, auth_events and depth.
|
|
|
|
// It is also used to tell whether the event is allowed by the event auth rules.
|
2017-03-06 14:29:39 +00:00
|
|
|
type QueryLatestEventsAndStateResponse struct {
|
|
|
|
// Does the room exist?
|
|
|
|
// If the room doesn't exist this will be false and LatestEvents will be empty.
|
2017-07-12 14:13:10 +01:00
|
|
|
RoomExists bool `json:"room_exists"`
|
2020-03-19 12:07:01 +00:00
|
|
|
// The room version of the room.
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
2017-03-06 14:29:39 +00:00
|
|
|
// The latest events in the room.
|
2017-06-27 15:28:44 +01:00
|
|
|
// These are used to set the prev_events when sending an event.
|
2023-05-24 11:14:42 +01:00
|
|
|
LatestEvents []string `json:"latest_events"`
|
2017-03-06 14:29:39 +00:00
|
|
|
// The state events requested.
|
2017-06-02 14:32:36 +01:00
|
|
|
// This list will be in an arbitrary order.
|
2017-06-27 15:28:44 +01:00
|
|
|
// These are used to set the auth_events when sending an event.
|
|
|
|
// These are used to check whether the event is allowed.
|
2023-04-27 12:54:20 +01:00
|
|
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
2017-06-27 15:28:44 +01:00
|
|
|
// The depth of the latest events.
|
|
|
|
// This is one greater than the maximum depth of the latest events.
|
|
|
|
// This is used to set the depth when sending an event.
|
2017-07-12 14:13:10 +01:00
|
|
|
Depth int64 `json:"depth"`
|
2017-03-06 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 17:44:31 +01:00
|
|
|
// QueryStateAfterEventsRequest is a request to QueryStateAfterEvents
|
|
|
|
type QueryStateAfterEventsRequest struct {
|
|
|
|
// The room ID to query the state in.
|
2017-07-12 14:13:10 +01:00
|
|
|
RoomID string `json:"room_id"`
|
2017-05-30 17:44:31 +01:00
|
|
|
// The list of previous events to return the events after.
|
2017-07-12 14:13:10 +01:00
|
|
|
PrevEventIDs []string `json:"prev_event_ids"`
|
2020-10-14 12:39:37 +01:00
|
|
|
// The state key tuples to fetch from the state. If none are specified then
|
|
|
|
// the entire resolved room state will be returned.
|
2017-07-12 14:13:10 +01:00
|
|
|
StateToFetch []gomatrixserverlib.StateKeyTuple `json:"state_to_fetch"`
|
2017-05-30 17:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryStateAfterEventsResponse is a response to QueryStateAfterEvents
|
|
|
|
type QueryStateAfterEventsResponse struct {
|
|
|
|
// Does the room exist on this roomserver?
|
|
|
|
// If the room doesn't exist this will be false and StateEvents will be empty.
|
2017-07-12 14:13:10 +01:00
|
|
|
RoomExists bool `json:"room_exists"`
|
2020-03-19 12:07:01 +00:00
|
|
|
// The room version of the room.
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
2017-05-30 17:44:31 +01:00
|
|
|
// Do all the previous events exist on this roomserver?
|
|
|
|
// If some of previous events do not exist this will be false and StateEvents will be empty.
|
2017-07-12 14:13:10 +01:00
|
|
|
PrevEventsExist bool `json:"prev_events_exist"`
|
2017-05-30 17:44:31 +01:00
|
|
|
// The state events requested.
|
2017-06-02 14:32:36 +01:00
|
|
|
// This list will be in an arbitrary order.
|
2023-04-27 12:54:20 +01:00
|
|
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
2017-05-30 17:44:31 +01:00
|
|
|
}
|
|
|
|
|
2017-06-02 14:32:36 +01:00
|
|
|
// QueryEventsByIDRequest is a request to QueryEventsByID
|
|
|
|
type QueryEventsByIDRequest struct {
|
2023-03-01 16:06:47 +00:00
|
|
|
// The roomID to query events for. If this is empty, we first try to fetch the roomID from the database
|
|
|
|
// as this is needed for further processing/parsing events.
|
|
|
|
RoomID string `json:"room_id"`
|
2017-06-02 14:32:36 +01:00
|
|
|
// The event IDs to look up.
|
2017-07-12 14:13:10 +01:00
|
|
|
EventIDs []string `json:"event_ids"`
|
2017-06-02 14:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryEventsByIDResponse is a response to QueryEventsByID
|
|
|
|
type QueryEventsByIDResponse struct {
|
|
|
|
// A list of events with the requested IDs.
|
|
|
|
// If the roomserver does not have a copy of a requested event
|
|
|
|
// then it will omit that event from the list.
|
|
|
|
// If the roomserver thinks it has a copy of the event, but
|
|
|
|
// fails to read it from the database then it will fail
|
|
|
|
// the entire request.
|
|
|
|
// This list will be in an arbitrary order.
|
2023-04-27 12:54:20 +01:00
|
|
|
Events []*types.HeaderedEvent `json:"events"`
|
2017-06-02 14:32:36 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 11:10:37 +01:00
|
|
|
// QueryMembershipForUserRequest is a request to QueryMembership
|
|
|
|
type QueryMembershipForUserRequest struct {
|
|
|
|
// ID of the room to fetch membership from
|
2023-06-12 12:19:25 +01:00
|
|
|
RoomID string
|
2018-07-11 11:10:37 +01:00
|
|
|
// ID of the user for whom membership is requested
|
2023-06-12 12:19:25 +01:00
|
|
|
UserID spec.UserID
|
2018-07-11 11:10:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMembershipForUserResponse is a response to QueryMembership
|
|
|
|
type QueryMembershipForUserResponse struct {
|
|
|
|
// The EventID of the latest "m.room.member" event for the sender,
|
|
|
|
// if HasBeenInRoom is true.
|
|
|
|
EventID string `json:"event_id"`
|
|
|
|
// True if the user has been in room before and has either stayed in it or left it.
|
|
|
|
HasBeenInRoom bool `json:"has_been_in_room"`
|
|
|
|
// True if the user is in room.
|
|
|
|
IsInRoom bool `json:"is_in_room"`
|
2020-06-24 18:19:54 +01:00
|
|
|
// The current membership
|
2020-11-05 10:19:23 +00:00
|
|
|
Membership string `json:"membership"`
|
|
|
|
// True if the user asked to forget this room.
|
|
|
|
IsRoomForgotten bool `json:"is_room_forgotten"`
|
2022-05-11 11:29:23 +01:00
|
|
|
RoomExists bool `json:"room_exists"`
|
2018-07-11 11:10:37 +01:00
|
|
|
}
|
|
|
|
|
2017-08-21 16:34:26 +01:00
|
|
|
// QueryMembershipsForRoomRequest is a request to QueryMembershipsForRoom
|
|
|
|
type QueryMembershipsForRoomRequest struct {
|
2017-08-24 16:00:14 +01:00
|
|
|
// If true, only returns the membership events of "join" membership
|
|
|
|
JoinedOnly bool `json:"joined_only"`
|
2022-04-06 10:43:54 +01:00
|
|
|
// If true, only returns the membership events of local users
|
|
|
|
LocalOnly bool `json:"local_only"`
|
2017-08-21 16:34:26 +01:00
|
|
|
// ID of the room to fetch memberships from
|
|
|
|
RoomID string `json:"room_id"`
|
2021-03-03 16:27:44 +00:00
|
|
|
// Optional - ID of the user sending the request, for checking if the
|
|
|
|
// user is allowed to see the memberships. If not specified then all
|
|
|
|
// room memberships will be returned.
|
2023-06-12 12:19:25 +01:00
|
|
|
SenderID spec.SenderID `json:"sender"`
|
2017-08-21 16:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMembershipsForRoomResponse is a response to QueryMembershipsForRoom
|
|
|
|
type QueryMembershipsForRoomResponse struct {
|
|
|
|
// The "m.room.member" events (of "join" membership) in the client format
|
2023-04-04 18:16:53 +01:00
|
|
|
JoinEvents []synctypes.ClientEvent `json:"join_events"`
|
2017-08-21 16:34:26 +01:00
|
|
|
// True if the user has been in room before and has either stayed in it or
|
|
|
|
// left it.
|
|
|
|
HasBeenInRoom bool `json:"has_been_in_room"`
|
2020-11-05 10:19:23 +00:00
|
|
|
// True if the user asked to forget this room.
|
|
|
|
IsRoomForgotten bool `json:"is_room_forgotten"`
|
2017-08-21 16:34:26 +01:00
|
|
|
}
|
|
|
|
|
2020-09-24 16:18:13 +01:00
|
|
|
// QueryServerJoinedToRoomRequest is a request to QueryServerJoinedToRoom
|
|
|
|
type QueryServerJoinedToRoomRequest struct {
|
2021-07-09 16:36:45 +01:00
|
|
|
// Server name of the server to find. If not specified, we will
|
|
|
|
// default to checking if the local server is joined.
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
2020-09-24 16:18:13 +01:00
|
|
|
// ID of the room to see if we are still joined to
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMembershipsForRoomResponse is a response to QueryServerJoinedToRoom
|
|
|
|
type QueryServerJoinedToRoomResponse struct {
|
|
|
|
// True if the room exists on the server
|
|
|
|
RoomExists bool `json:"room_exists"`
|
2021-07-21 13:06:32 +01:00
|
|
|
// True if we still believe that the server is participating in the room
|
2020-09-24 16:18:13 +01:00
|
|
|
IsInRoom bool `json:"is_in_room"`
|
2023-06-28 19:29:49 +01:00
|
|
|
// The roomversion if joined to room
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion
|
2020-09-24 16:18:13 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 12:38:22 +01:00
|
|
|
// QueryServerAllowedToSeeEventRequest is a request to QueryServerAllowedToSeeEvent
|
|
|
|
type QueryServerAllowedToSeeEventRequest struct {
|
|
|
|
// The event ID to look up invites in.
|
|
|
|
EventID string `json:"event_id"`
|
|
|
|
// The server interested in the event
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
2017-09-06 12:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryServerAllowedToSeeEventResponse is a response to QueryServerAllowedToSeeEvent
|
|
|
|
type QueryServerAllowedToSeeEventResponse struct {
|
|
|
|
// Wether the server in question is allowed to see the event
|
|
|
|
AllowedToSeeEvent bool `json:"can_see_event"`
|
|
|
|
}
|
|
|
|
|
2018-06-26 11:25:49 +01:00
|
|
|
// QueryMissingEventsRequest is a request to QueryMissingEvents
|
|
|
|
type QueryMissingEventsRequest struct {
|
|
|
|
// Events which are known previous to the gap in the timeline.
|
|
|
|
EarliestEvents []string `json:"earliest_events"`
|
|
|
|
// Latest known events.
|
|
|
|
LatestEvents []string `json:"latest_events"`
|
|
|
|
// Limit the number of events this query returns.
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
// The server interested in the event
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
2018-06-26 11:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMissingEventsResponse is a response to QueryMissingEvents
|
|
|
|
type QueryMissingEventsResponse struct {
|
|
|
|
// Missing events, arbritrary order.
|
2023-04-27 12:54:20 +01:00
|
|
|
Events []*types.HeaderedEvent `json:"events"`
|
2018-06-26 11:25:49 +01:00
|
|
|
}
|
|
|
|
|
2017-11-27 10:20:00 +00:00
|
|
|
// QueryStateAndAuthChainRequest is a request to QueryStateAndAuthChain
|
|
|
|
type QueryStateAndAuthChainRequest struct {
|
|
|
|
// The room ID to query the state in.
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
// The list of prev events for the event. Used to calculate the state at
|
2021-01-22 14:55:08 +00:00
|
|
|
// the event.
|
2017-11-27 10:20:00 +00:00
|
|
|
PrevEventIDs []string `json:"prev_event_ids"`
|
|
|
|
// The list of auth events for the event. Used to calculate the auth chain
|
|
|
|
AuthEventIDs []string `json:"auth_event_ids"`
|
2022-01-06 17:13:34 +00:00
|
|
|
// If true, the auth chain events for the auth event IDs given will be fetched only. Prev event IDs are ignored.
|
|
|
|
// If false, state and auth chain events for the prev event IDs and entire current state will be included.
|
|
|
|
// TODO: not a great API shape. It serves 2 main uses: false=>response for send_join, true=>response for /event_auth
|
|
|
|
OnlyFetchAuthChain bool `json:"only_fetch_auth_chain"`
|
Federation for v3/v4 rooms (#954)
* Update gomatrixserverlib
* Default to room version 4
* Update gomatrixserverlib
* Limit prev_events and auth_events
* Fix auth_events, prev_events
* Fix linter issues
* Update gomatrixserverlib
* Fix getState
* Update sytest-whitelist
* Squashed commit of the following:
commit 067b87506357c996fd6ddb11271db9469ad4ce80
Author: Neil Alexander <neilalexander@users.noreply.github.com>
Date: Fri Apr 3 14:29:06 2020 +0100
Invites v2 endpoint (#952)
* Start converting v1 invite endpoint to v2
* Update gomatrixserverlib
* Early federationsender code for sending invites
* Sending invites sorta happens now
* Populate invite request with stripped state
* Remodel a bit, don't reflect received invites
* Handle invite_room_state
* Handle room versions a bit better
* Update gomatrixserverlib
* Tweak order in destinationQueue.next
* Revert check in processMessage
* Tweak federation sender destination queue code a bit
* Add comments
commit 955244c09298d0e6c870377dad3af2ffa1f5e578
Author: Ben B <benne@klimlive.de>
Date: Fri Apr 3 12:40:50 2020 +0200
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one.
The previously used default client doesn't come with a timeout. This could cause
unwanted locks.
That solution chosen here creates a http client in the base component dendrite
with a constant timeout of 30 seconds. If it should be necessary to overwrite
this, we could include the timeout in the dendrite configuration.
Here it would be a good idea to extend the type "Address" by a timeout and
create an http client for each service.
Closes #820
Signed-off-by: Benedikt Bongartz <benne@klimlive.de>
Co-authored-by: Kegsay <kegan@matrix.org>
* Update sytest-whitelist, sytest-blacklist
* Update go.mod/go.sum
* Add some error wrapping for debug
* Add a NOTSPEC to common/events.go
* Perform state resolution at send_join
* Set default room version to v2 again
* Tweak GetCapabilities
* Add comments to ResolveConflictsAdhoc
* Update sytest-blacklist
* go mod tidy
* Update sytest-whitelist, sytest-blacklist
* Update versions
* Updates from review comments
* Update sytest-blacklist, sytest-whitelist
* Check room versions compatible at make_join, add some comments, update gomatrixserverlib, other tweaks
* Set default room version back to v2
* Update gomatrixserverlib, sytest-whitelist
2020-04-09 15:46:06 +01:00
|
|
|
// Should state resolution be ran on the result events?
|
|
|
|
// TODO: check call sites and remove if we always want to do state res
|
|
|
|
ResolveState bool `json:"resolve_state"`
|
2017-11-27 10:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryStateAndAuthChainResponse is a response to QueryStateAndAuthChain
|
|
|
|
type QueryStateAndAuthChainResponse struct {
|
|
|
|
// Does the room exist on this roomserver?
|
|
|
|
// If the room doesn't exist this will be false and StateEvents will be empty.
|
|
|
|
RoomExists bool `json:"room_exists"`
|
2020-03-19 12:07:01 +00:00
|
|
|
// The room version of the room.
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
2017-11-27 10:20:00 +00:00
|
|
|
// Do all the previous events exist on this roomserver?
|
|
|
|
// If some of previous events do not exist this will be false and StateEvents will be empty.
|
|
|
|
PrevEventsExist bool `json:"prev_events_exist"`
|
2022-08-25 09:51:36 +01:00
|
|
|
StateKnown bool `json:"state_known"`
|
2017-11-27 10:20:00 +00:00
|
|
|
// The state and auth chain events that were requested.
|
|
|
|
// The lists will be in an arbitrary order.
|
2023-04-27 12:54:20 +01:00
|
|
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
|
|
|
AuthChainEvents []*types.HeaderedEvent `json:"auth_chain_events"`
|
2022-04-25 18:05:01 +01:00
|
|
|
// True if the queried event was rejected earlier.
|
|
|
|
IsRejected bool `json:"is_rejected"`
|
2017-11-27 10:20:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 11:46:47 +01:00
|
|
|
// QueryRoomVersionForRoomRequest asks for the room version for a given room.
|
2020-03-27 16:28:22 +00:00
|
|
|
type QueryRoomVersionForRoomRequest struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
}
|
|
|
|
|
2020-04-28 11:46:47 +01:00
|
|
|
// QueryRoomVersionForRoomResponse is a response to QueryRoomVersionForRoomRequest
|
2020-03-27 16:28:22 +00:00
|
|
|
type QueryRoomVersionForRoomResponse struct {
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
|
|
|
}
|
2020-07-02 15:41:18 +01:00
|
|
|
|
|
|
|
type QueryPublishedRoomsRequest struct {
|
|
|
|
// Optional. If specified, returns whether this room is published or not.
|
2022-10-27 13:40:35 +01:00
|
|
|
RoomID string
|
|
|
|
NetworkID string
|
|
|
|
IncludeAllNetworks bool
|
2020-07-02 15:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryPublishedRoomsResponse struct {
|
|
|
|
// The list of published rooms.
|
|
|
|
RoomIDs []string
|
|
|
|
}
|
2020-09-03 17:20:54 +01:00
|
|
|
|
2020-12-04 14:11:01 +00:00
|
|
|
type QueryAuthChainRequest struct {
|
|
|
|
EventIDs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryAuthChainResponse struct {
|
2023-04-27 12:54:20 +01:00
|
|
|
AuthChain []*types.HeaderedEvent
|
2020-12-04 14:11:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 17:20:54 +01:00
|
|
|
type QuerySharedUsersRequest struct {
|
|
|
|
UserID string
|
2022-03-01 13:01:38 +00:00
|
|
|
OtherUserIDs []string
|
2020-09-03 17:20:54 +01:00
|
|
|
ExcludeRoomIDs []string
|
|
|
|
IncludeRoomIDs []string
|
2022-10-05 12:47:53 +01:00
|
|
|
LocalOnly bool
|
2020-09-03 17:20:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type QuerySharedUsersResponse struct {
|
|
|
|
UserIDsToCount map[string]int
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryRoomsForUserRequest struct {
|
|
|
|
UserID string
|
|
|
|
// The desired membership of the user. If this is the empty string then no rooms are returned.
|
|
|
|
WantMembership string
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryRoomsForUserResponse struct {
|
|
|
|
RoomIDs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryBulkStateContentRequest struct {
|
|
|
|
// Returns state events in these rooms
|
|
|
|
RoomIDs []string
|
|
|
|
// If true, treats the '*' StateKey as "all state events of this type" rather than a literal value of '*'
|
|
|
|
AllowWildcards bool
|
|
|
|
// The state events to return. Only a small subset of tuples are allowed in this request as only certain events
|
|
|
|
// have their content fields extracted. Specifically, the tuple Type must be one of:
|
|
|
|
// m.room.avatar
|
|
|
|
// m.room.create
|
|
|
|
// m.room.canonical_alias
|
|
|
|
// m.room.guest_access
|
|
|
|
// m.room.history_visibility
|
|
|
|
// m.room.join_rules
|
|
|
|
// m.room.member
|
|
|
|
// m.room.name
|
|
|
|
// m.room.topic
|
|
|
|
// Any other tuple type will result in the query failing.
|
|
|
|
StateTuples []gomatrixserverlib.StateKeyTuple
|
|
|
|
}
|
|
|
|
type QueryBulkStateContentResponse struct {
|
|
|
|
// map of room ID -> tuple -> content_value
|
|
|
|
Rooms map[string]map[gomatrixserverlib.StateKeyTuple]string
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryCurrentStateRequest struct {
|
2022-03-01 13:40:07 +00:00
|
|
|
RoomID string
|
|
|
|
AllowWildcards bool
|
|
|
|
// State key tuples. If a state_key has '*' and AllowWidlcards is true, returns all matching
|
|
|
|
// state events with that event type.
|
2020-09-03 17:20:54 +01:00
|
|
|
StateTuples []gomatrixserverlib.StateKeyTuple
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryCurrentStateResponse struct {
|
2023-04-27 12:54:20 +01:00
|
|
|
StateEvents map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent
|
2020-09-03 17:20:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryKnownUsersRequest struct {
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
SearchString string `json:"search_string"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryKnownUsersResponse struct {
|
|
|
|
Users []authtypes.FullyQualifiedProfile `json:"profiles"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryServerBannedFromRoomRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
|
|
|
RoomID string `json:"room_id"`
|
2020-09-03 17:20:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryServerBannedFromRoomResponse struct {
|
|
|
|
Banned bool `json:"banned"`
|
2022-05-25 10:05:30 +01:00
|
|
|
}
|
|
|
|
|
2020-09-07 12:38:09 +01:00
|
|
|
// MarshalJSON stringifies the room ID and StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
|
|
|
func (r *QueryBulkStateContentResponse) MarshalJSON() ([]byte, error) {
|
|
|
|
se := make(map[string]string)
|
|
|
|
for roomID, tupleToEvent := range r.Rooms {
|
|
|
|
for tuple, event := range tupleToEvent {
|
|
|
|
// use 0x1F (unit separator) as the delimiter between room ID/type/state key,
|
|
|
|
se[fmt.Sprintf("%s\x1F%s\x1F%s", roomID, tuple.EventType, tuple.StateKey)] = event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return json.Marshal(se)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *QueryBulkStateContentResponse) UnmarshalJSON(data []byte) error {
|
|
|
|
wireFormat := make(map[string]string)
|
|
|
|
err := json.Unmarshal(data, &wireFormat)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
r.Rooms = make(map[string]map[gomatrixserverlib.StateKeyTuple]string)
|
|
|
|
for roomTuple, value := range wireFormat {
|
|
|
|
fields := strings.Split(roomTuple, "\x1F")
|
|
|
|
roomID := fields[0]
|
|
|
|
if r.Rooms[roomID] == nil {
|
|
|
|
r.Rooms[roomID] = make(map[gomatrixserverlib.StateKeyTuple]string)
|
|
|
|
}
|
|
|
|
r.Rooms[roomID][gomatrixserverlib.StateKeyTuple{
|
|
|
|
EventType: fields[1],
|
|
|
|
StateKey: fields[2],
|
|
|
|
}] = value
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 17:20:54 +01:00
|
|
|
// MarshalJSON stringifies the StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
|
|
|
func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) {
|
2023-04-27 12:54:20 +01:00
|
|
|
se := make(map[string]*types.HeaderedEvent, len(r.StateEvents))
|
2020-09-03 17:20:54 +01:00
|
|
|
for k, v := range r.StateEvents {
|
|
|
|
// use 0x1F (unit separator) as the delimiter between type/state key,
|
|
|
|
se[fmt.Sprintf("%s\x1F%s", k.EventType, k.StateKey)] = v
|
|
|
|
}
|
|
|
|
return json.Marshal(se)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *QueryCurrentStateResponse) UnmarshalJSON(data []byte) error {
|
2023-04-27 12:54:20 +01:00
|
|
|
res := make(map[string]*types.HeaderedEvent)
|
2020-09-03 17:20:54 +01:00
|
|
|
err := json.Unmarshal(data, &res)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-04-27 12:54:20 +01:00
|
|
|
r.StateEvents = make(map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent, len(res))
|
2020-09-03 17:20:54 +01:00
|
|
|
for k, v := range res {
|
|
|
|
fields := strings.Split(k, "\x1F")
|
|
|
|
r.StateEvents[gomatrixserverlib.StateKeyTuple{
|
|
|
|
EventType: fields[0],
|
|
|
|
StateKey: fields[1],
|
|
|
|
}] = v
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-11 17:23:35 +01:00
|
|
|
|
2023-02-07 13:31:23 +00:00
|
|
|
// QueryMembershipAtEventRequest requests the membership event for a user
|
2022-08-11 17:23:35 +01:00
|
|
|
// for a list of eventIDs.
|
|
|
|
type QueryMembershipAtEventRequest struct {
|
|
|
|
RoomID string
|
|
|
|
EventIDs []string
|
|
|
|
UserID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMembershipAtEventResponse is the response to QueryMembershipAtEventRequest.
|
|
|
|
type QueryMembershipAtEventResponse struct {
|
2023-02-07 13:31:23 +00:00
|
|
|
// Membership is a map from eventID to membership event. Events that
|
|
|
|
// do not have known state will return a nil event, resulting in a "leave" membership
|
|
|
|
// when calculating history visibility.
|
2023-04-27 12:54:20 +01:00
|
|
|
Membership map[string]*types.HeaderedEvent `json:"membership"`
|
2022-08-11 17:23:35 +01:00
|
|
|
}
|
2022-12-12 07:20:59 +00:00
|
|
|
|
|
|
|
// QueryLeftUsersRequest is a request to calculate users that we (the server) don't share a
|
|
|
|
// a room with anymore. This is used to cleanup stale device list entries, where we would
|
|
|
|
// otherwise keep on trying to get device lists.
|
|
|
|
type QueryLeftUsersRequest struct {
|
|
|
|
StaleDeviceListUsers []string `json:"user_ids"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryLeftUsersResponse is the response to QueryLeftUsersRequest.
|
|
|
|
type QueryLeftUsersResponse struct {
|
|
|
|
LeftUsers []string `json:"user_ids"`
|
|
|
|
}
|
2023-05-31 17:33:49 +01:00
|
|
|
|
2023-06-06 14:16:55 +01:00
|
|
|
type JoinRoomQuerier struct {
|
|
|
|
Roomserver RestrictedJoinAPI
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rq *JoinRoomQuerier) CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (gomatrixserverlib.PDU, error) {
|
|
|
|
return rq.Roomserver.CurrentStateEvent(ctx, roomID, eventType, stateKey)
|
|
|
|
}
|
|
|
|
|
2023-06-12 12:19:25 +01:00
|
|
|
func (rq *JoinRoomQuerier) InvitePending(ctx context.Context, roomID spec.RoomID, senderID spec.SenderID) (bool, error) {
|
|
|
|
return rq.Roomserver.InvitePending(ctx, roomID, senderID)
|
2023-06-06 14:16:55 +01:00
|
|
|
}
|
|
|
|
|
2023-06-12 12:19:25 +01:00
|
|
|
func (rq *JoinRoomQuerier) RestrictedRoomJoinInfo(ctx context.Context, roomID spec.RoomID, senderID spec.SenderID, localServerName spec.ServerName) (*gomatrixserverlib.RestrictedRoomJoinInfo, error) {
|
2023-06-06 14:16:55 +01:00
|
|
|
roomInfo, err := rq.Roomserver.QueryRoomInfo(ctx, roomID)
|
|
|
|
if err != nil || roomInfo == nil || roomInfo.IsStub() {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req := QueryServerJoinedToRoomRequest{
|
|
|
|
ServerName: localServerName,
|
|
|
|
RoomID: roomID.String(),
|
|
|
|
}
|
|
|
|
res := QueryServerJoinedToRoomResponse{}
|
|
|
|
if err = rq.Roomserver.QueryServerJoinedToRoom(ctx, &req, &res); err != nil {
|
|
|
|
util.GetLogger(ctx).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
|
|
|
|
return nil, fmt.Errorf("InternalServerError: Failed to query room: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-06-12 12:19:25 +01:00
|
|
|
userJoinedToRoom, err := rq.Roomserver.UserJoinedToRoom(ctx, types.RoomNID(roomInfo.RoomNID), senderID)
|
2023-06-06 14:16:55 +01:00
|
|
|
if err != nil {
|
|
|
|
util.GetLogger(ctx).WithError(err).Error("rsAPI.UserJoinedToRoom failed")
|
|
|
|
return nil, fmt.Errorf("InternalServerError: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
locallyJoinedUsers, err := rq.Roomserver.LocallyJoinedUsers(ctx, roomInfo.RoomVersion, types.RoomNID(roomInfo.RoomNID))
|
|
|
|
if err != nil {
|
|
|
|
util.GetLogger(ctx).WithError(err).Error("rsAPI.GetLocallyJoinedUsers failed")
|
|
|
|
return nil, fmt.Errorf("InternalServerError: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &gomatrixserverlib.RestrictedRoomJoinInfo{
|
|
|
|
LocalServerInRoom: res.RoomExists && res.IsInRoom,
|
|
|
|
UserJoinedToRoom: userJoinedToRoom,
|
|
|
|
JoinedUsers: locallyJoinedUsers,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-05-31 17:33:49 +01:00
|
|
|
type MembershipQuerier struct {
|
|
|
|
Roomserver FederationRoomserverAPI
|
|
|
|
}
|
|
|
|
|
2023-06-06 21:55:18 +01:00
|
|
|
func (mq *MembershipQuerier) CurrentMembership(ctx context.Context, roomID spec.RoomID, senderID spec.SenderID) (string, error) {
|
2023-05-31 17:33:49 +01:00
|
|
|
res := QueryMembershipForUserResponse{}
|
2023-06-12 12:19:25 +01:00
|
|
|
err := mq.Roomserver.QueryMembershipForSenderID(ctx, roomID, senderID, &res)
|
2023-05-31 17:33:49 +01:00
|
|
|
|
|
|
|
membership := ""
|
|
|
|
if err == nil {
|
|
|
|
membership = res.Membership
|
|
|
|
}
|
|
|
|
return membership, err
|
|
|
|
}
|
2023-07-20 15:06:05 +01:00
|
|
|
|
|
|
|
type QueryRoomHierarchyRequest struct {
|
|
|
|
SuggestedOnly bool `json:"suggested_only"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
MaxDepth int `json:"max_depth"`
|
|
|
|
From int `json:"json"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// A struct storing the intermediate state of a room hierarchy query for pagination purposes.
|
|
|
|
//
|
|
|
|
// Used for implementing space summaries / room hierarchies
|
|
|
|
//
|
|
|
|
// Use NewRoomHierarchyWalker to construct this, and QueryNextRoomHierarchyPage on the roomserver API
|
|
|
|
// to traverse the room hierarchy.
|
|
|
|
type RoomHierarchyWalker struct {
|
|
|
|
RootRoomID spec.RoomID
|
|
|
|
Caller types.DeviceOrServerName
|
|
|
|
SuggestedOnly bool
|
|
|
|
MaxDepth int
|
|
|
|
Processed RoomSet
|
|
|
|
Unvisited []RoomHierarchyWalkerQueuedRoom
|
|
|
|
}
|
|
|
|
|
|
|
|
type RoomHierarchyWalkerQueuedRoom struct {
|
|
|
|
RoomID spec.RoomID
|
|
|
|
ParentRoomID *spec.RoomID
|
|
|
|
Depth int
|
|
|
|
Vias []string // vias to query this room by
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new room hierarchy walker, starting from the provided root room ID.
|
|
|
|
//
|
|
|
|
// Use the resulting struct with QueryNextRoomHierarchyPage on the roomserver API to traverse the room hierarchy.
|
|
|
|
func NewRoomHierarchyWalker(caller types.DeviceOrServerName, roomID spec.RoomID, suggestedOnly bool, maxDepth int) RoomHierarchyWalker {
|
|
|
|
walker := RoomHierarchyWalker{
|
|
|
|
RootRoomID: roomID,
|
|
|
|
Caller: caller,
|
|
|
|
SuggestedOnly: suggestedOnly,
|
|
|
|
MaxDepth: maxDepth,
|
|
|
|
Unvisited: []RoomHierarchyWalkerQueuedRoom{{
|
|
|
|
RoomID: roomID,
|
|
|
|
ParentRoomID: nil,
|
|
|
|
Depth: 0,
|
|
|
|
}},
|
|
|
|
Processed: NewRoomSet(),
|
|
|
|
}
|
|
|
|
|
|
|
|
return walker
|
|
|
|
}
|
|
|
|
|
|
|
|
// A set of room IDs.
|
|
|
|
type RoomSet map[spec.RoomID]struct{}
|
|
|
|
|
|
|
|
// Create a new empty room set.
|
|
|
|
func NewRoomSet() RoomSet {
|
|
|
|
return RoomSet{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if a room ID is in a room set.
|
|
|
|
func (s RoomSet) Contains(val spec.RoomID) bool {
|
|
|
|
_, ok := s[val]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a room ID to a room set.
|
|
|
|
func (s RoomSet) Add(val spec.RoomID) {
|
|
|
|
s[val] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s RoomSet) Copy() RoomSet {
|
|
|
|
copied := make(RoomSet, len(s))
|
|
|
|
for k := range s {
|
|
|
|
copied.Add(k)
|
|
|
|
}
|
|
|
|
return copied
|
|
|
|
}
|