dendrite/pushserver/producers/syncapi.go
Tommie Gannert f5d8f0e72f Add push rules query/put API in Pushserver.
This manipulates account data over User API, and fires sync messages
for changes. Those sync messages should, according to an existing TODO
in clientapi, be moved to userapi.

Forks clientapi/producers/syncapi.go to pushserver/ for later extension.
2021-12-03 19:43:02 +01:00

42 lines
975 B
Go

package producers
import (
"encoding/json"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/internal/eventutil"
log "github.com/sirupsen/logrus"
)
// SyncAPIProducer produces messages for the Sync API server to consume.
type SyncAPIProducer struct {
Producer sarama.SyncProducer
ClientDataTopic string
}
// SendAccountData sends account data to the Sync API server.
func (p *SyncAPIProducer) SendAccountData(userID string, roomID string, dataType string) error {
var m sarama.ProducerMessage
data := eventutil.AccountData{
RoomID: roomID,
Type: dataType,
}
value, err := json.Marshal(data)
if err != nil {
return err
}
m.Topic = string(p.ClientDataTopic)
m.Key = sarama.StringEncoder(userID)
m.Value = sarama.ByteEncoder(value)
log.WithFields(log.Fields{
"user_id": userID,
"room_id": roomID,
"data_type": dataType,
}).Infof("Producing to topic '%s'", m.Topic)
_, _, err = p.Producer.SendMessage(&m)
return err
}