matrix continuation lives in db not config file

master
Bel LaPointe 2022-01-14 08:48:09 -05:00
parent cf421e414c
commit 442e8c2992
5 changed files with 23 additions and 11 deletions

View File

@ -62,7 +62,6 @@
"Matrix": { "Matrix": {
"ReceiveEnabled": true, "ReceiveEnabled": true,
"Mock": false, "Mock": false,
"Continuation": "1420",
"Homeserver": "https://m.bltrucks.top", "Homeserver": "https://m.bltrucks.top",
"Username": "@bot.m.bltrucks.top", "Username": "@bot.m.bltrucks.top",
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS", "Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",

View File

@ -41,7 +41,6 @@ type Config struct {
Matrix struct { Matrix struct {
ReceiveEnabled bool ReceiveEnabled bool
Mock bool Mock bool
Continuation string
Homeserver string Homeserver string
Username string Username string
Token string Token string

View File

@ -141,11 +141,7 @@ func matrixrecv() error {
} }
setNewPauses(pauses) setNewPauses(pauses)
}() }()
conf := *config.Get() message.SetMatrixContinuation(sender.Continuation())
if conf.Message.Matrix.Continuation != sender.Continuation() {
conf.Message.Matrix.Continuation = sender.Continuation()
config.Set(conf)
}
return nil return nil
} }

View File

@ -31,7 +31,7 @@ func NewMatrix() Matrix {
token: conf.Token, token: conf.Token,
room: conf.Room, room: conf.Room,
mock: conf.Mock, mock: conf.Mock,
continuation: conf.Continuation, continuation: GetMatrixContinuation(),
} }
} }
@ -71,11 +71,11 @@ func (m *Matrix) Receive() ([]Message, error) {
return nil, err return nil, err
} }
messages := make([]Message, 0) 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 { if err != nil {
return nil, err 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 m.continuation = result.End
for _, event := range result.Chunk { for _, event := range result.Chunk {
//log.Printf("%+v", event) //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) log.Printf("sent image %s => %s: %+v", uri, publicURI, resp)
return err 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"
}

View File

@ -1,5 +1,4 @@
todo: todo:
- tokens in db, not in config
- mark jobs no longer avail by modifying - mark jobs no longer avail by modifying
- write-as for clients so ma can write to pa by default - 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 - 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 - banlist criteria like vendors, brokers, metadata
- set up copy for caleb, broc - set up copy for caleb, broc
done: done:
- tokens in db, not in config
- cache on disk jobinfo - cache on disk jobinfo
- link to view more - link to view more
- map with to-from line - map with to-from line