Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: duplicated selections from remote (#5023)
Lucas.Xu893d23d6a3e9
diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/doc_collab_adapter.dart b/frontend/appflowy_flutter/lib/plugins/document/application/doc_collab_adapter.dartindex 598dfb3798..fc67e14ece 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/doc_collab_adapter.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/doc_collab_adapter.dart@@ -3,6 +3,7 @@ import 'dart:convert';import 'package:appflowy/plugins/document/application/doc_awareness_metadata.dart';import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';import 'package:appflowy/plugins/document/application/prelude.dart';+import 'package:appflowy/shared/list_extension.dart';import 'package:appflowy/startup/tasks/device_info_task.dart';import 'package:appflowy/util/color_generator/color_generator.dart';import 'package:appflowy/util/json_print.dart';@@ -138,7 +139,15 @@ class DocumentCollabAdapter {) async {final List<RemoteSelection> remoteSelections = [];final deviceId = ApplicationInfo.deviceId;- for (final state in states.value.values) {+ // the values may be duplicated, sort by the timestamp and then filter the duplicated values+ final values = states.value.values+ .sorted(+ (a, b) => b.timestamp.compareTo(a.timestamp),+ ) // in descending order+ .unique(+ (e) => Object.hashAll([e.user.uid, e.user.deviceId]),+ );+ for (final state in values) {// the following code is only for version 1if (state.version != 1) {return;diff --git a/frontend/appflowy_flutter/lib/shared/list_extension.dart b/frontend/appflowy_flutter/lib/shared/list_extension.dartnew file mode 100644index 0000000000..e701ec3c5e--- /dev/null+++ b/frontend/appflowy_flutter/lib/shared/list_extension.dart@@ -0,0 +1,8 @@+extension Unique<E, Id> on List<E> {+ List<E> unique([Id Function(E element)? id]) {+ final ids = <dynamic>{};+ final list = [...this];+ list.retainWhere((x) => ids.add(id != null ? id(x) : x as Id));+ return list;+ }+}diff --git a/frontend/rust-lib/flowy-core/src/integrate/log.rs b/frontend/rust-lib/flowy-core/src/integrate/log.rsindex 51156ea07c..8ffaa5e329 100644--- a/frontend/rust-lib/flowy-core/src/integrate/log.rs+++ b/frontend/rust-lib/flowy-core/src/integrate/log.rs@@ -4,7 +4,8 @@ use crate::AppFlowyCoreConfig;static INIT_LOG: AtomicBool = AtomicBool::new(false);pub(crate) fn init_log(config: &AppFlowyCoreConfig) {- if cfg!(debug_assertions) && get_bool_from_env_var("DISABLE_CI_TEST_LOG") {+ #[cfg(debug_assertions)]+ if get_bool_from_env_var("DISABLE_CI_TEST_LOG") {return;}