mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-10 16:33:11 -06:00
Basic API for handling room directory
This commit is contained in:
parent
584ebe7725
commit
24a529bb42
|
|
@ -49,7 +49,7 @@ type GetPublicRoomsRequest struct {
|
|||
|
||||
// GetPublicRoomsResponse is a response to GetPublicRooms
|
||||
type GetPublicRoomsResponse struct {
|
||||
Chunk []PublicRoomsChunk `json:"chunk"`
|
||||
Chunks []PublicRoomsChunk `json:"chunk"`
|
||||
NextBatch string `json:"next_batch"`
|
||||
PrevBatch string `json:"prev_batch"`
|
||||
TotalRoomCountEstimate int64 `json:"total_room_count_estimate"`
|
||||
|
|
@ -57,15 +57,15 @@ type GetPublicRoomsResponse struct {
|
|||
|
||||
// PublicRoomsChunk implements the PublicRoomsChunk structure from the Matrix spec
|
||||
type PublicRoomsChunk struct {
|
||||
RoomID string `json:"room_id"`
|
||||
Aliases []string `json:"aliases"`
|
||||
CanonicalAlias string `json:"canonical_alias"`
|
||||
Name string `json:"name"`
|
||||
Topic string `json:"topic"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
JoinedMembers int64 `json:"num_joined_members"`
|
||||
WorldReadable bool `json:"world_readable"`
|
||||
GuestCanJoin bool `json:"guest_can_join"`
|
||||
RoomID string `json:"room_id"`
|
||||
Aliases []string `json:"aliases"`
|
||||
CanonicalAlias string `json:"canonical_alias"`
|
||||
Name string `json:"name"`
|
||||
Topic string `json:"topic"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
NumJoinedMembers int64 `json:"num_joined_members"`
|
||||
WorldReadable bool `json:"world_readable"`
|
||||
GuestCanJoin bool `json:"guest_can_join"`
|
||||
}
|
||||
|
||||
// RoomserverPublicRoomAPI is used to update or retrieve the visibility setting
|
||||
|
|
|
|||
|
|
@ -108,6 +108,29 @@ func (r *RoomserverPublicRoomAPI) GetPublicRooms(
|
|||
req *api.GetPublicRoomsRequest,
|
||||
response *api.GetPublicRoomsResponse,
|
||||
) error {
|
||||
roomIDs, err := r.DB.GetPublicRoomIDs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rooms, err := r.DB.GetAliasesFromRoomIDs(roomIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var chunks []api.PublicRoomsChunk
|
||||
for room, aliases := range rooms {
|
||||
chunk := api.PublicRoomsChunk{
|
||||
RoomID: room,
|
||||
Aliases: aliases,
|
||||
NumJoinedMembers: 0,
|
||||
WorldReadable: true,
|
||||
GuestCanJoin: true,
|
||||
}
|
||||
chunks = append(chunks, chunk)
|
||||
}
|
||||
|
||||
response.Chunks = chunks
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue