mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Tweaks/fixes to presence
This commit is contained in:
parent
50a4f51f2f
commit
6f7c57e6bd
|
|
@ -185,6 +185,7 @@ func (p *PDUStreamProvider) IncrementalSync(
|
||||||
// If this room was joined in this sync, try to fetch
|
// If this room was joined in this sync, try to fetch
|
||||||
// as much timeline events as allowed by the filter.
|
// as much timeline events as allowed by the filter.
|
||||||
if delta.NewlyJoined {
|
if delta.NewlyJoined {
|
||||||
|
req.NewlyJoined[delta.RoomID] = struct{}{}
|
||||||
// Reverse the range, so we get the most recent first.
|
// Reverse the range, so we get the most recent first.
|
||||||
// This will be limited by the eventFilter.
|
// This will be limited by the eventFilter.
|
||||||
newRange = types.Range{
|
newRange = types.Range{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/syncapi/notifier"
|
"github.com/matrix-org/dendrite/syncapi/notifier"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
|
|
@ -70,20 +69,19 @@ func (p *PresenceStreamProvider) IncrementalSync(
|
||||||
return from
|
return from
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(presences) == 0 {
|
|
||||||
return to
|
|
||||||
}
|
|
||||||
|
|
||||||
// add newly joined rooms user presences
|
// add newly joined rooms user presences
|
||||||
newlyJoined := joinedRooms(req.Response, req.Device.UserID)
|
if len(req.NewlyJoined) > 0 {
|
||||||
if len(newlyJoined) > 0 {
|
newlyJoinedRoomIDs := make([]string, 0, len(req.NewlyJoined))
|
||||||
|
for roomID := range req.NewlyJoined {
|
||||||
|
newlyJoinedRoomIDs = append(newlyJoinedRoomIDs, roomID)
|
||||||
|
}
|
||||||
// TODO: Check if this is working better than before.
|
// TODO: Check if this is working better than before.
|
||||||
if err = p.notifier.LoadRooms(ctx, p.DB, newlyJoined); err != nil {
|
if err = p.notifier.LoadRooms(ctx, p.DB, newlyJoinedRoomIDs); err != nil {
|
||||||
req.Log.WithError(err).Error("unable to refresh notifier lists")
|
req.Log.WithError(err).Error("unable to refresh notifier lists")
|
||||||
return from
|
return from
|
||||||
}
|
}
|
||||||
NewlyJoinedLoop:
|
NewlyJoinedLoop:
|
||||||
for _, roomID := range newlyJoined {
|
for _, roomID := range newlyJoinedRoomIDs {
|
||||||
roomUsers := p.notifier.JoinedUsers(roomID)
|
roomUsers := p.notifier.JoinedUsers(roomID)
|
||||||
for i := range roomUsers {
|
for i := range roomUsers {
|
||||||
// we already got a presence from this user
|
// we already got a presence from this user
|
||||||
|
|
@ -103,6 +101,8 @@ func (p *PresenceStreamProvider) IncrementalSync(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return to
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPos := from
|
lastPos := from
|
||||||
|
|
@ -162,36 +162,3 @@ func (p *PresenceStreamProvider) IncrementalSync(
|
||||||
|
|
||||||
return lastPos
|
return lastPos
|
||||||
}
|
}
|
||||||
|
|
||||||
func joinedRooms(res *types.Response, userID string) []string {
|
|
||||||
var roomIDs []string
|
|
||||||
for roomID, join := range res.Rooms.Join {
|
|
||||||
// we would expect to see our join event somewhere if we newly joined the room.
|
|
||||||
// Normal events get put in the join section so it's not enough to know the room ID is present in 'join'.
|
|
||||||
newlyJoined := membershipEventPresent(join.State.Events, userID)
|
|
||||||
if newlyJoined {
|
|
||||||
roomIDs = append(roomIDs, roomID)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
newlyJoined = membershipEventPresent(join.Timeline.Events, userID)
|
|
||||||
if newlyJoined {
|
|
||||||
roomIDs = append(roomIDs, roomID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return roomIDs
|
|
||||||
}
|
|
||||||
|
|
||||||
func membershipEventPresent(events []gomatrixserverlib.ClientEvent, userID string) bool {
|
|
||||||
for _, ev := range events {
|
|
||||||
// it's enough to know that we have our member event here, don't need to check membership content
|
|
||||||
// as it's implied by being in the respective section of the sync response.
|
|
||||||
if ev.Type == gomatrixserverlib.MRoomMember && ev.StateKey != nil && *ev.StateKey == userID {
|
|
||||||
// ignore e.g. join -> join changes
|
|
||||||
if gjson.GetBytes(ev.Unsigned, "prev_content.membership").Str == gjson.GetBytes(ev.Content, "membership").Str {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncRequest struct {
|
type SyncRequest struct {
|
||||||
|
|
@ -22,6 +23,8 @@ type SyncRequest struct {
|
||||||
// Updated by the PDU stream.
|
// Updated by the PDU stream.
|
||||||
Rooms map[string]string
|
Rooms map[string]string
|
||||||
// Updated by the PDU stream.
|
// Updated by the PDU stream.
|
||||||
|
NewlyJoined map[string]struct{}
|
||||||
|
// Updated by the PDU stream.
|
||||||
IgnoredUsers IgnoredUsers
|
IgnoredUsers IgnoredUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue