mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-11 18:22:49 +01:00
Merge branch 'krille/update-matrix-sdk' into 'main'
refactor: Update Matrix SDK See merge request famedly/fluffychat!869
This commit is contained in:
commit
d755ca7496
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:matrix/widget.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat/add_widget_tile_view.dart';
|
import 'package:fluffychat/pages/chat/add_widget_tile_view.dart';
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class UserBottomSheetView extends StatelessWidget {
|
|||||||
subtitle:
|
subtitle:
|
||||||
Text(presence.getLocalizedLastActiveAgo(context)),
|
Text(presence.getLocalizedLastActiveAgo(context)),
|
||||||
trailing: Icon(Icons.circle,
|
trailing: Icon(Icons.circle,
|
||||||
color: presence.presence.currentlyActive ?? false
|
color: presence.presence == PresenceType.online
|
||||||
? Colors.green
|
? Colors.green
|
||||||
: Colors.grey),
|
: Colors.grey),
|
||||||
),
|
),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
extension ClientPresenceExtension on Client {
|
extension ClientPresenceExtension on Client {
|
||||||
List<Presence> get contactList {
|
List<CachedPresence> get contactList {
|
||||||
final directChatsMxid = rooms
|
final directChatsMxid = rooms
|
||||||
.where((r) => r.isDirectChat)
|
.where((r) => r.isDirectChat)
|
||||||
.map((r) => r.directChatMatrixID)
|
.map((r) => r.directChatMatrixID)
|
||||||
@ -10,20 +10,21 @@ extension ClientPresenceExtension on Client {
|
|||||||
.map(
|
.map(
|
||||||
(mxid) =>
|
(mxid) =>
|
||||||
presences[mxid] ??
|
presences[mxid] ??
|
||||||
Presence.fromJson(
|
CachedPresence(
|
||||||
{
|
PresenceType.offline,
|
||||||
'sender': mxid,
|
0,
|
||||||
'type': 'm.presence',
|
null,
|
||||||
'content': {'presence': 'offline'},
|
false,
|
||||||
},
|
mxid ?? '',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
contactList.sort((a, b) => a.senderId.compareTo(b.senderId));
|
contactList.sort((a, b) => a.userid.compareTo(b.userid));
|
||||||
contactList.sort((a, b) => (a.presence.lastActiveAgo?.toDouble() ??
|
contactList.sort((a, b) => ((a.lastActiveTimestamp ??
|
||||||
double.infinity)
|
DateTime.fromMillisecondsSinceEpoch(0))
|
||||||
.compareTo((b.presence.lastActiveAgo?.toDouble() ?? double.infinity)));
|
.compareTo(
|
||||||
|
b.lastActiveTimestamp ?? DateTime.fromMillisecondsSinceEpoch(0))));
|
||||||
return contactList;
|
return contactList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,30 +5,29 @@ import 'package:matrix/matrix.dart';
|
|||||||
|
|
||||||
import '../date_time_extension.dart';
|
import '../date_time_extension.dart';
|
||||||
|
|
||||||
extension PresenceExtension on Presence {
|
extension PresenceExtension on CachedPresence {
|
||||||
String getLocalizedLastActiveAgo(BuildContext context) {
|
String getLocalizedLastActiveAgo(BuildContext context) {
|
||||||
if (presence.lastActiveAgo != null && presence.lastActiveAgo != 0) {
|
final lastActiveTimestamp = this.lastActiveTimestamp;
|
||||||
return L10n.of(context)!.lastActiveAgo(
|
if (lastActiveTimestamp != null) {
|
||||||
DateTime.fromMillisecondsSinceEpoch(
|
return L10n.of(context)!
|
||||||
DateTime.now().millisecondsSinceEpoch -
|
.lastActiveAgo(lastActiveTimestamp.localizedTimeShort(context));
|
||||||
presence.lastActiveAgo!)
|
|
||||||
.localizedTimeShort(context));
|
|
||||||
}
|
}
|
||||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLocalizedStatusMessage(BuildContext context) {
|
String getLocalizedStatusMessage(BuildContext context) {
|
||||||
if (presence.statusMsg?.isNotEmpty ?? false) {
|
final statusMsg = this.statusMsg;
|
||||||
return presence.statusMsg!;
|
if (statusMsg != null && statusMsg.isNotEmpty) {
|
||||||
|
return statusMsg;
|
||||||
}
|
}
|
||||||
if (presence.currentlyActive ?? false) {
|
if (currentlyActive ?? false) {
|
||||||
return L10n.of(context)!.currentlyActive;
|
return L10n.of(context)!.currentlyActive;
|
||||||
}
|
}
|
||||||
return getLocalizedLastActiveAgo(context);
|
return getLocalizedLastActiveAgo(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color get color {
|
Color get color {
|
||||||
switch (presence.presence) {
|
switch (presence) {
|
||||||
case PresenceType.online:
|
case PresenceType.online:
|
||||||
return Colors.green;
|
return Colors.green;
|
||||||
case PresenceType.offline:
|
case PresenceType.offline:
|
||||||
|
@ -8,26 +8,25 @@ import 'date_time_extension.dart';
|
|||||||
import 'matrix_sdk_extensions.dart/filtered_timeline_extension.dart';
|
import 'matrix_sdk_extensions.dart/filtered_timeline_extension.dart';
|
||||||
|
|
||||||
extension RoomStatusExtension on Room {
|
extension RoomStatusExtension on Room {
|
||||||
Presence? get directChatPresence => client.presences[directChatMatrixID];
|
CachedPresence? get directChatPresence =>
|
||||||
|
client.presences[directChatMatrixID];
|
||||||
|
|
||||||
String getLocalizedStatus(BuildContext context) {
|
String getLocalizedStatus(BuildContext context) {
|
||||||
if (isDirectChat) {
|
if (isDirectChat) {
|
||||||
final directChatPresence = this.directChatPresence;
|
final directChatPresence = this.directChatPresence;
|
||||||
if (directChatPresence != null &&
|
if (directChatPresence != null &&
|
||||||
(directChatPresence.presence.lastActiveAgo != null ||
|
(directChatPresence.lastActiveTimestamp != null ||
|
||||||
directChatPresence.presence.currentlyActive != null)) {
|
directChatPresence.currentlyActive != null)) {
|
||||||
if (directChatPresence.presence.statusMsg?.isNotEmpty ?? false) {
|
if (directChatPresence.statusMsg?.isNotEmpty ?? false) {
|
||||||
return directChatPresence.presence.statusMsg!;
|
return directChatPresence.statusMsg!;
|
||||||
}
|
}
|
||||||
if (directChatPresence.presence.currentlyActive == true) {
|
if (directChatPresence.currentlyActive == true) {
|
||||||
return L10n.of(context)!.currentlyActive;
|
return L10n.of(context)!.currentlyActive;
|
||||||
}
|
}
|
||||||
if (directChatPresence.presence.lastActiveAgo == null) {
|
if (directChatPresence.lastActiveTimestamp == null) {
|
||||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||||
}
|
}
|
||||||
final time = DateTime.fromMillisecondsSinceEpoch(
|
final time = directChatPresence.lastActiveTimestamp!;
|
||||||
DateTime.now().millisecondsSinceEpoch -
|
|
||||||
directChatPresence.presence.lastActiveAgo!);
|
|
||||||
return L10n.of(context)!
|
return L10n.of(context)!
|
||||||
.lastActiveAgo(time.localizedTimeShort(context));
|
.lastActiveAgo(time.localizedTimeShort(context));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class _ContactsState extends State<ContactsList> {
|
|||||||
final contactList = Matrix.of(context)
|
final contactList = Matrix.of(context)
|
||||||
.client
|
.client
|
||||||
.contactList
|
.contactList
|
||||||
.where((p) => p.senderId
|
.where((p) => p.userid
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(widget.searchController.text.toLowerCase()))
|
.contains(widget.searchController.text.toLowerCase()))
|
||||||
.toList();
|
.toList();
|
||||||
@ -66,17 +66,16 @@ class _ContactsState extends State<ContactsList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ContactListTile extends StatelessWidget {
|
class _ContactListTile extends StatelessWidget {
|
||||||
final Presence contact;
|
final CachedPresence contact;
|
||||||
|
|
||||||
const _ContactListTile({Key? key, required this.contact}) : super(key: key);
|
const _ContactListTile({Key? key, required this.contact}) : super(key: key);
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<Profile>(
|
return FutureBuilder<Profile>(
|
||||||
future:
|
future: Matrix.of(context).client.getProfileFromUserId(contact.userid),
|
||||||
Matrix.of(context).client.getProfileFromUserId(contact.senderId),
|
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final displayname = snapshot.data?.displayName ??
|
final displayname = snapshot.data?.displayName ??
|
||||||
contact.senderId.localpart ??
|
contact.userid.localpart ??
|
||||||
'No valid MXID';
|
'No valid MXID';
|
||||||
final avatarUrl = snapshot.data?.avatarUrl;
|
final avatarUrl = snapshot.data?.avatarUrl;
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@ -104,7 +103,7 @@ class _ContactListTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
title: Text(displayname),
|
title: Text(displayname),
|
||||||
subtitle: Text(contact.getLocalizedStatusMessage(context),
|
subtitle: Text(contact.getLocalizedStatusMessage(context),
|
||||||
style: contact.presence.statusMsg?.isNotEmpty ?? false
|
style: contact.statusMsg?.isNotEmpty ?? false
|
||||||
? TextStyle(
|
? TextStyle(
|
||||||
color: Theme.of(context).colorScheme.secondary,
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -112,9 +111,7 @@ class _ContactListTile extends StatelessWidget {
|
|||||||
: null),
|
: null),
|
||||||
onTap: () => VRouter.of(context).toSegments([
|
onTap: () => VRouter.of(context).toSegments([
|
||||||
'rooms',
|
'rooms',
|
||||||
Matrix.of(context)
|
Matrix.of(context).client.getDirectChatFromUserId(contact.userid)!
|
||||||
.client
|
|
||||||
.getDirectChatFromUserId(contact.senderId)!
|
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -224,7 +224,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
final onUiaRequest = <String, StreamSubscription<UiaRequest>>{};
|
final onUiaRequest = <String, StreamSubscription<UiaRequest>>{};
|
||||||
StreamSubscription<html.Event>? onFocusSub;
|
StreamSubscription<html.Event>? onFocusSub;
|
||||||
StreamSubscription<html.Event>? onBlurSub;
|
StreamSubscription<html.Event>? onBlurSub;
|
||||||
final onOwnPresence = <String, StreamSubscription<Presence>>{};
|
final onOwnPresence = <String, StreamSubscription<CachedPresence>>{};
|
||||||
|
|
||||||
String? _cachedPassword;
|
String? _cachedPassword;
|
||||||
Timer? _cachedPasswordClearTimer;
|
Timer? _cachedPasswordClearTimer;
|
||||||
@ -342,13 +342,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Cache and resend status message
|
// Cache and resend status message
|
||||||
onOwnPresence[name] ??= c.onPresence.stream.listen((presence) {
|
onOwnPresence[name] ??= c.onPresenceChanged.stream.listen((presence) {
|
||||||
if (c.isLogged() &&
|
if (c.isLogged() &&
|
||||||
c.userID == presence.senderId &&
|
c.userID == presence.userid &&
|
||||||
presence.presence.statusMsg != null) {
|
presence.statusMsg != null) {
|
||||||
Logs().v('Update status message: "${presence.presence.statusMsg}"');
|
Logs().v('Update status message: "${presence.statusMsg}"');
|
||||||
store.setItem(
|
store.setItem(SettingKeys.ownStatusMessage, presence.statusMsg);
|
||||||
SettingKeys.ownStatusMessage, presence.presence.statusMsg);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);
|
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);
|
||||||
|
@ -1005,7 +1005,7 @@ packages:
|
|||||||
name: matrix
|
name: matrix
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.20"
|
version: "0.9.4"
|
||||||
matrix_api_lite:
|
matrix_api_lite:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -56,7 +56,7 @@ dependencies:
|
|||||||
keyboard_shortcuts: ^0.1.4
|
keyboard_shortcuts: ^0.1.4
|
||||||
localstorage: ^4.0.0+1
|
localstorage: ^4.0.0+1
|
||||||
lottie: ^1.2.2
|
lottie: ^1.2.2
|
||||||
matrix: ^0.8.20
|
matrix: ^0.9.4
|
||||||
matrix_homeserver_recommendations: ^0.2.0
|
matrix_homeserver_recommendations: ^0.2.0
|
||||||
matrix_link_text: ^1.0.2
|
matrix_link_text: ^1.0.2
|
||||||
native_imaging:
|
native_imaging:
|
||||||
|
@ -6,9 +6,10 @@ import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_
|
|||||||
|
|
||||||
Future<Client> prepareTestClient({
|
Future<Client> prepareTestClient({
|
||||||
bool loggedIn = false,
|
bool loggedIn = false,
|
||||||
String homeserver = 'https://fakeserver.notexisting',
|
Uri? homeserver,
|
||||||
String id = 'FluffyChat Widget Test',
|
String id = 'FluffyChat Widget Test',
|
||||||
}) async {
|
}) async {
|
||||||
|
homeserver ??= Uri.parse('https://fakeserver.notexisting');
|
||||||
final client = Client(
|
final client = Client(
|
||||||
'FluffyChat Widget Tests',
|
'FluffyChat Widget Tests',
|
||||||
httpClient: FakeMatrixApi(),
|
httpClient: FakeMatrixApi(),
|
||||||
|
Loading…
Reference in New Issue
Block a user