mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 06:52:35 +01:00
fix: Minor user status bugs
This commit is contained in:
parent
cafd639c24
commit
f84ac1d121
@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
@ -55,6 +54,8 @@ class MatrixState extends State<Matrix> {
|
||||
@override
|
||||
BuildContext context;
|
||||
|
||||
static const String userStatusesType = 'chat.fluffy.user_statuses';
|
||||
|
||||
Map<String, dynamic> get shareContent => _shareContent;
|
||||
set shareContent(Map<String, dynamic> content) {
|
||||
_shareContent = content;
|
||||
@ -90,6 +91,7 @@ class MatrixState extends State<Matrix> {
|
||||
widget.clientName,
|
||||
);
|
||||
}
|
||||
_cleanUpUserStatus(userStatuses);
|
||||
}
|
||||
|
||||
Map<String, dynamic> getAuthByPassword(String password, [String session]) => {
|
||||
@ -195,16 +197,6 @@ class MatrixState extends State<Matrix> {
|
||||
@override
|
||||
void initState() {
|
||||
store = widget.store ?? Store();
|
||||
store.getItem('fluffychat.user_statuses').then(
|
||||
(json) {
|
||||
userStatuses = json == null
|
||||
? []
|
||||
: (jsonDecode(json)['user_statuses'] as List)
|
||||
.map((j) => UserStatus.fromJson(j))
|
||||
.toList();
|
||||
_cleanUpUserStatus();
|
||||
},
|
||||
);
|
||||
if (widget.client == null) {
|
||||
debugPrint('[Matrix] Init matrix client');
|
||||
final Set verificationMethods = <KeyVerificationMethod>{
|
||||
@ -303,9 +295,18 @@ class MatrixState extends State<Matrix> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
List<UserStatus> userStatuses = [];
|
||||
List<UserStatus> get userStatuses {
|
||||
try {
|
||||
return (client.accountData[userStatusesType].content['user_statuses']
|
||||
as List)
|
||||
.map((json) => UserStatus.fromJson(json))
|
||||
.toList();
|
||||
} catch (_) {}
|
||||
return [];
|
||||
}
|
||||
|
||||
void _storeUserStatus(Presence presence) {
|
||||
final tmpUserStatuses = List<UserStatus>.from(userStatuses);
|
||||
final currentStatusIndex =
|
||||
userStatuses.indexWhere((u) => u.userId == presence.senderId);
|
||||
final newUserStatus = UserStatus()
|
||||
@ -313,37 +314,38 @@ class MatrixState extends State<Matrix> {
|
||||
..statusMsg = presence.presence.statusMsg
|
||||
..userId = presence.senderId;
|
||||
if (currentStatusIndex == -1) {
|
||||
userStatuses.add(newUserStatus);
|
||||
} else if (userStatuses[currentStatusIndex].statusMsg !=
|
||||
tmpUserStatuses.add(newUserStatus);
|
||||
} else if (tmpUserStatuses[currentStatusIndex].statusMsg !=
|
||||
presence.presence.statusMsg) {
|
||||
if (presence.presence.statusMsg.trim().isEmpty) {
|
||||
userStatuses.removeAt(currentStatusIndex);
|
||||
tmpUserStatuses.removeAt(currentStatusIndex);
|
||||
} else {
|
||||
userStatuses[currentStatusIndex] = newUserStatus;
|
||||
tmpUserStatuses[currentStatusIndex] = newUserStatus;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
_cleanUpUserStatus();
|
||||
_cleanUpUserStatus(tmpUserStatuses);
|
||||
}
|
||||
|
||||
void _cleanUpUserStatus() {
|
||||
void _cleanUpUserStatus(List<UserStatus> tmpUserStatuses) {
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
userStatuses
|
||||
tmpUserStatuses
|
||||
.removeWhere((u) => (now - u.receivedAt) > (1000 * 60 * 60 * 24));
|
||||
userStatuses.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
|
||||
if (userStatuses.length > 40) {
|
||||
userStatuses.removeRange(40, userStatuses.length);
|
||||
tmpUserStatuses.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
|
||||
if (tmpUserStatuses.length > 40) {
|
||||
tmpUserStatuses.removeRange(40, tmpUserStatuses.length);
|
||||
}
|
||||
store.setItem(
|
||||
'fluffychat.user_statuses',
|
||||
jsonEncode(
|
||||
if (tmpUserStatuses != userStatuses) {
|
||||
client.setAccountData(
|
||||
client.userID,
|
||||
userStatusesType,
|
||||
{
|
||||
'user_statuses': userStatuses.map((i) => i.toJson()).toList(),
|
||||
'user_statuses': tmpUserStatuses.map((i) => i.toJson()).toList(),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -81,6 +81,7 @@ class StatusView extends StatelessWidget {
|
||||
backgroundColor: displayname.color,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0.0,
|
||||
brightness: Brightness.dark,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
@ -100,6 +101,7 @@ class StatusView extends StatelessWidget {
|
||||
),
|
||||
subtitle: Text(
|
||||
status?.userId ?? Matrix.of(context).client.userID,
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
|
52
pubspec.lock
52
pubspec.lock
@ -49,7 +49,7 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
version: "2.5.0-nullsafety.1"
|
||||
base58check:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -63,7 +63,7 @@ packages:
|
||||
name: boolean_selector
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.1.0-nullsafety.1"
|
||||
bot_toast:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -91,14 +91,14 @@ packages:
|
||||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
version: "1.1.0-nullsafety.3"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.3"
|
||||
version: "1.2.0-nullsafety.1"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -112,14 +112,14 @@ packages:
|
||||
name: clock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.1.0-nullsafety.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.14.13"
|
||||
version: "1.15.0-nullsafety.3"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -175,7 +175,7 @@ packages:
|
||||
name: fake_async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.2.0-nullsafety.1"
|
||||
famedlysdk:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -456,7 +456,7 @@ packages:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.2"
|
||||
version: "0.6.3-nullsafety.1"
|
||||
localstorage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -484,7 +484,7 @@ packages:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.8"
|
||||
version: "0.12.10-nullsafety.1"
|
||||
matrix_file_e2ee:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -512,7 +512,7 @@ packages:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.8"
|
||||
version: "1.3.0-nullsafety.3"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -605,7 +605,7 @@ packages:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.0"
|
||||
version: "1.8.0-nullsafety.1"
|
||||
path_provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -647,7 +647,7 @@ packages:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
version: "1.10.0-nullsafety.1"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -689,7 +689,7 @@ packages:
|
||||
name: pool
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
version: "1.5.0-nullsafety.1"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -792,21 +792,21 @@ packages:
|
||||
name: source_map_stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.1.0-nullsafety.2"
|
||||
source_maps:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_maps
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.9"
|
||||
version: "0.10.10-nullsafety.1"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.0"
|
||||
version: "1.8.0-nullsafety.2"
|
||||
sqflite:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -841,21 +841,21 @@ packages:
|
||||
name: stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.5"
|
||||
version: "1.10.0-nullsafety.1"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.1.0-nullsafety.1"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
version: "1.1.0-nullsafety.1"
|
||||
synchronized:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -869,35 +869,35 @@ packages:
|
||||
name: term_glyph
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.2.0-nullsafety.1"
|
||||
test:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.2"
|
||||
version: "1.16.0-nullsafety.5"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.17"
|
||||
version: "0.2.19-nullsafety.2"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.10"
|
||||
version: "0.3.12-nullsafety.5"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "1.3.0-nullsafety.3"
|
||||
universal_html:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -981,7 +981,7 @@ packages:
|
||||
name: vector_math
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.8"
|
||||
version: "2.1.0-nullsafety.3"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1053,5 +1053,5 @@ packages:
|
||||
source: hosted
|
||||
version: "0.1.2"
|
||||
sdks:
|
||||
dart: ">=2.9.0 <3.0.0"
|
||||
dart: ">=2.10.0-110 <2.11.0"
|
||||
flutter: ">=1.20.0 <2.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user