feat: Implement new status feature

This commit is contained in:
Christian Pauly 2020-10-03 15:53:08 +02:00
commit c5d84c22ca
10 changed files with 329 additions and 245 deletions

View file

@ -1,10 +1,7 @@
import 'package:famedlysdk/famedlysdk.dart';
extension ClientPresenceExtension on Client {
static final Map<String, Profile> presencesCache = {};
Future<Profile> requestProfileCached(String senderId) async {
presencesCache[senderId] ??= await getProfileFromUserId(senderId);
return presencesCache[senderId];
}
List<Presence> get statuses => presences.values
.where((p) => p.presence.statusMsg?.isNotEmpty ?? false)
.toList();
}

View file

@ -5,6 +5,8 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'date_time_extension.dart';
extension PresenceExtension on Presence {
bool get isUserStatus => presence?.statusMsg?.isNotEmpty ?? false;
String getLocalizedStatusMessage(BuildContext context) {
if (presence.statusMsg?.isNotEmpty ?? false) {
return presence.statusMsg;

View file

@ -0,0 +1,21 @@
class UserStatus {
String statusMsg;
String userId;
int receivedAt;
UserStatus();
UserStatus.fromJson(Map<String, dynamic> json) {
statusMsg = json['status_msg'];
userId = json['user_id'];
receivedAt = json['received_at'];
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['status_msg'] = statusMsg;
data['user_id'] = userId;
data['received_at'] = receivedAt;
return data;
}
}