From 6f144198b7279a24c4263325bfbab24daaa28fae Mon Sep 17 00:00:00 2001 From: Krille Date: Fri, 20 Oct 2023 15:12:23 +0200 Subject: [PATCH 1/4] fix: Do not convert linebreaks in pre blocks on markdown parsing --- lib/src/utils/markdown.dart | 15 ++++++++++++++- test/markdown_test.dart | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/src/utils/markdown.dart b/lib/src/utils/markdown.dart index 18aae2b9..93a37eac 100644 --- a/lib/src/utils/markdown.dart +++ b/lib/src/utils/markdown.dart @@ -258,8 +258,21 @@ String markdown( // Remove trailing linebreaks .replaceAll(RegExp(r'(
)+$'), ''); if (convertLinebreaks) { - ret = ret.replaceAll('\n', '
'); + // Only convert linebreaks which are not in
 blocks
+    ret = ret.convertLinebreaksToBr();
   }
 
   return ret;
 }
+
+extension on String {
+  String convertLinebreaksToBr() {
+    final parts = split('pre>');
+    var convertLinebreaks = true;
+    for (var i = 0; i < parts.length; i++) {
+      if (convertLinebreaks) parts[i] = parts[i].replaceAll('\n', '
'); + convertLinebreaks = !convertLinebreaks; + } + return parts.join('pre>'); + } +} diff --git a/test/markdown_test.dart b/test/markdown_test.dart index 4445670a..4e88b5a4 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -123,5 +123,22 @@ void main() { expect(markdown('meep `\$\\frac{2}{3}\$`'), 'meep \$\\frac{2}{3}\$'); }); + test('Code blocks', () { + expect( + markdown( + '```dart\nvoid main(){\nprint(something);\n}\n```', + convertLinebreaks: true, + ), + '
void main(){\nprint(something);\n}\n
', + ); + + expect( + markdown( + 'The first \n codeblock\n```dart\nvoid main(){\nprint(something);\n}\n```\nAnd the second code block\n```js\nmeow\nmeow\n```', + convertLinebreaks: true, + ), + '

The first
codeblock


void main(){\nprint(something);\n}\n

And the second code block


meow\nmeow\n
', + ); + }); }); } From f0e423293099685fafd18a3179407871e770ca8e Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 23 Oct 2023 09:22:15 +0200 Subject: [PATCH 2/4] refactor: Wait for room in sync until sync process and trigger cleanup call not before actually start clean up. --- lib/src/client.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 23fa4769..2b03896a 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -739,10 +739,17 @@ class Client extends MatrixApi { leave = true; } - return await onSync.stream.firstWhere((sync) => + // Wait for the next sync where this room appears. + final syncUpdate = await onSync.stream.firstWhere((sync) => invite && (sync.rooms?.invite?.containsKey(roomId) ?? false) || join && (sync.rooms?.join?.containsKey(roomId) ?? false) || leave && (sync.rooms?.leave?.containsKey(roomId) ?? false)); + + // Wait for this sync to be completely processed. + await onSyncStatus.stream.firstWhere( + (syncStatus) => syncStatus.status == SyncStatus.finished, + ); + return syncUpdate; } /// Checks if the given user has encryption keys. May query keys from the @@ -1659,7 +1666,7 @@ class Client extends MatrixApi { Logs().d('Running sync while init isn\'t done yet, dropping request'); return; } - dynamic syncError; + Object? syncError; await _checkSyncFilter(); timeout ??= const Duration(seconds: 30); final syncRequest = sync( @@ -1699,12 +1706,12 @@ class Client extends MatrixApi { () async => await _currentTransaction, syncResp.itemCount, ); - onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp)); } else { await _handleSync(syncResp, direction: Direction.f); } if (_disposed || _aborted) return; prevBatch = syncResp.nextBatch; + onSyncStatus.add(SyncStatusUpdate(SyncStatus.cleaningUp)); // ignore: unawaited_futures database?.deleteOldFiles( DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch); From 569fa186cfce3ce3a6620012494f3c2a74c4adab Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 23 Oct 2023 13:03:30 +0200 Subject: [PATCH 3/4] build: Release 0.22.6 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82deb5b2..953efe2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.22.6] - 23 October 2023 +- fix: Do not convert linebreaks in pre blocks on markdown parsing (Krille) +- refactor: Wait for room in sync until sync process and trigger cleanup call not before actually start clean up. (Krille) + ## [0.22.5] - 20 October 2023 - build(deps): bump http from 0.13.6 to 1.1.0 (dependabot[bot]) - feat: Add methods to load all room keys from online key backup (Krille) diff --git a/pubspec.yaml b/pubspec.yaml index 25daf555..f8d71f0f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: matrix description: Matrix Dart SDK -version: 0.22.5 +version: 0.22.6 homepage: https://famedly.com repository: https://github.com/famedly/matrix-dart-sdk.git From 318134d6f4cb786cd87d9a99b23c771c5a2ab7a4 Mon Sep 17 00:00:00 2001 From: td Date: Wed, 25 Oct 2023 04:17:01 +0530 Subject: [PATCH 4/4] chore: use our custom reusable workflow to avoid manually configuring each publish job --- .github/workflows/publish.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ae696f7f..de10fd3a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,6 @@ on: jobs: publish: permissions: - id-token: write # Required for authentication using OIDC - uses: dart-lang/setup-dart/.github/workflows/publish.yml@a57a6c04cf7d4840e88432aad6281d1e125f0d46 - with: - environment: pub.dev + contents: read + id-token: write + uses: famedly/frontend-ci-templates/.github/workflows/publish-pub.yml@main