fluffychat/lib/utils/matrix_sdk_extensions.dart/client_presence_extension.dart

30 lines
880 B
Dart
Raw Normal View History

import 'package:matrix/matrix.dart';
extension ClientPresenceExtension on Client {
List<Presence> get contactList {
final directChatsMxid = rooms
.where((r) => r.isDirectChat)
.map((r) => r.directChatMatrixID)
.toSet();
final contactList = directChatsMxid
.map(
(mxid) =>
presences[mxid] ??
Presence.fromJson(
{
'sender': mxid,
'type': 'm.presence',
2021-02-05 10:10:59 +01:00
'content': {'presence': 'offline'},
},
),
)
.toList();
2021-02-05 16:43:05 +01:00
contactList.sort((a, b) => a.senderId.compareTo(b.senderId));
contactList.sort((a, b) => (a.presence.lastActiveAgo?.toDouble() ??
double.infinity)
.compareTo((b.presence.lastActiveAgo?.toDouble() ?? double.infinity)));
return contactList;
}
}