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