mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-28 09:13:09 -06:00
Fix typing positions
This commit is contained in:
parent
a6549669ca
commit
0465f523cb
3
eduserver/cache/cache.go
vendored
3
eduserver/cache/cache.go
vendored
|
|
@ -151,6 +151,8 @@ func (t *EDUCache) RemoveUser(userID, roomID string) int64 {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
|
|
||||||
|
t.latestSyncPosition++
|
||||||
|
|
||||||
roomData, ok := t.data[roomID]
|
roomData, ok := t.data[roomID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return t.latestSyncPosition
|
return t.latestSyncPosition
|
||||||
|
|
@ -164,7 +166,6 @@ func (t *EDUCache) RemoveUser(userID, roomID string) int64 {
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
delete(roomData.userSet, userID)
|
delete(roomData.userSet, userID)
|
||||||
|
|
||||||
t.latestSyncPosition++
|
|
||||||
t.data[roomID].syncPosition = t.latestSyncPosition
|
t.data[roomID].syncPosition = t.latestSyncPosition
|
||||||
|
|
||||||
return t.latestSyncPosition
|
return t.latestSyncPosition
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ func (s *OutputReceiptEventConsumer) onMessage(msg *sarama.ConsumerMessage) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.streams.TypingStreamProvider.Advance(streamPos)
|
s.streams.ReceiptStreamProvider.Advance(streamPos)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package consumers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
"github.com/matrix-org/dendrite/eduserver/api"
|
"github.com/matrix-org/dendrite/eduserver/api"
|
||||||
|
|
@ -65,11 +66,9 @@ func NewOutputTypingEventConsumer(
|
||||||
|
|
||||||
// Start consuming from EDU api
|
// Start consuming from EDU api
|
||||||
func (s *OutputTypingEventConsumer) Start() error {
|
func (s *OutputTypingEventConsumer) Start() error {
|
||||||
/*
|
s.eduCache.SetTimeoutCallback(func(userID, roomID string, latestSyncPosition int64) {
|
||||||
s.eduCache.SetTypingTimeoutCallback(func(userID, roomID string, latestSyncPosition int64) {
|
s.streams.TypingStreamProvider.Advance(types.StreamPosition(latestSyncPosition))
|
||||||
s.eduCache.TypingStream().Advance(types.StreamPosition(latestSyncPosition))
|
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
return s.typingConsumer.Start()
|
return s.typingConsumer.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +98,9 @@ func (s *OutputTypingEventConsumer) onMessage(msg *sarama.ConsumerMessage) error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Advancing typing position to", typingPos)
|
||||||
s.streams.TypingStreamProvider.Advance(typingPos)
|
s.streams.TypingStreamProvider.Advance(typingPos)
|
||||||
|
fmt.Println("Advanced typing position to", typingPos)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,19 @@ func (p *PartitionedStreamProvider) Advance(
|
||||||
latest types.LogPosition,
|
latest types.LogPosition,
|
||||||
) {
|
) {
|
||||||
p.latestMutex.Lock()
|
p.latestMutex.Lock()
|
||||||
defer p.latestMutex.Unlock()
|
|
||||||
|
|
||||||
if latest.IsAfter(&p.latest) {
|
if latest.IsAfter(&p.latest) {
|
||||||
p.latest = latest
|
p.latest = latest
|
||||||
|
}
|
||||||
|
p.latestMutex.Unlock()
|
||||||
|
|
||||||
p.subscriptionsMutex.Lock()
|
p.subscriptionsMutex.Lock()
|
||||||
|
defer p.subscriptionsMutex.Unlock()
|
||||||
|
|
||||||
for id, s := range p.subscriptions {
|
for id, s := range p.subscriptions {
|
||||||
select {
|
select {
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
close(s.ch)
|
close(s.ch)
|
||||||
delete(p.subscriptions, id)
|
delete(p.subscriptions, id)
|
||||||
continue
|
|
||||||
default:
|
default:
|
||||||
if latest.IsAfter(&s.from) {
|
if latest.IsAfter(&s.from) {
|
||||||
close(s.ch)
|
close(s.ch)
|
||||||
|
|
@ -50,8 +51,6 @@ func (p *PartitionedStreamProvider) Advance(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.subscriptionsMutex.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PartitionedStreamProvider) LatestPosition(
|
func (p *PartitionedStreamProvider) LatestPosition(
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,19 @@ func (p *StreamProvider) Advance(
|
||||||
latest types.StreamPosition,
|
latest types.StreamPosition,
|
||||||
) {
|
) {
|
||||||
p.latestMutex.Lock()
|
p.latestMutex.Lock()
|
||||||
defer p.latestMutex.Unlock()
|
|
||||||
|
|
||||||
if latest > p.latest {
|
if latest > p.latest {
|
||||||
p.latest = latest
|
p.latest = latest
|
||||||
|
}
|
||||||
|
p.latestMutex.Unlock()
|
||||||
|
|
||||||
p.subscriptionsMutex.Lock()
|
p.subscriptionsMutex.Lock()
|
||||||
|
defer p.subscriptionsMutex.Unlock()
|
||||||
|
|
||||||
for id, s := range p.subscriptions {
|
for id, s := range p.subscriptions {
|
||||||
select {
|
select {
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
close(s.ch)
|
close(s.ch)
|
||||||
delete(p.subscriptions, id)
|
delete(p.subscriptions, id)
|
||||||
continue
|
|
||||||
default:
|
default:
|
||||||
if latest > s.from {
|
if latest > s.from {
|
||||||
close(s.ch)
|
close(s.ch)
|
||||||
|
|
@ -50,8 +51,6 @@ func (p *StreamProvider) Advance(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.subscriptionsMutex.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *StreamProvider) LatestPosition(
|
func (p *StreamProvider) LatestPosition(
|
||||||
|
|
|
||||||
|
|
@ -221,38 +221,31 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
|
||||||
syncReq.Response.NextBatch = types.StreamingToken{
|
syncReq.Response.NextBatch = types.StreamingToken{
|
||||||
PDUPosition: rp.streams.PDUStreamProvider.IncrementalSync(
|
PDUPosition: rp.streams.PDUStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.PDUPosition, // from
|
syncReq.Since.PDUPosition, rp.streams.PDUStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.PDUStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
TypingPosition: rp.streams.TypingStreamProvider.IncrementalSync(
|
TypingPosition: rp.streams.TypingStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.TypingPosition, // from
|
syncReq.Since.TypingPosition, rp.streams.TypingStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.TypingStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
ReceiptPosition: rp.streams.ReceiptStreamProvider.IncrementalSync(
|
ReceiptPosition: rp.streams.ReceiptStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.ReceiptPosition, // from
|
syncReq.Since.ReceiptPosition, rp.streams.ReceiptStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.ReceiptStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
InvitePosition: rp.streams.InviteStreamProvider.IncrementalSync(
|
InvitePosition: rp.streams.InviteStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.InvitePosition, // from
|
syncReq.Since.InvitePosition, rp.streams.InviteStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.InviteStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
SendToDevicePosition: rp.streams.SendToDeviceStreamProvider.IncrementalSync(
|
SendToDevicePosition: rp.streams.SendToDeviceStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.SendToDevicePosition, // from
|
syncReq.Since.SendToDevicePosition, rp.streams.SendToDeviceStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.SendToDeviceStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
AccountDataPosition: rp.streams.AccountDataStreamProvider.IncrementalSync(
|
AccountDataPosition: rp.streams.AccountDataStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.AccountDataPosition, // from
|
syncReq.Since.AccountDataPosition, rp.streams.AccountDataStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.AccountDataStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
DeviceListPosition: rp.streams.DeviceListStreamProvider.IncrementalSync(
|
DeviceListPosition: rp.streams.DeviceListStreamProvider.IncrementalSync(
|
||||||
syncReq.Context, syncReq,
|
syncReq.Context, syncReq,
|
||||||
syncReq.Since.DeviceListPosition, // from
|
syncReq.Since.DeviceListPosition, rp.streams.DeviceListStreamProvider.LatestPosition(syncReq.Context),
|
||||||
rp.streams.DeviceListStreamProvider.LatestPosition(syncReq.Context), // to
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue