Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1675: presence status updated too many times #54

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,10 @@ class Client extends MatrixApi {
final CachedStreamController<CachedPresence> onPresenceChanged =
CachedStreamController();

/// Callback will be called on presence update and return latest value.
final CachedStreamController<CachedPresence> onlatestPresenceChanged =
CachedStreamController();

/// Callback will be called on account data updates.
final CachedStreamController<BasicEvent> onAccountData =
CachedStreamController();
Expand Down Expand Up @@ -1801,13 +1805,27 @@ class Client extends MatrixApi {
await _handleRooms(leave, direction: direction);
}
}

CachedPresence? lowestLastActivePresence;
hoangdat marked this conversation as resolved.
Show resolved Hide resolved

for (final newPresence in sync.presence ?? []) {
final cachedPresence = CachedPresence.fromMatrixEvent(newPresence);
presences[newPresence.senderId] = cachedPresence;
// ignore: deprecated_member_use_from_same_package
onPresence.add(newPresence);
onPresenceChanged.add(cachedPresence);

if (lowestLastActivePresence == null ||
cachedPresence.lastActiveTimestamp!
.isBefore(lowestLastActivePresence.lastActiveTimestamp!)) {
Te-Z marked this conversation as resolved.
Show resolved Hide resolved
lowestLastActivePresence = cachedPresence;
}
}

if (lowestLastActivePresence != null) {
onlatestPresenceChanged.add(lowestLastActivePresence);
}

for (final newAccountData in sync.accountData ?? []) {
await database?.storeAccountData(
newAccountData.type,
Expand Down
Loading