mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 11:53:09 -06:00
Merge branch 'master' into kegan/syncapi-table-even-moar
This commit is contained in:
commit
292e8bcb6f
34
cmd/dendrite-key-server/main.go
Normal file
34
cmd/dendrite-key-server/main.go
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
|
"github.com/matrix-org/dendrite/keyserver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg := basecomponent.ParseFlags()
|
||||||
|
base := basecomponent.NewBaseDendrite(cfg, "KeyServer")
|
||||||
|
defer base.Close() // nolint: errcheck
|
||||||
|
|
||||||
|
accountDB := base.CreateAccountsDB()
|
||||||
|
deviceDB := base.CreateDeviceDB()
|
||||||
|
|
||||||
|
keyserver.SetupKeyServerComponent(base, deviceDB, accountDB)
|
||||||
|
|
||||||
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.KeyServer), string(base.Cfg.Listen.KeyServer))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
"github.com/matrix-org/dendrite/federationapi"
|
"github.com/matrix-org/dendrite/federationapi"
|
||||||
"github.com/matrix-org/dendrite/federationsender"
|
"github.com/matrix-org/dendrite/federationsender"
|
||||||
|
"github.com/matrix-org/dendrite/keyserver"
|
||||||
"github.com/matrix-org/dendrite/mediaapi"
|
"github.com/matrix-org/dendrite/mediaapi"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi"
|
"github.com/matrix-org/dendrite/publicroomsapi"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
||||||
|
|
@ -76,6 +77,9 @@ func main() {
|
||||||
federation, &keyRing, rsAPI,
|
federation, &keyRing, rsAPI,
|
||||||
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
||||||
)
|
)
|
||||||
|
keyserver.SetupKeyServerComponent(
|
||||||
|
base, deviceDB, accountDB,
|
||||||
|
)
|
||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,7 @@ type Dendrite struct {
|
||||||
FederationSender Address `yaml:"federation_sender"`
|
FederationSender Address `yaml:"federation_sender"`
|
||||||
PublicRoomsAPI Address `yaml:"public_rooms_api"`
|
PublicRoomsAPI Address `yaml:"public_rooms_api"`
|
||||||
EDUServer Address `yaml:"edu_server"`
|
EDUServer Address `yaml:"edu_server"`
|
||||||
|
KeyServer Address `yaml:"key_server"`
|
||||||
} `yaml:"bind"`
|
} `yaml:"bind"`
|
||||||
|
|
||||||
// The addresses for talking to other microservices.
|
// The addresses for talking to other microservices.
|
||||||
|
|
@ -242,6 +243,7 @@ type Dendrite struct {
|
||||||
FederationSender Address `yaml:"federation_sender"`
|
FederationSender Address `yaml:"federation_sender"`
|
||||||
PublicRoomsAPI Address `yaml:"public_rooms_api"`
|
PublicRoomsAPI Address `yaml:"public_rooms_api"`
|
||||||
EDUServer Address `yaml:"edu_server"`
|
EDUServer Address `yaml:"edu_server"`
|
||||||
|
KeyServer Address `yaml:"key_server"`
|
||||||
} `yaml:"listen"`
|
} `yaml:"listen"`
|
||||||
|
|
||||||
// The config for tracing the dendrite servers.
|
// The config for tracing the dendrite servers.
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ listen:
|
||||||
federation_sender: "localhost:7776"
|
federation_sender: "localhost:7776"
|
||||||
appservice_api: "localhost:7777"
|
appservice_api: "localhost:7777"
|
||||||
edu_server: "localhost:7778"
|
edu_server: "localhost:7778"
|
||||||
|
key_server: "localhost:7779"
|
||||||
|
|
||||||
# The configuration for tracing the dendrite components.
|
# The configuration for tracing the dendrite components.
|
||||||
tracing:
|
tracing:
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,16 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
|
|
||||||
|
key_server:
|
||||||
|
container_name: dendrite_key_server
|
||||||
|
hostname: key_server
|
||||||
|
entrypoint: ["bash", "./docker/services/key-server.sh"]
|
||||||
|
build: ./
|
||||||
|
volumes:
|
||||||
|
- ..:/build
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
container_name: dendrite_postgres
|
container_name: dendrite_postgres
|
||||||
hostname: postgres
|
hostname: postgres
|
||||||
|
|
|
||||||
5
docker/services/key-server.sh
Normal file
5
docker/services/key-server.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
bash ./docker/build.sh
|
||||||
|
|
||||||
|
./bin/dendrite-key-server --config dendrite.yaml
|
||||||
32
keyserver/keyserver.go
Normal file
32
keyserver/keyserver.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package keyserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
|
"github.com/matrix-org/dendrite/keyserver/routing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetupFederationSenderComponent sets up and registers HTTP handlers for the
|
||||||
|
// FederationSender component.
|
||||||
|
func SetupKeyServerComponent(
|
||||||
|
base *basecomponent.BaseDendrite,
|
||||||
|
deviceDB devices.Database,
|
||||||
|
accountsDB accounts.Database,
|
||||||
|
) {
|
||||||
|
routing.Setup(base.APIMux, base.Cfg, accountsDB, deviceDB)
|
||||||
|
}
|
||||||
33
keyserver/routing/keys.go
Normal file
33
keyserver/routing/keys.go
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package routing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func QueryKeys(
|
||||||
|
req *http.Request,
|
||||||
|
) util.JSONResponse {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: map[string]interface{}{
|
||||||
|
"failures": map[string]interface{}{},
|
||||||
|
"device_keys": map[string]interface{}{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
56
keyserver/routing/routing.go
Normal file
56
keyserver/routing/routing.go
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package routing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const pathPrefixR0 = "/_matrix/client/r0"
|
||||||
|
|
||||||
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
||||||
|
// to clients which need to make outbound HTTP requests.
|
||||||
|
//
|
||||||
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
||||||
|
// applied:
|
||||||
|
// nolint: gocyclo
|
||||||
|
func Setup(
|
||||||
|
apiMux *mux.Router, cfg *config.Dendrite,
|
||||||
|
accountDB accounts.Database,
|
||||||
|
deviceDB devices.Database,
|
||||||
|
) {
|
||||||
|
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
||||||
|
|
||||||
|
authData := auth.Data{
|
||||||
|
AccountDB: accountDB,
|
||||||
|
DeviceDB: deviceDB,
|
||||||
|
AppServices: cfg.Derived.ApplicationServices,
|
||||||
|
}
|
||||||
|
|
||||||
|
r0mux.Handle("/keys/query",
|
||||||
|
common.MakeAuthAPI("queryKeys", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
|
return QueryKeys(req)
|
||||||
|
}),
|
||||||
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
|
}
|
||||||
|
|
@ -231,8 +231,7 @@ func updateToLeaveMembership(
|
||||||
return updates, nil
|
return updates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// membershipChanges pairs up the membership state changes from a sorted list
|
// membershipChanges pairs up the membership state changes.
|
||||||
// of state removed and a sorted list of state added.
|
|
||||||
func membershipChanges(removed, added []types.StateEntry) []stateChange {
|
func membershipChanges(removed, added []types.StateEntry) []stateChange {
|
||||||
changes := pairUpChanges(removed, added)
|
changes := pairUpChanges(removed, added)
|
||||||
var result []stateChange
|
var result []stateChange
|
||||||
|
|
@ -251,64 +250,39 @@ type stateChange struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pairUpChanges pairs up the state events added and removed for each type,
|
// pairUpChanges pairs up the state events added and removed for each type,
|
||||||
// state key tuple. Assumes that removed and added are sorted.
|
// state key tuple.
|
||||||
func pairUpChanges(removed, added []types.StateEntry) []stateChange {
|
func pairUpChanges(removed, added []types.StateEntry) []stateChange {
|
||||||
var ai int
|
tuples := make(map[types.StateKeyTuple]stateChange)
|
||||||
var ri int
|
changes := []stateChange{}
|
||||||
var result []stateChange
|
|
||||||
for {
|
// First, go through the newly added state entries.
|
||||||
switch {
|
for _, add := range added {
|
||||||
case ai == len(added):
|
if change, ok := tuples[add.StateKeyTuple]; ok {
|
||||||
// We've reached the end of the added entries.
|
// If we already have an entry, update it.
|
||||||
// The rest of the removed list are events that were removed without
|
change.addedEventNID = add.EventNID
|
||||||
// an event with the same state key being added.
|
tuples[add.StateKeyTuple] = change
|
||||||
for _, s := range removed[ri:] {
|
} else {
|
||||||
result = append(result, stateChange{
|
// Otherwise, create a new entry.
|
||||||
StateKeyTuple: s.StateKeyTuple,
|
tuples[add.StateKeyTuple] = stateChange{add.StateKeyTuple, 0, add.EventNID}
|
||||||
removedEventNID: s.EventNID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
case ri == len(removed):
|
|
||||||
// We've reached the end of the removed entries.
|
|
||||||
// The rest of the added list are events that were added without
|
|
||||||
// an event with the same state key being removed.
|
|
||||||
for _, s := range added[ai:] {
|
|
||||||
result = append(result, stateChange{
|
|
||||||
StateKeyTuple: s.StateKeyTuple,
|
|
||||||
addedEventNID: s.EventNID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
case added[ai].StateKeyTuple == removed[ri].StateKeyTuple:
|
|
||||||
// The tuple is in both lists so an event with that key is being
|
|
||||||
// removed and another event with the same key is being added.
|
|
||||||
result = append(result, stateChange{
|
|
||||||
StateKeyTuple: added[ai].StateKeyTuple,
|
|
||||||
removedEventNID: removed[ri].EventNID,
|
|
||||||
addedEventNID: added[ai].EventNID,
|
|
||||||
})
|
|
||||||
ai++
|
|
||||||
ri++
|
|
||||||
case added[ai].StateKeyTuple.LessThan(removed[ri].StateKeyTuple):
|
|
||||||
// The lists are sorted so the added entry being less than the
|
|
||||||
// removed entry means that the added event was added without an
|
|
||||||
// event with the same key being removed.
|
|
||||||
result = append(result, stateChange{
|
|
||||||
StateKeyTuple: added[ai].StateKeyTuple,
|
|
||||||
addedEventNID: added[ai].EventNID,
|
|
||||||
})
|
|
||||||
ai++
|
|
||||||
default:
|
|
||||||
// Reaching the default case implies that the removed entry is less
|
|
||||||
// than the added entry. Since the lists are sorted this means that
|
|
||||||
// the removed event was removed without an event with the same
|
|
||||||
// key being added.
|
|
||||||
result = append(result, stateChange{
|
|
||||||
StateKeyTuple: removed[ai].StateKeyTuple,
|
|
||||||
removedEventNID: removed[ri].EventNID,
|
|
||||||
})
|
|
||||||
ri++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now go through the removed state entries.
|
||||||
|
for _, remove := range removed {
|
||||||
|
if change, ok := tuples[remove.StateKeyTuple]; ok {
|
||||||
|
// If we already have an entry, update it.
|
||||||
|
change.removedEventNID = remove.EventNID
|
||||||
|
tuples[remove.StateKeyTuple] = change
|
||||||
|
} else {
|
||||||
|
// Otherwise, create a new entry.
|
||||||
|
tuples[remove.StateKeyTuple] = stateChange{remove.StateKeyTuple, remove.EventNID, 0}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now return the changes as an array.
|
||||||
|
for _, change := range tuples {
|
||||||
|
changes = append(changes, change)
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,22 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
||||||
return fmt.Errorf("eb.SetContent: %w", err)
|
return fmt.Errorf("eb.SetContent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First work out if this is in response to an existing invite.
|
||||||
|
// If it is then we avoid the situation where we might think we
|
||||||
|
// know about a room in the following section but don't know the
|
||||||
|
// latest state as all of our users have left.
|
||||||
|
isInvitePending, inviteSender, err := r.isInvitePending(ctx, req.RoomIDOrAlias, req.UserID)
|
||||||
|
if err == nil && isInvitePending {
|
||||||
|
// Add the server of the person who invited us to the server list,
|
||||||
|
// as they should be a fairly good bet.
|
||||||
|
if _, inviterDomain, ierr := gomatrixserverlib.SplitID('@', inviteSender); ierr == nil {
|
||||||
|
req.ServerNames = append(req.ServerNames, inviterDomain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform a federated room join.
|
||||||
|
return r.performFederatedJoinRoomByID(ctx, req, res)
|
||||||
|
}
|
||||||
|
|
||||||
// Try to construct an actual join event from the template.
|
// Try to construct an actual join event from the template.
|
||||||
// If this succeeds then it is a sign that the room already exists
|
// If this succeeds then it is a sign that the room already exists
|
||||||
// locally on the homeserver.
|
// locally on the homeserver.
|
||||||
|
|
@ -178,21 +194,32 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
||||||
return fmt.Errorf("Room ID %q does not exist", req.RoomIDOrAlias)
|
return fmt.Errorf("Room ID %q does not exist", req.RoomIDOrAlias)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try joining by all of the supplied server names.
|
// Perform a federated room join.
|
||||||
fedReq := fsAPI.PerformJoinRequest{
|
return r.performFederatedJoinRoomByID(ctx, req, res)
|
||||||
RoomID: req.RoomIDOrAlias, // the room ID to try and join
|
|
||||||
UserID: req.UserID, // the user ID joining the room
|
|
||||||
ServerNames: req.ServerNames, // the server to try joining with
|
|
||||||
Content: req.Content, // the membership event content
|
|
||||||
}
|
|
||||||
fedRes := fsAPI.PerformJoinResponse{}
|
|
||||||
err = r.fsAPI.PerformJoin(ctx, &fedReq, &fedRes)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error joining federated room: %q", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Error joining room %q: %w", req.RoomIDOrAlias, err)
|
// Something else went wrong.
|
||||||
|
return fmt.Errorf("Error joining local room: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoomserverInternalAPI) performFederatedJoinRoomByID(
|
||||||
|
ctx context.Context,
|
||||||
|
req *api.PerformJoinRequest,
|
||||||
|
res *api.PerformJoinResponse, // nolint:unparam
|
||||||
|
) error {
|
||||||
|
// Try joining by all of the supplied server names.
|
||||||
|
fedReq := fsAPI.PerformJoinRequest{
|
||||||
|
RoomID: req.RoomIDOrAlias, // the room ID to try and join
|
||||||
|
UserID: req.UserID, // the user ID joining the room
|
||||||
|
ServerNames: req.ServerNames, // the server to try joining with
|
||||||
|
Content: req.Content, // the membership event content
|
||||||
|
}
|
||||||
|
fedRes := fsAPI.PerformJoinResponse{}
|
||||||
|
if err := r.fsAPI.PerformJoin(ctx, &fedReq, &fedRes); err != nil {
|
||||||
|
return fmt.Errorf("Error joining federated room: %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (r *RoomserverInternalAPI) performLeaveRoomByID(
|
||||||
) error {
|
) error {
|
||||||
// If there's an invite outstanding for the room then respond to
|
// If there's an invite outstanding for the room then respond to
|
||||||
// that.
|
// that.
|
||||||
isInvitePending, senderUser, err := r.isInvitePending(ctx, req, res)
|
isInvitePending, senderUser, err := r.isInvitePending(ctx, req.RoomID, req.UserID)
|
||||||
if err == nil && isInvitePending {
|
if err == nil && isInvitePending {
|
||||||
return r.performRejectInvite(ctx, req, res, senderUser)
|
return r.performRejectInvite(ctx, req, res, senderUser)
|
||||||
}
|
}
|
||||||
|
|
@ -160,23 +160,22 @@ func (r *RoomserverInternalAPI) performRejectInvite(
|
||||||
|
|
||||||
func (r *RoomserverInternalAPI) isInvitePending(
|
func (r *RoomserverInternalAPI) isInvitePending(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *api.PerformLeaveRequest,
|
roomID, userID string,
|
||||||
res *api.PerformLeaveResponse, // nolint:unparam
|
|
||||||
) (bool, string, error) {
|
) (bool, string, error) {
|
||||||
// Look up the room NID for the supplied room ID.
|
// Look up the room NID for the supplied room ID.
|
||||||
roomNID, err := r.DB.RoomNID(ctx, req.RoomID)
|
roomNID, err := r.DB.RoomNID(ctx, roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", fmt.Errorf("r.DB.RoomNID: %w", err)
|
return false, "", fmt.Errorf("r.DB.RoomNID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up the state key NID for the supplied user ID.
|
// Look up the state key NID for the supplied user ID.
|
||||||
targetUserNIDs, err := r.DB.EventStateKeyNIDs(ctx, []string{req.UserID})
|
targetUserNIDs, err := r.DB.EventStateKeyNIDs(ctx, []string{userID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", fmt.Errorf("r.DB.EventStateKeyNIDs: %w", err)
|
return false, "", fmt.Errorf("r.DB.EventStateKeyNIDs: %w", err)
|
||||||
}
|
}
|
||||||
targetUserNID, targetUserFound := targetUserNIDs[req.UserID]
|
targetUserNID, targetUserFound := targetUserNIDs[userID]
|
||||||
if !targetUserFound {
|
if !targetUserFound {
|
||||||
return false, "", fmt.Errorf("missing NID for user %q (%+v)", req.UserID, targetUserNIDs)
|
return false, "", fmt.Errorf("missing NID for user %q (%+v)", userID, targetUserNIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's see if we have an event active for the user in the room. If
|
// Let's see if we have an event active for the user in the room. If
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue