mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
Implement typing over federation (#949)
Also fix a pet peeve of mine: not putting units on things!!! Manually tested on p2p and works well, with some fudge factor delay.
This commit is contained in:
parent
11a8059bba
commit
8fbe9f4078
10 changed files with 75 additions and 25 deletions
|
@ -41,12 +41,13 @@ func SetupFederationAPIComponent(
|
|||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
federationSenderAPI federationSenderAPI.FederationSenderQueryAPI,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
) {
|
||||
roomserverProducer := producers.NewRoomserverProducer(inputAPI, queryAPI)
|
||||
|
||||
routing.Setup(
|
||||
base.APIMux, base.Cfg, queryAPI, aliasAPI, asAPI,
|
||||
roomserverProducer, federationSenderAPI, *keyRing,
|
||||
roomserverProducer, eduProducer, federationSenderAPI, *keyRing,
|
||||
federation, accountsDB, deviceDB,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ func Setup(
|
|||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
federationSenderAPI federationSenderAPI.FederationSenderQueryAPI,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
|
@ -79,7 +80,7 @@ func Setup(
|
|||
}
|
||||
return Send(
|
||||
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
|
||||
cfg, query, producer, keys, federation,
|
||||
cfg, query, producer, eduProducer, keys, federation,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodPut, http.MethodOptions)
|
||||
|
|
|
@ -36,20 +36,22 @@ func Send(
|
|||
cfg *config.Dendrite,
|
||||
query api.RoomserverQueryAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
) util.JSONResponse {
|
||||
t := txnReq{
|
||||
context: httpReq.Context(),
|
||||
query: query,
|
||||
producer: producer,
|
||||
keys: keys,
|
||||
federation: federation,
|
||||
context: httpReq.Context(),
|
||||
query: query,
|
||||
producer: producer,
|
||||
eduProducer: eduProducer,
|
||||
keys: keys,
|
||||
federation: federation,
|
||||
}
|
||||
|
||||
var txnEvents struct {
|
||||
PDUs []json.RawMessage `json:"pdus"`
|
||||
EDUs []json.RawMessage `json:"edus"`
|
||||
PDUs []json.RawMessage `json:"pdus"`
|
||||
EDUs []gomatrixserverlib.EDU `json:"edus"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(request.Content(), &txnEvents); err != nil {
|
||||
|
@ -59,7 +61,9 @@ func Send(
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Really we should have a function to convert FederationRequest to txnReq
|
||||
t.PDUs = txnEvents.PDUs
|
||||
t.EDUs = txnEvents.EDUs
|
||||
t.Origin = request.Origin()
|
||||
t.TransactionID = txnID
|
||||
t.Destination = cfg.Matrix.ServerName
|
||||
|
@ -80,11 +84,12 @@ func Send(
|
|||
|
||||
type txnReq struct {
|
||||
gomatrixserverlib.Transaction
|
||||
context context.Context
|
||||
query api.RoomserverQueryAPI
|
||||
producer *producers.RoomserverProducer
|
||||
keys gomatrixserverlib.KeyRing
|
||||
federation *gomatrixserverlib.FederationClient
|
||||
context context.Context
|
||||
query api.RoomserverQueryAPI
|
||||
producer *producers.RoomserverProducer
|
||||
eduProducer *producers.EDUServerProducer
|
||||
keys gomatrixserverlib.KeyRing
|
||||
federation *gomatrixserverlib.FederationClient
|
||||
}
|
||||
|
||||
func (t *txnReq) processTransaction() (*gomatrixserverlib.RespSend, error) {
|
||||
|
@ -152,7 +157,7 @@ func (t *txnReq) processTransaction() (*gomatrixserverlib.RespSend, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Process the EDUs.
|
||||
t.processEDUs(t.EDUs)
|
||||
util.GetLogger(t.context).Infof("Processed %d PDUs from transaction %q", len(results), t.TransactionID)
|
||||
return &gomatrixserverlib.RespSend{PDUs: results}, nil
|
||||
}
|
||||
|
@ -163,6 +168,29 @@ type unknownRoomError struct {
|
|||
|
||||
func (e unknownRoomError) Error() string { return fmt.Sprintf("unknown room %q", e.roomID) }
|
||||
|
||||
func (t *txnReq) processEDUs(edus []gomatrixserverlib.EDU) {
|
||||
for _, e := range edus {
|
||||
switch e.Type {
|
||||
case gomatrixserverlib.MTyping:
|
||||
// https://matrix.org/docs/spec/server_server/latest#typing-notifications
|
||||
var typingPayload struct {
|
||||
RoomID string `json:"room_id"`
|
||||
UserID string `json:"user_id"`
|
||||
Typing bool `json:"typing"`
|
||||
}
|
||||
if err := json.Unmarshal(e.Content, &typingPayload); err != nil {
|
||||
util.GetLogger(t.context).WithError(err).Error("Failed to unmarshal typing event")
|
||||
continue
|
||||
}
|
||||
if err := t.eduProducer.SendTyping(t.context, typingPayload.UserID, typingPayload.RoomID, typingPayload.Typing, 30*1000); err != nil {
|
||||
util.GetLogger(t.context).WithError(err).Error("Failed to send typing event to edu server")
|
||||
}
|
||||
default:
|
||||
util.GetLogger(t.context).WithField("type", e.Type).Warn("unhandled edu")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *txnReq) processEvent(e gomatrixserverlib.Event) error {
|
||||
prevEventIDs := e.PrevEventIDs()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue