mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -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
|
// GetPublicRoomsResponse is a response to GetPublicRooms
|
||||||
type GetPublicRoomsResponse struct {
|
type GetPublicRoomsResponse struct {
|
||||||
Chunk []PublicRoomsChunk `json:"chunk"`
|
Chunks []PublicRoomsChunk `json:"chunk"`
|
||||||
NextBatch string `json:"next_batch"`
|
NextBatch string `json:"next_batch"`
|
||||||
PrevBatch string `json:"prev_batch"`
|
PrevBatch string `json:"prev_batch"`
|
||||||
TotalRoomCountEstimate int64 `json:"total_room_count_estimate"`
|
TotalRoomCountEstimate int64 `json:"total_room_count_estimate"`
|
||||||
|
|
@ -57,15 +57,15 @@ type GetPublicRoomsResponse struct {
|
||||||
|
|
||||||
// PublicRoomsChunk implements the PublicRoomsChunk structure from the Matrix spec
|
// PublicRoomsChunk implements the PublicRoomsChunk structure from the Matrix spec
|
||||||
type PublicRoomsChunk struct {
|
type PublicRoomsChunk struct {
|
||||||
RoomID string `json:"room_id"`
|
RoomID string `json:"room_id"`
|
||||||
Aliases []string `json:"aliases"`
|
Aliases []string `json:"aliases"`
|
||||||
CanonicalAlias string `json:"canonical_alias"`
|
CanonicalAlias string `json:"canonical_alias"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Topic string `json:"topic"`
|
Topic string `json:"topic"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
JoinedMembers int64 `json:"num_joined_members"`
|
NumJoinedMembers int64 `json:"num_joined_members"`
|
||||||
WorldReadable bool `json:"world_readable"`
|
WorldReadable bool `json:"world_readable"`
|
||||||
GuestCanJoin bool `json:"guest_can_join"`
|
GuestCanJoin bool `json:"guest_can_join"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RoomserverPublicRoomAPI is used to update or retrieve the visibility setting
|
// RoomserverPublicRoomAPI is used to update or retrieve the visibility setting
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,29 @@ func (r *RoomserverPublicRoomAPI) GetPublicRooms(
|
||||||
req *api.GetPublicRoomsRequest,
|
req *api.GetPublicRoomsRequest,
|
||||||
response *api.GetPublicRoomsResponse,
|
response *api.GetPublicRoomsResponse,
|
||||||
) error {
|
) 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue