refactor: Update Matrix SDK
This commit is contained in:
parent
d0b8d56b2a
commit
355abeb17f
10 changed files with 48 additions and 53 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
extension ClientPresenceExtension on Client {
|
||||
List<Presence> get contactList {
|
||||
List<CachedPresence> get contactList {
|
||||
final directChatsMxid = rooms
|
||||
.where((r) => r.isDirectChat)
|
||||
.map((r) => r.directChatMatrixID)
|
||||
|
|
@ -10,20 +10,21 @@ extension ClientPresenceExtension on Client {
|
|||
.map(
|
||||
(mxid) =>
|
||||
presences[mxid] ??
|
||||
Presence.fromJson(
|
||||
{
|
||||
'sender': mxid,
|
||||
'type': 'm.presence',
|
||||
'content': {'presence': 'offline'},
|
||||
},
|
||||
CachedPresence(
|
||||
PresenceType.offline,
|
||||
0,
|
||||
null,
|
||||
false,
|
||||
mxid ?? '',
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
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)));
|
||||
contactList.sort((a, b) => a.userid.compareTo(b.userid));
|
||||
contactList.sort((a, b) => ((a.lastActiveTimestamp ??
|
||||
DateTime.fromMillisecondsSinceEpoch(0))
|
||||
.compareTo(
|
||||
b.lastActiveTimestamp ?? DateTime.fromMillisecondsSinceEpoch(0))));
|
||||
return contactList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,30 +5,29 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
import '../date_time_extension.dart';
|
||||
|
||||
extension PresenceExtension on Presence {
|
||||
extension PresenceExtension on CachedPresence {
|
||||
String getLocalizedLastActiveAgo(BuildContext context) {
|
||||
if (presence.lastActiveAgo != null && presence.lastActiveAgo != 0) {
|
||||
return L10n.of(context)!.lastActiveAgo(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch -
|
||||
presence.lastActiveAgo!)
|
||||
.localizedTimeShort(context));
|
||||
final lastActiveTimestamp = this.lastActiveTimestamp;
|
||||
if (lastActiveTimestamp != null) {
|
||||
return L10n.of(context)!
|
||||
.lastActiveAgo(lastActiveTimestamp.localizedTimeShort(context));
|
||||
}
|
||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||
}
|
||||
|
||||
String getLocalizedStatusMessage(BuildContext context) {
|
||||
if (presence.statusMsg?.isNotEmpty ?? false) {
|
||||
return presence.statusMsg!;
|
||||
final statusMsg = this.statusMsg;
|
||||
if (statusMsg != null && statusMsg.isNotEmpty) {
|
||||
return statusMsg;
|
||||
}
|
||||
if (presence.currentlyActive ?? false) {
|
||||
if (currentlyActive ?? false) {
|
||||
return L10n.of(context)!.currentlyActive;
|
||||
}
|
||||
return getLocalizedLastActiveAgo(context);
|
||||
}
|
||||
|
||||
Color get color {
|
||||
switch (presence.presence) {
|
||||
switch (presence) {
|
||||
case PresenceType.online:
|
||||
return Colors.green;
|
||||
case PresenceType.offline:
|
||||
|
|
|
|||
|
|
@ -8,26 +8,25 @@ import 'date_time_extension.dart';
|
|||
import 'matrix_sdk_extensions.dart/filtered_timeline_extension.dart';
|
||||
|
||||
extension RoomStatusExtension on Room {
|
||||
Presence? get directChatPresence => client.presences[directChatMatrixID];
|
||||
CachedPresence? get directChatPresence =>
|
||||
client.presences[directChatMatrixID];
|
||||
|
||||
String getLocalizedStatus(BuildContext context) {
|
||||
if (isDirectChat) {
|
||||
final directChatPresence = this.directChatPresence;
|
||||
if (directChatPresence != null &&
|
||||
(directChatPresence.presence.lastActiveAgo != null ||
|
||||
directChatPresence.presence.currentlyActive != null)) {
|
||||
if (directChatPresence.presence.statusMsg?.isNotEmpty ?? false) {
|
||||
return directChatPresence.presence.statusMsg!;
|
||||
(directChatPresence.lastActiveTimestamp != null ||
|
||||
directChatPresence.currentlyActive != null)) {
|
||||
if (directChatPresence.statusMsg?.isNotEmpty ?? false) {
|
||||
return directChatPresence.statusMsg!;
|
||||
}
|
||||
if (directChatPresence.presence.currentlyActive == true) {
|
||||
if (directChatPresence.currentlyActive == true) {
|
||||
return L10n.of(context)!.currentlyActive;
|
||||
}
|
||||
if (directChatPresence.presence.lastActiveAgo == null) {
|
||||
if (directChatPresence.lastActiveTimestamp == null) {
|
||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||
}
|
||||
final time = DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch -
|
||||
directChatPresence.presence.lastActiveAgo!);
|
||||
final time = directChatPresence.lastActiveTimestamp!;
|
||||
return L10n.of(context)!
|
||||
.lastActiveAgo(time.localizedTimeShort(context));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue