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;
}
}

View file

@ -37,4 +37,16 @@ extension PresenceExtension on Presence {
}
return presence.presence.getLocalized(context);
}
Color get color {
switch (presence?.presence ?? PresenceType.offline) {
case PresenceType.online:
return Colors.green;
case PresenceType.offline:
return Colors.red;
case PresenceType.unavailable:
default:
return Colors.grey;
}
}
}

View file

@ -1,19 +0,0 @@
class Status {
static const String namespace = 'im.fluffychat.statuses';
final String senderId;
final String message;
final DateTime dateTime;
Status(this.senderId, this.message, this.dateTime);
Status.fromJson(Map<String, dynamic> json)
: senderId = json['sender_id'],
message = json['message'],
dateTime = DateTime.fromMillisecondsSinceEpoch(json['date_time']);
Map<String, dynamic> toJson() => <String, dynamic>{
'sender_id': senderId,
'message': message,
'date_time': dateTime.millisecondsSinceEpoch,
};
}