forked from matrix-org/dendrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from globekeeper/DEV-801/recent-locations-endp…
…oint ✨ /location_sync endpoint for fetching recent locations in a room.
- Loading branch information
Showing
7 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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 routing | ||
|
||
import ( | ||
"database/sql" | ||
"net/http" | ||
|
||
"github.com/matrix-org/dendrite/roomserver/api" | ||
"github.com/matrix-org/dendrite/syncapi/storage" | ||
"github.com/matrix-org/dendrite/syncapi/types" | ||
userapi "github.com/matrix-org/dendrite/userapi/api" | ||
"github.com/matrix-org/gomatrixserverlib/spec" | ||
"github.com/matrix-org/util" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members | ||
type getLocationSyncResponse struct { | ||
RecentLocations types.MultiRoom `json:"recent_locations"` | ||
} | ||
|
||
// GetLocationSync return each VISIBLE user's most recent location update in the room. | ||
// This is used for the case of newly joined users which require catching up on location events of users, | ||
// but aren't able to retrieve certain location events from /sync, since they joined after them. | ||
func GetLocationSync( | ||
req *http.Request, device *userapi.Device, roomID string, | ||
syncDB storage.Database, rsAPI api.SyncRoomserverAPI, | ||
) util.JSONResponse { | ||
snapshot, err := syncDB.NewDatabaseSnapshot(req.Context()) | ||
if err != nil { | ||
logrus.WithError(err).Error("Failed to get snapshot for locations sync") | ||
return util.JSONResponse{ | ||
Code: http.StatusInternalServerError, | ||
JSON: spec.InternalServerError{}, | ||
} | ||
} | ||
mr, err := snapshot.SelectAllMultiRoomDataInRoom(req.Context(), roomID) | ||
if err != nil { | ||
if err != sql.ErrNoRows { | ||
util.GetLogger(req.Context()).WithError(err).Error("failed to select all most recent multiroom data for room") | ||
return util.JSONResponse{ | ||
Code: http.StatusInternalServerError, | ||
JSON: spec.InternalServerError{}, | ||
} | ||
} | ||
} | ||
return util.JSONResponse{ | ||
Code: http.StatusOK, | ||
JSON: getLocationSyncResponse{RecentLocations: mr}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters