mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Add room_list API stubs
This commit is contained in:
parent
2916a5274e
commit
35ce28bb96
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -21,6 +22,7 @@ import (
|
||||
var postgresConnectionString = "user=xxxxx dbname=syncv3_test sslmode=disable"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
runtime.SetCPUProfileRate(10000)
|
||||
postgresConnectionString = testutils.PrepareDBConnectionString("syncv3_test_main")
|
||||
exitCode := m.Run()
|
||||
os.Exit(exitCode)
|
||||
|
@ -39,9 +39,6 @@ func (r *Request) ApplyDeltas(req2 *Request) (bool, error) {
|
||||
return !bytes.Equal(original, combined), nil
|
||||
}
|
||||
|
||||
// Sentinel value indicating the first page of results.
|
||||
const FirstPage = "0"
|
||||
|
||||
// P is the pagination struct for streams
|
||||
type P struct {
|
||||
Next string `json:"next,omitempty"`
|
||||
|
@ -5,4 +5,5 @@ type Response struct {
|
||||
Typing *TypingResponse `json:"typing,omitempty"`
|
||||
ToDevice *ToDeviceResponse `json:"to_device,omitempty"`
|
||||
RoomMember *RoomMemberResponse `json:"room_member,omitempty"`
|
||||
RoomList *RoomListResponse `json:"room_list,omitempty"`
|
||||
}
|
||||
|
@ -1,6 +1,68 @@
|
||||
package streams
|
||||
|
||||
import "github.com/matrix-org/sync-v3/state"
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/sync-v3/state"
|
||||
"github.com/matrix-org/sync-v3/sync3"
|
||||
)
|
||||
|
||||
type RoomListSortOrder string
|
||||
|
||||
const (
|
||||
// Sort rooms based on the most recent event in the room. Newer first.
|
||||
SortRoomListByRecency RoomListSortOrder = "by_recent"
|
||||
// Sort rooms based on their tag in this user's account data.
|
||||
// Follows the `order` value if one exists. Lower first.
|
||||
// See https://matrix.org/docs/spec/client_server/latest#room-tagging
|
||||
SortRoomListByTag RoomListSortOrder = "by_tag"
|
||||
)
|
||||
|
||||
// FilterRoomList represents a filter on the RoomList stream
|
||||
type FilterRoomList struct {
|
||||
// Which event types should be returned as the latest event in the room.
|
||||
// Clients should include only events they know how to render here.
|
||||
// Empty set = everything
|
||||
LastEventTypes []string `json:"last_event_types"`
|
||||
// The number of rooms to return per request.
|
||||
// Clients should return at least 1 screen's worth of data (based on viewport size)
|
||||
// Server can override this value.
|
||||
Limit int `json:"limit"`
|
||||
// how to sort the rooms in the response. The first sort option is applied first, then any identical
|
||||
// values are sorted by the next sort option and so on. E.g [by_tag, by_recent] sorts the rooms by
|
||||
// tags first (abiding by the 'order' in the spec) then sorts matching tags by most recent first
|
||||
Sorts []RoomListSortOrder `json:"sorts"`
|
||||
// If true, return the m.room.name event if one exists
|
||||
// Low bandwidth clients may prefer just the `name` key on this event, and the ability to force
|
||||
// a truncation of the key if the name is too long, but this cannot be done in E2E rooms hence
|
||||
// this option is not presented in this stream.
|
||||
IncludeRoomName bool `json:"include_name"`
|
||||
// If true, return the m.room.avatar event if one exists
|
||||
IncludeRoomAvatar bool `json:"include_avatar"`
|
||||
// The pagination parameters to request the next page of results.
|
||||
P *P `json:"p,omitempty"`
|
||||
}
|
||||
|
||||
type RoomListResponse struct {
|
||||
// Negotiated values
|
||||
Limit int `json:"limit"`
|
||||
RoomNameSize int `json:"room_name_size"`
|
||||
Sorts []RoomListSortOrder `json:"sorts"`
|
||||
// The rooms
|
||||
Rooms []RoomListEntry `json:"rooms"`
|
||||
// The pagination parameters to request the next page, can be empty if all rooms fit on one page.
|
||||
P *P `json:"p,omitempty"`
|
||||
}
|
||||
|
||||
type RoomListEntry struct {
|
||||
RoomID string `json:"room_id"`
|
||||
NameEvent json.RawMessage `json:"m.room.name,omitempty"`
|
||||
AvatarEvent json.RawMessage `json:"m.room.avatar,omitempty"`
|
||||
MemberCount int `json:"member_count"`
|
||||
LastEvent json.RawMessage `json:"last_event"`
|
||||
RoomType string `json:"room_type"` // e.g spaces
|
||||
IsDM bool `json:"dm"` // from the m.direct event in account data
|
||||
}
|
||||
|
||||
// RoomList represents a stream of room summaries.
|
||||
// This stream is paginatable.
|
||||
@ -12,34 +74,24 @@ func NewRoomList(s *state.Storage) *RoomList {
|
||||
return &RoomList{s}
|
||||
}
|
||||
|
||||
// FilterRoomList represents a filter on the RoomList stream
|
||||
type FilterRoomList struct {
|
||||
// Which event types should be returned as the latest event in the room.
|
||||
// Clients should include only events they know how to render here.
|
||||
// Empty set = everything
|
||||
SummaryEventTypes []string
|
||||
// The number of rooms to return per request.
|
||||
// Clients should return at least 1 screen's worth of data (based on viewport size)
|
||||
// Server can override this value.
|
||||
EntriesPerBatch int
|
||||
// The max length of the room name. If the name is higher than this, it will be truncated with
|
||||
// unicode ellipsis.
|
||||
// Clients should limit the size to how much they can display (e.g 70 chars)
|
||||
RoomNameSize int
|
||||
// True to include the MXC URI for the room avatar, if it has one.
|
||||
IncludeRoomAvatarMXC *bool
|
||||
func (s *RoomList) Position(tok *sync3.Token) int64 {
|
||||
return tok.EventPosition()
|
||||
}
|
||||
|
||||
type ControlMessageRoomList struct {
|
||||
EntriesPerBatch *int `json:"entries_per_batch,omitempty"`
|
||||
Upcoming string `json:"upcoming"`
|
||||
NextPage string `json:"next_page"`
|
||||
func (s *RoomList) SetPosition(tok *sync3.Token, pos int64) {
|
||||
tok.SetEventPosition(pos)
|
||||
}
|
||||
|
||||
// Process a room list stream request
|
||||
func (s *RoomList) Process(userID string, from, to int64, page string, f *FilterRoomList) (ctrl *ControlMessageRoomList, result string, err error) {
|
||||
if from == 0 {
|
||||
func (s *RoomList) IsPaginationRequest(req *Request) bool {
|
||||
return req.RoomList != nil && req.RoomList.P != nil && req.RoomList.P.Next != ""
|
||||
}
|
||||
|
||||
func (s *RoomList) SessionConfirmed(session *sync3.Session, confirmedPos int64, allSessions bool) {
|
||||
}
|
||||
|
||||
func (s *RoomList) DataInRange(session *sync3.Session, fromExcl, toIncl int64, request *Request, resp *Response) (int64, error) {
|
||||
if request.RoomList == nil {
|
||||
return 0, ErrNotRequested
|
||||
}
|
||||
return nil, "", nil
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultRoomMemberLimit = 50
|
||||
maxRoomMemberLimit = 1000
|
||||
DefaultRoomMemberLimit = 50
|
||||
MaxRoomMemberLimit = 1000
|
||||
)
|
||||
|
||||
type FilterRoomMember struct {
|
||||
@ -118,11 +118,11 @@ func (s *RoomMember) DataInRange(session *sync3.Session, fromExcl, toIncl int64,
|
||||
return 0, ErrNotRequested
|
||||
}
|
||||
// ensure limit is always set
|
||||
if request.RoomMember.Limit > maxRoomMemberLimit {
|
||||
request.RoomMember.Limit = maxRoomMemberLimit
|
||||
if request.RoomMember.Limit > MaxRoomMemberLimit {
|
||||
request.RoomMember.Limit = MaxRoomMemberLimit
|
||||
}
|
||||
if request.RoomMember.Limit <= 0 {
|
||||
request.RoomMember.Limit = defaultRoomMemberLimit
|
||||
request.RoomMember.Limit = DefaultRoomMemberLimit
|
||||
}
|
||||
if request.RoomMember.P == nil && fromExcl != 0 {
|
||||
return s.streamingDataInRange(session, fromExcl, toIncl, request, resp)
|
||||
|
1
v3.go
1
v3.go
@ -118,6 +118,7 @@ func NewSyncV3Handler(v2Client sync2.Client, postgresDBURI string) *SyncV3Handle
|
||||
sh.streams = append(sh.streams, streams.NewTyping(sh.Storage))
|
||||
sh.streams = append(sh.streams, streams.NewToDevice(sh.Storage))
|
||||
sh.streams = append(sh.streams, streams.NewRoomMember(sh.Storage))
|
||||
sh.streams = append(sh.streams, streams.NewRoomList(sh.Storage))
|
||||
|
||||
latestToken := sync3.NewBlankSyncToken(0, 0)
|
||||
nid, err := sh.Storage.LatestEventNID()
|
||||
|
Loading…
x
Reference in New Issue
Block a user