diff --git a/config.json b/config.json index 29afc8f..7154044 100644 --- a/config.json +++ b/config.json @@ -62,7 +62,6 @@ "Matrix": { "ReceiveEnabled": true, "Mock": false, - "Continuation": "1420", "Homeserver": "https://m.bltrucks.top", "Username": "@bot.m.bltrucks.top", "Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS", diff --git a/config/config.go b/config/config.go index 31c3019..c4ffc49 100644 --- a/config/config.go +++ b/config/config.go @@ -41,7 +41,6 @@ type Config struct { Matrix struct { ReceiveEnabled bool Mock bool - Continuation string Homeserver string Username string Token string diff --git a/main.go b/main.go index dc39cf2..c211343 100644 --- a/main.go +++ b/main.go @@ -141,11 +141,7 @@ func matrixrecv() error { } setNewPauses(pauses) }() - conf := *config.Get() - if conf.Message.Matrix.Continuation != sender.Continuation() { - conf.Message.Matrix.Continuation = sender.Continuation() - config.Set(conf) - } + message.SetMatrixContinuation(sender.Continuation()) return nil } diff --git a/message/matrix.go b/message/matrix.go index 4d0a208..176d12f 100644 --- a/message/matrix.go +++ b/message/matrix.go @@ -31,7 +31,7 @@ func NewMatrix() Matrix { token: conf.Token, room: conf.Room, mock: conf.Mock, - continuation: conf.Continuation, + continuation: GetMatrixContinuation(), } } @@ -71,11 +71,11 @@ func (m *Matrix) Receive() ([]Message, error) { return nil, err } messages := make([]Message, 0) - result, err := c.Messages(m.room, "999999999999999999", m.continuation, 'b', 50) + result, err := c.Messages(m.room, "999999999999999999", m.Continuation(), 'b', 50) if err != nil { return nil, err } - log.Printf("%s => {Start:%s End:%v};; %v, (%d)", m.continuation, result.Start, result.End, err, len(result.Chunk)) + log.Printf("%s => {Start:%s End:%v};; %v, (%d)", m.Continuation(), result.Start, result.End, err, len(result.Chunk)) m.continuation = result.End for _, event := range result.Chunk { //log.Printf("%+v", event) @@ -161,3 +161,21 @@ func (m Matrix) SendImage(uri string) error { log.Printf("sent image %s => %s: %+v", uri, publicURI, resp) return err } + +func SetMatrixContinuation(continuation string) { + db := config.Get().DB() + db.Set(getMatrixContinuationKey(), []byte(continuation)) +} + +func GetMatrixContinuation() string { + db := config.Get().DB() + b, _ := db.Get(getMatrixContinuationKey()) + if b == nil { + return "0" + } + return string(b) +} + +func getMatrixContinuationKey() string { + return "matrix_continuation" +} diff --git a/todo.yaml b/todo.yaml index cd44882..310693f 100644 --- a/todo.yaml +++ b/todo.yaml @@ -1,5 +1,4 @@ todo: -- tokens in db, not in config - mark jobs no longer avail by modifying - write-as for clients so ma can write to pa by default - continuation is garbo, but I can still do better client side to avoid get-set high level @@ -23,6 +22,7 @@ todo: - banlist criteria like vendors, brokers, metadata - set up copy for caleb, broc done: +- tokens in db, not in config - cache on disk jobinfo - link to view more - map with to-from line