2018-01-02 10:26:56 +00:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// 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 publicroomsapi
|
|
|
|
|
|
|
|
import (
|
2020-06-09 11:07:33 +00:00
|
|
|
"github.com/Shopify/sarama"
|
2020-06-08 14:51:07 +00:00
|
|
|
"github.com/gorilla/mux"
|
2018-01-02 10:26:56 +00:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
2020-06-09 11:07:33 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/config"
|
2020-01-24 17:11:20 +00:00
|
|
|
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
|
2018-01-02 10:26:56 +00:00
|
|
|
"github.com/matrix-org/dendrite/publicroomsapi/routing"
|
|
|
|
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
2020-03-19 11:04:08 +00:00
|
|
|
"github.com/matrix-org/dendrite/publicroomsapi/types"
|
2020-01-24 17:11:20 +00:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-03-19 11:04:08 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2018-01-02 10:26:56 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2020-06-08 14:51:07 +00:00
|
|
|
// AddPublicRoutes sets up and registers HTTP handlers for the PublicRoomsAPI
|
2018-01-02 10:26:56 +00:00
|
|
|
// component.
|
2020-06-08 14:51:07 +00:00
|
|
|
func AddPublicRoutes(
|
|
|
|
router *mux.Router,
|
2020-06-09 11:07:33 +00:00
|
|
|
cfg *config.Dendrite,
|
|
|
|
consumer sarama.Consumer,
|
2020-02-13 17:27:33 +00:00
|
|
|
deviceDB devices.Database,
|
2020-04-14 15:15:59 +00:00
|
|
|
publicRoomsDB storage.Database,
|
2020-05-01 09:48:17 +00:00
|
|
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
2020-03-19 11:04:08 +00:00
|
|
|
fedClient *gomatrixserverlib.FederationClient,
|
|
|
|
extRoomsProvider types.ExternalPublicRoomsProvider,
|
2018-01-02 10:26:56 +00:00
|
|
|
) {
|
2020-01-24 17:11:20 +00:00
|
|
|
rsConsumer := consumers.NewOutputRoomEventConsumer(
|
2020-06-09 11:07:33 +00:00
|
|
|
cfg, consumer, publicRoomsDB, rsAPI,
|
2020-01-24 17:11:20 +00:00
|
|
|
)
|
2020-04-14 15:15:59 +00:00
|
|
|
if err := rsConsumer.Start(); err != nil {
|
2020-01-24 17:11:20 +00:00
|
|
|
logrus.WithError(err).Panic("failed to start public rooms server consumer")
|
|
|
|
}
|
|
|
|
|
2020-06-08 14:51:07 +00:00
|
|
|
routing.Setup(router, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
|
2018-01-02 10:26:56 +00:00
|
|
|
}
|