mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 06:43:09 -06:00
Merge branch 'master' into neilalexander/rsjoininput
This commit is contained in:
commit
746c113530
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
currentstateAPI "github.com/matrix-org/dendrite/currentstateserver/api"
|
||||
"github.com/matrix-org/dendrite/internal/config"
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
|
@ -41,6 +42,7 @@ type PublicRoomReq struct {
|
|||
Since string `json:"since,omitempty"`
|
||||
Limit int16 `json:"limit,omitempty"`
|
||||
Filter filter `json:"filter,omitempty"`
|
||||
Server string `json:"server,omitempty"`
|
||||
}
|
||||
|
||||
type filter struct {
|
||||
|
|
@ -51,11 +53,28 @@ type filter struct {
|
|||
func GetPostPublicRooms(
|
||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI, stateAPI currentstateAPI.CurrentStateInternalAPI,
|
||||
extRoomsProvider api.ExtraPublicRoomsProvider,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
cfg *config.ClientAPI,
|
||||
) util.JSONResponse {
|
||||
var request PublicRoomReq
|
||||
if fillErr := fillPublicRoomsReq(req, &request); fillErr != nil {
|
||||
return *fillErr
|
||||
}
|
||||
|
||||
serverName := gomatrixserverlib.ServerName(request.Server)
|
||||
|
||||
if serverName != "" && serverName != cfg.Matrix.ServerName {
|
||||
res, err := federation.GetPublicRooms(req.Context(), serverName, int(request.Limit), request.Since, false, "")
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("failed to get public rooms")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: res,
|
||||
}
|
||||
}
|
||||
|
||||
response, err := publicRooms(req.Context(), request, rsAPI, stateAPI, extRoomsProvider)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Errorf("failed to work out public rooms")
|
||||
|
|
@ -98,6 +117,8 @@ func publicRooms(ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI
|
|||
|
||||
response.TotalRoomCountEstimate = len(rooms)
|
||||
|
||||
rooms = filterRooms(rooms, request.Filter.SearchTerms)
|
||||
|
||||
chunk, prev, next := sliceInto(rooms, offset, limit)
|
||||
if prev >= 0 {
|
||||
response.PrevBatch = "T" + strconv.Itoa(prev)
|
||||
|
|
@ -111,6 +132,25 @@ func publicRooms(ctx context.Context, request PublicRoomReq, rsAPI roomserverAPI
|
|||
return &response, err
|
||||
}
|
||||
|
||||
func filterRooms(rooms []gomatrixserverlib.PublicRoom, searchTerm string) []gomatrixserverlib.PublicRoom {
|
||||
if searchTerm == "" {
|
||||
return rooms
|
||||
}
|
||||
|
||||
normalizedTerm := strings.ToLower(searchTerm)
|
||||
|
||||
result := make([]gomatrixserverlib.PublicRoom, 0)
|
||||
for _, room := range rooms {
|
||||
if strings.Contains(strings.ToLower(room.Name), normalizedTerm) ||
|
||||
strings.Contains(strings.ToLower(room.Topic), normalizedTerm) ||
|
||||
strings.Contains(strings.ToLower(room.CanonicalAlias), normalizedTerm) {
|
||||
result = append(result, room)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// fillPublicRoomsReq fills the Limit, Since and Filter attributes of a GET or POST request
|
||||
// on /publicRooms by parsing the incoming HTTP request
|
||||
// Filter is only filled for POST requests
|
||||
|
|
@ -134,11 +174,13 @@ func fillPublicRoomsReq(httpReq *http.Request, request *PublicRoomReq) *util.JSO
|
|||
}
|
||||
request.Limit = int16(limit)
|
||||
request.Since = httpReq.FormValue("since")
|
||||
request.Server = httpReq.FormValue("server")
|
||||
} else {
|
||||
resErr := httputil.UnmarshalJSONRequest(httpReq, request)
|
||||
if resErr != nil {
|
||||
return resErr
|
||||
}
|
||||
request.Server = httpReq.FormValue("server")
|
||||
}
|
||||
|
||||
// strip the 'T' which is only required because when sytest does pagination tests it stops
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ func Setup(
|
|||
).Methods(http.MethodPut, http.MethodOptions)
|
||||
r0mux.Handle("/publicRooms",
|
||||
httputil.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
|
||||
return GetPostPublicRooms(req, rsAPI, stateAPI, extRoomsProvider)
|
||||
return GetPostPublicRooms(req, rsAPI, stateAPI, extRoomsProvider, federation, cfg)
|
||||
}),
|
||||
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||
|
||||
|
|
|
|||
|
|
@ -104,8 +104,6 @@ type Database interface {
|
|||
// matches the streamevent.transactionID device then the transaction ID gets
|
||||
// added to the unsigned section of the output event.
|
||||
StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []gomatrixserverlib.HeaderedEvent
|
||||
// SyncStreamPosition returns the latest position in the sync stream. Returns 0 if there are no events yet.
|
||||
SyncStreamPosition(ctx context.Context) (types.StreamPosition, error)
|
||||
// AddSendToDevice increases the EDU position in the cache and returns the stream position.
|
||||
AddSendToDevice() types.StreamPosition
|
||||
// SendToDeviceUpdatesForSync returns a list of send-to-device updates. It returns three lists:
|
||||
|
|
|
|||
|
|
@ -133,35 +133,6 @@ func (d *Database) GetStateEventsForRoom(
|
|||
return
|
||||
}
|
||||
|
||||
func (d *Database) SyncStreamPosition(ctx context.Context) (types.StreamPosition, error) {
|
||||
var maxID int64
|
||||
var err error
|
||||
err = sqlutil.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
maxID, err = d.OutputEvents.SelectMaxEventID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var maxAccountDataID int64
|
||||
maxAccountDataID, err = d.AccountData.SelectMaxAccountDataID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maxAccountDataID > maxID {
|
||||
maxID = maxAccountDataID
|
||||
}
|
||||
var maxInviteID int64
|
||||
maxInviteID, err = d.Invites.SelectMaxInviteID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maxInviteID > maxID {
|
||||
maxID = maxInviteID
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return types.StreamPosition(maxID), err
|
||||
}
|
||||
|
||||
// AddInviteEvent stores a new invite event for a user.
|
||||
// If the invite was successfully stored this returns the stream ID it was stored at.
|
||||
// Returns an error if there was a problem communicating with the database.
|
||||
|
|
|
|||
|
|
@ -457,3 +457,6 @@ Inbound /v1/send_leave rejects leaves from other servers
|
|||
Guest users can accept invites to private rooms over federation
|
||||
AS user (not ghost) can join room without registering
|
||||
If user leaves room, remote user changes device and rejoins we see update in /sync and /keys/changes
|
||||
Can search public room list
|
||||
Can get remote public room list
|
||||
Asking for a remote rooms list, but supplying the local server's name, returns the local rooms list
|
||||
|
|
|
|||
Loading…
Reference in a new issue