Move a couple of callers to helpers.IsServerCurrentlyInRoom over to the query API (#1912)

This commit is contained in:
Neil Alexander 2021-07-09 17:49:59 +01:00 committed by GitHub
parent 1ed732cc78
commit acec6fa979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 5 deletions

View file

@ -50,6 +50,10 @@ func UpdateToInviteMembership(
return updates, nil
}
// IsServerCurrentlyInRoom checks if a server is in a given room, based on the room
// memberships. If the servername is not supplied then the local server will be
// checked instead using a faster code path.
// TODO: This should probably be replaced by an API call.
func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverName gomatrixserverlib.ServerName, roomID string) (bool, error) {
info, err := db.RoomInfo(ctx, roomID)
if err != nil {
@ -59,6 +63,10 @@ func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverNam
return false, fmt.Errorf("unknown room %s", roomID)
}
if serverName == "" {
return db.GetLocalServerInRoom(ctx, info.RoomNID)
}
eventNIDs, err := db.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, true, false)
if err != nil {
return false, err