change: Implement contact list instead of status

This commit is contained in:
Christian Pauly 2021-02-05 08:43:44 +01:00
commit 237240407f
10 changed files with 216 additions and 288 deletions

View file

@ -1,7 +1,34 @@
import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client {
List<Presence> get statuses => presences.values
.where((p) => p.presence.statusMsg?.isNotEmpty ?? false)
.toList();
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',
'content': {'presence': 'online'},
},
),
)
.toList();
contactList.addAll(
presences.values
.where((p) =>
!directChatsMxid.contains(p.senderId) &&
(p.presence?.statusMsg?.isNotEmpty ?? false))
.toList(),
);
contactList.sort((a, b) => (a.presence.lastActiveAgo?.toDouble() ??
double.infinity)
.compareTo((b.presence.lastActiveAgo?.toDouble() ?? double.infinity)));
return contactList;
}
}