Browse Source

Review comments

pull/60/head
Kegan Dougal 8 years ago
parent
commit
178ae79e29
  1. 2
      src/github.com/matrix-org/go-neb/clients/clients.go
  2. 11
      src/github.com/matrix-org/go-neb/matrix/matrix.go

2
src/github.com/matrix-org/go-neb/clients/clients.go

@ -238,7 +238,7 @@ func (c *Clients) newClient(config types.ClientConfig) (*matrix.Client, error) {
} }
client := matrix.NewClient(homeserverURL, config.AccessToken, config.UserID) client := matrix.NewClient(homeserverURL, config.AccessToken, config.UserID)
client.NextBatch = nextBatchStore{c.db}
client.NextBatchStorer = nextBatchStore{c.db}
// TODO: Check that the access token is valid for the userID by peforming // TODO: Check that the access token is valid for the userID by peforming
// a request against the server. // a request against the server.

11
src/github.com/matrix-org/go-neb/matrix/matrix.go

@ -57,7 +57,7 @@ type Client struct {
syncingID uint32 // Identifies the current Sync. Only one Sync can be active at any given time. syncingID uint32 // Identifies the current Sync. Only one Sync can be active at any given time.
httpClient *http.Client httpClient *http.Client
filterID string filterID string
NextBatch NextBatchStorer
NextBatchStorer NextBatchStorer
} }
func (cli *Client) buildURL(urlPath ...string) string { func (cli *Client) buildURL(urlPath ...string) string {
@ -214,7 +214,7 @@ func (cli *Client) Sync() {
} }
cli.filterID = filterID cli.filterID = filterID
logger.WithField("filter", filterID).Print("Got filter ID") logger.WithField("filter", filterID).Print("Got filter ID")
nextToken := cli.NextBatch.Load(cli.UserID)
nextToken := cli.NextBatchStorer.Load(cli.UserID)
logger.WithField("next_batch", nextToken).Print("Starting sync") logger.WithField("next_batch", nextToken).Print("Starting sync")
@ -261,7 +261,7 @@ func (cli *Client) Sync() {
// Save the token now *before* passing it through to the worker. This means it's possible // Save the token now *before* passing it through to the worker. This means it's possible
// to not process some events, but it means that we won't get constantly stuck processing // to not process some events, but it means that we won't get constantly stuck processing
// a malformed/buggy event which keeps making us panic. // a malformed/buggy event which keeps making us panic.
cli.NextBatch.Save(cli.UserID, nextToken)
cli.NextBatchStorer.Save(cli.UserID, nextToken)
if !isFirstSync { if !isFirstSync {
channel <- syncResponse channel <- syncResponse
@ -390,7 +390,10 @@ func NewClient(homeserverURL *url.URL, accessToken string, userID string) *Clien
Prefix: "/_matrix/client/r0", Prefix: "/_matrix/client/r0",
} }
cli.Worker = newWorker(&cli) cli.Worker = newWorker(&cli)
cli.NextBatch = noopNextBatchStore{}
// By default, use a no-op next_batch storer which will never save tokens and always
// "load" the empty string as a token. The client will work with this storer: it just won't
// remember the token across restarts. In practice, a database backend should be used.
cli.NextBatchStorer = noopNextBatchStore{}
cli.Rooms = make(map[string]*Room) cli.Rooms = make(map[string]*Room)
cli.httpClient = &http.Client{} cli.httpClient = &http.Client{}

Loading…
Cancel
Save