mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-24 03:12:20 +00:00
Move Sync method to user method
This commit is contained in:
parent
d3f90c8eda
commit
585ccbc332
@ -15,7 +15,6 @@ type Backend interface {
|
|||||||
GetUserByToken(token string) (user User)
|
GetUserByToken(token string) (user User)
|
||||||
GetUserByName(userName string) User
|
GetUserByName(userName string) User
|
||||||
GetRoomByID(id string) Room
|
GetRoomByID(id string) Room
|
||||||
Sync(token string, request sync.SyncRequest) (response *sync.SyncReply, err models.ApiError)
|
|
||||||
PublicRooms(filter string) []Room
|
PublicRooms(filter string) []Room
|
||||||
ValidateUsernameFunc() func(string) error
|
ValidateUsernameFunc() func(string) error
|
||||||
GetEventByID(id string) events.Event
|
GetEventByID(id string) events.Event
|
||||||
@ -59,4 +58,5 @@ type User interface {
|
|||||||
GetFilterByID(filterID string) *common.Filter
|
GetFilterByID(filterID string) *common.Filter
|
||||||
AddRoomAlias(Room, string) models.ApiError
|
AddRoomAlias(Room, string) models.ApiError
|
||||||
DeleteRoomAlias(string) models.ApiError
|
DeleteRoomAlias(string) models.ApiError
|
||||||
|
Sync(token string, request sync.SyncRequest) (response *sync.SyncReply, err models.ApiError)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/signaller-matrix/signaller/internal/models/common"
|
"github.com/signaller-matrix/signaller/internal/models/common"
|
||||||
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
||||||
"github.com/signaller-matrix/signaller/internal/models/events"
|
"github.com/signaller-matrix/signaller/internal/models/events"
|
||||||
mSync "github.com/signaller-matrix/signaller/internal/models/sync"
|
|
||||||
"github.com/wangjia184/sortedset"
|
"github.com/wangjia184/sortedset"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,13 +88,6 @@ func (backend *Backend) Login(username, password, device string) (user internal.
|
|||||||
return user, token, nil
|
return user, token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) Sync(token string, request mSync.SyncRequest) (response *mSync.SyncReply, err models.ApiError) {
|
|
||||||
backend.mutex.Lock()
|
|
||||||
defer backend.mutex.Unlock()
|
|
||||||
|
|
||||||
return nil, nil // TODO: implement
|
|
||||||
}
|
|
||||||
|
|
||||||
func (backend *Backend) GetUserByToken(token string) internal.User {
|
func (backend *Backend) GetUserByToken(token string) internal.User {
|
||||||
backend.mutex.RLock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.RUnlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
"github.com/signaller-matrix/signaller/internal/models/createroom"
|
||||||
"github.com/signaller-matrix/signaller/internal/models/devices"
|
"github.com/signaller-matrix/signaller/internal/models/devices"
|
||||||
"github.com/signaller-matrix/signaller/internal/models/events"
|
"github.com/signaller-matrix/signaller/internal/models/events"
|
||||||
|
mSync "github.com/signaller-matrix/signaller/internal/models/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
@ -351,3 +352,7 @@ func (user *User) GetFilterByID(filterID string) *common.Filter {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) Sync(token string, request mSync.SyncRequest) (response *mSync.SyncReply, err models.ApiError) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -281,18 +281,24 @@ func SyncHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
timeout, err := strconv.Atoi(r.FormValue("timeout"))
|
timeout, err := strconv.Atoi(r.FormValue("timeout"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResponse(w, models.M_UNKNOWN, http.StatusBadRequest, "timeout parse failes")
|
errorResponse(w, models.M_UNKNOWN, http.StatusBadRequest, "timeout parse failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
request.Timeout = timeout
|
request.Timeout = timeout
|
||||||
|
|
||||||
token := getTokenFromResponse(r)
|
token := getTokenFromResponse(r)
|
||||||
if token == "" {
|
if token == "" {
|
||||||
errorResponse(w, models.M_MISSING_TOKEN, http.StatusBadRequest, "")
|
errorResponse(w, models.M_FORBIDDEN, http.StatusForbidden, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response, _ := currServer.Backend.Sync(token, request) // TODO: handle error
|
user := currServer.Backend.GetUserByToken(token)
|
||||||
|
if user == nil {
|
||||||
|
errorResponse(w, models.M_UNKNOWN_TOKEN, http.StatusBadRequest, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response, _ := user.Sync(token, request) // TODO: handle error
|
||||||
|
|
||||||
response.NextBatch = "123"
|
response.NextBatch = "123"
|
||||||
response.Rooms = mSync.RoomsSyncReply{}
|
response.Rooms = mSync.RoomsSyncReply{}
|
||||||
|
Loading…
Reference in New Issue
Block a user