Start the unsent sending

This commit is contained in:
Erik Johnston 2017-12-19 15:43:02 +00:00
parent c112c68d8e
commit 3f205b1dab

View file

@ -17,6 +17,7 @@ package input
import ( import (
"bytes" "bytes"
"context" "context"
"sync"
"github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
@ -26,6 +27,44 @@ import (
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
type sendValue struct {
finishedChan chan<- struct{}
stateAtEvent types.StateAtEvent
event gomatrixserverlib.Event
sendAsServer string
transactionID *api.TransactionID
}
type EventSender struct {
db RoomEventDatabase
outputWriter OutputRoomEventWriter
sendingMutex sync.Mutex
sending map[types.RoomNID][]sendValue
}
func (e *EventSender) send(
ctx context.Context,
roomNID types.RoomNID,
stateAtEvent types.StateAtEvent,
event gomatrixserverlib.Event,
sendAsServer string,
transactionID *api.TransactionID,
) {
e.sendingMutex.Lock()
defer e.sendingMutex.Unlock()
finishedChan := make(chan struct{})
e.sending[roomNID] = append(e.sending[roomNID], sendValue{
finishedChan: finishedChan,
stateAtEvent: stateAtEvent,
event: event,
sendAsServer: sendAsServer,
transactionID: transactionID,
})
<-finishedChan
}
// updateLatestEvents updates the list of latest events for this room in the database and writes the // updateLatestEvents updates the list of latest events for this room in the database and writes the
// event to the output log. // event to the output log.
// The latest events are the events that aren't referenced by another event in the database: // The latest events are the events that aren't referenced by another event in the database: