From 051ca26c42663ff76c8b8f4d9afaf295a3e0bc23 Mon Sep 17 00:00:00 2001 From: ereio Date: Sun, 21 Mar 2021 15:37:05 -0400 Subject: [PATCH 1/4] version bump 0.1.7+1 --- pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 11e36c6f0..2708dd989 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,7 +47,7 @@ description: a privacy focused matrix client # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. -version: 0.1.7+170 +version: 0.1.7+171 environment: sdk: ">=2.9.0 <3.0.0" # <- modified to solve build_runner @@ -99,7 +99,7 @@ dependencies: easy_localization: 2.3.3 flutter_dotenv: 2.1.0 android_alarm_manager: 0.4.5+15 - uni_links: 0.4.0 + uni_links: 0.4.0 # flutter_apns: 1.1.0 # TODO: extract only the iOS code and remove # Desktop UI Only - UNCOMMENT FOR BUILDS @@ -174,7 +174,7 @@ flutter: - ./.env.debug - ./.env.release - assets/translations/en.json - - assets/translations/ru.json + - assets/translations/ru.json - assets/graphics/undraw_sync_files.svg - assets/graphics/undraw_accept_terms.svg - assets/graphics/undraw_mobile_user.svg From 4bd72831e936249b82b89dec47d908c34b3e0d79 Mon Sep 17 00:00:00 2001 From: ereio Date: Sun, 21 Mar 2021 15:49:05 -0400 Subject: [PATCH 2/4] fix: ignore events not edited by their own sender --- lib/store/events/selectors.dart | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/store/events/selectors.dart b/lib/store/events/selectors.dart index f40986921..07f9228c6 100644 --- a/lib/store/events/selectors.dart +++ b/lib/store/events/selectors.dart @@ -123,20 +123,27 @@ Map replaceEdited(List messages) { // iterate through replacements and modify messages as needed O(M + M) replacements.sort((b, a) => a.timestamp.compareTo(b.timestamp)); - for (Message replacement in replacements) { - final messageId = replacement.relatedEventId; - if (messagesMap.containsKey(messageId)) { - final messageEdited = messagesMap[messageId]; - - messagesMap[messageId] = messageEdited.copyWith( - edited: true, - body: replacement.body, - msgtype: replacement.msgtype, - edits: [messageEdited, ...(messageEdited.edits ?? List())], - ); + for (Message messageEdited in replacements) { + final messageIdOriginal = messageEdited.relatedEventId; + final messageOriginal = messagesMap[messageIdOriginal]; + + if (messageOriginal != null) { + final validEdit = messageEdited.senderKey == messageOriginal.senderKey; + + if (validEdit) { + messagesMap[messageIdOriginal] = messageOriginal.copyWith( + edited: true, + body: messageEdited.body, + msgtype: messageEdited.msgtype, + edits: [ + messageOriginal, + ...(messageOriginal.edits ?? List()) + ], + ); + } // remove replacements from the returned messages - messagesMap.remove(replacement.id); + messagesMap.remove(messageEdited.id); } } From 485681fdc37245e7ff21efd49b98a289f99590cb Mon Sep 17 00:00:00 2001 From: ereio Date: Sun, 21 Mar 2021 17:57:26 -0400 Subject: [PATCH 3/4] fix: catch room mutation failure so broken rooms dont affect others --- lib/global/libs/matrix/events.dart | 9 ++++++++ lib/store/events/messages/actions.dart | 30 +++++++++++++++----------- lib/store/events/selectors.dart | 8 +++---- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/global/libs/matrix/events.dart b/lib/global/libs/matrix/events.dart index e44cbc045..90fa0ad78 100644 --- a/lib/global/libs/matrix/events.dart +++ b/lib/global/libs/matrix/events.dart @@ -29,6 +29,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; final response = await http.get( @@ -64,6 +65,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; final response = await http.get( @@ -121,6 +123,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; Map body = { @@ -171,6 +174,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; final response = await http.put( @@ -206,6 +210,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; Map body = { @@ -259,6 +264,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; Map body = { @@ -296,6 +302,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; Map body = {}; @@ -335,6 +342,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; // Use astrick to send to all known devices for user @@ -367,6 +375,7 @@ abstract class Events { Map headers = { 'Authorization': 'Bearer $accessToken', + ...Values.defaultHeaders, }; Map body = { diff --git a/lib/store/events/messages/actions.dart b/lib/store/events/messages/actions.dart index 0a8002856..d9e57361e 100644 --- a/lib/store/events/messages/actions.dart +++ b/lib/store/events/messages/actions.dart @@ -62,19 +62,23 @@ ThunkAction mutateMessagesAll({List messages}) { final roomMessages = store.state.eventStore.messages; await Future.wait(roomMessages.entries.map((entry) async { - final roomId = entry.key; - final allMessages = entry.value; - - final revisedMessages = await compute(reviseMessagesBackground, { - 'reactions': reactions, - 'redactions': redactions, - 'messages': allMessages, - }); - - await store.dispatch(setMessages( - room: Room(id: roomId), - messages: revisedMessages, - )); + try { + final roomId = entry.key; + final allMessages = entry.value; + + final revisedMessages = await compute(reviseMessagesBackground, { + 'reactions': reactions, + 'redactions': redactions, + 'messages': allMessages, + }); + + await store.dispatch(setMessages( + room: Room(id: roomId), + messages: revisedMessages, + )); + } catch (error) { + // TODO: Error handling for mutating messages per room + } })); }; } diff --git a/lib/store/events/selectors.dart b/lib/store/events/selectors.dart index 07f9228c6..44d6b3617 100644 --- a/lib/store/events/selectors.dart +++ b/lib/store/events/selectors.dart @@ -128,7 +128,7 @@ Map replaceEdited(List messages) { final messageOriginal = messagesMap[messageIdOriginal]; if (messageOriginal != null) { - final validEdit = messageEdited.senderKey == messageOriginal.senderKey; + final validEdit = messageEdited.sender == messageOriginal.sender; if (validEdit) { messagesMap[messageIdOriginal] = messageOriginal.copyWith( @@ -141,10 +141,10 @@ Map replaceEdited(List messages) { ], ); } - - // remove replacements from the returned messages - messagesMap.remove(messageEdited.id); } + + // remove replacements from the returned messages + messagesMap.remove(messageEdited.id); } return messagesMap; From 858753cb97476363499abcb9e5fd38f889a52d02 Mon Sep 17 00:00:00 2001 From: ereio Date: Sun, 21 Mar 2021 18:24:39 -0400 Subject: [PATCH 4/4] refactor: bit of cleanup and todos --- lib/store/auth/actions.dart | 1 + lib/store/events/messages/actions.dart | 4 +++- lib/store/events/selectors.dart | 27 +++++++++----------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/store/auth/actions.dart b/lib/store/auth/actions.dart index a2fa8fe7a..e029fe4b4 100644 --- a/lib/store/auth/actions.dart +++ b/lib/store/auth/actions.dart @@ -33,6 +33,7 @@ import 'package:syphon/store/auth/credential/model.dart'; import 'package:syphon/store/auth/homeserver/actions.dart'; import 'package:syphon/store/auth/homeserver/model.dart'; import 'package:syphon/store/crypto/actions.dart'; +import 'package:syphon/store/events/messages/actions.dart'; import 'package:syphon/store/index.dart'; import 'package:syphon/store/media/actions.dart'; import 'package:syphon/store/rooms/actions.dart'; diff --git a/lib/store/events/messages/actions.dart b/lib/store/events/messages/actions.dart index d9e57361e..cc4f9e52a 100644 --- a/lib/store/events/messages/actions.dart +++ b/lib/store/events/messages/actions.dart @@ -13,6 +13,7 @@ import 'package:syphon/global/algos.dart'; // Project imports: import 'package:syphon/global/libs/matrix/index.dart'; +import 'package:syphon/global/print.dart'; import 'package:syphon/store/alerts/actions.dart'; import 'package:syphon/store/crypto/actions.dart'; import 'package:syphon/store/crypto/events/actions.dart'; @@ -78,6 +79,7 @@ ThunkAction mutateMessagesAll({List messages}) { )); } catch (error) { // TODO: Error handling for mutating messages per room + debugPrint(error.toString()); } })); }; @@ -104,7 +106,7 @@ ThunkAction mutateMessagesRoom({Room room}) { 'messages': messages, }); - store.dispatch(setMessages( + await store.dispatch(setMessages( room: Room(id: room.id), messages: revisedMessages, )); diff --git a/lib/store/events/selectors.dart b/lib/store/events/selectors.dart index 44d6b3617..2acee7e72 100644 --- a/lib/store/events/selectors.dart +++ b/lib/store/events/selectors.dart @@ -22,23 +22,22 @@ List filterMessages( ) { final blocked = state.userStore.blocked; + // TODO: remove the replacement filter here, should be managed by the mutators return messages ..removeWhere( - (message) => blocked.contains(message.sender), + (message) => blocked.contains(message.sender) || message.replacement, ); } -List reviseMessages( - List messages, - AppState state, -) { - final reactions = selectReactions(state); - final redactions = state.eventStore.redactions; +List reviseMessagesBackground(Map params) { + List messages = params['messages']; + Map redactions = params['redactions']; + Map> reactions = params['reactions']; - return reviseMessagesAlt(messages, redactions, reactions); + return reviseMessagesFilter(messages, redactions, reactions); } -List reviseMessagesAlt( +List reviseMessagesFilter( List messages, Map redactions, Map> reactions, @@ -55,14 +54,6 @@ List reviseMessagesAlt( return List.from(messagesMap.values); } -List reviseMessagesBackground(Map params) { - List messages = params['messages']; - Map redactions = params['redactions']; - Map> reactions = params['reactions']; - - return reviseMessagesAlt(messages, redactions, reactions); -} - Map filterRedactions( Map messages, { Map redactions, @@ -106,7 +97,7 @@ Map appendReactions( Map replaceEdited(List messages) { final replacements = List(); - // create a map of messages for O(1) when replacing (O(N)) + // create a map of messages for O(1) when replacing O(N) final messagesMap = Map.fromIterable( messages ?? [], key: (msg) => msg.id,