Temporary fix for appservice txnid (Dendrite issue #2718) (#29)

* temporary fix for dendrite regression #2718

* Change comment to match with dendrite main pr

* renamed zion-registration.yaml to zion-appservice.yaml. Change gitignore to ignore this file.

Co-authored-by: Tak Wai Wong <tak@hntlabs.com>
This commit is contained in:
Tak Wai Wong 2022-09-15 13:49:05 -07:00 committed by GitHub
parent 6ffe8147f5
commit 333a5c74c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

1
.gitignore vendored
View file

@ -53,6 +53,7 @@ _testmain.go
# Default configuration file
dendrite.yaml
zion-appservice.yaml
# Database files
*.db

View file

@ -173,13 +173,14 @@ func (s *OutputRoomEventConsumer) sendEvents(
return err
}
// TODO: We should probably be more intelligent and pick something not
// in the control of the event. A NATS timestamp header or something maybe.
txnID := events[0].Event.OriginServerTS()
// If the number of items in the array is different,
// then this should be treated as a different transaction. Incorporate the length
// of events into the transaction ID.
txnID := fmt.Sprintf("%d_%d", events[0].Event.OriginServerTS(), len(transaction))
// Send the transaction to the appservice.
// https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid
address := fmt.Sprintf("%s/transactions/%d?access_token=%s", state.URL, txnID, url.QueryEscape(state.HSToken))
address := fmt.Sprintf("%s/transactions/%s?access_token=%s", state.URL, txnID, url.QueryEscape(state.HSToken))
req, err := http.NewRequestWithContext(ctx, "PUT", address, bytes.NewBuffer(transaction))
if err != nil {
return err