fix: duplicated selections from remote (#5023)

* fix: duplicated selections from remote

* fix: docker ci
This commit is contained in:
Lucas.Xu 2024-04-01 12:08:52 +08:00 committed by GitHub
parent 932a403b5d
commit 893d23d6a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:appflowy/plugins/document/application/doc_awareness_metadata.dart'; 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/document_data_pb_extension.dart';
import 'package:appflowy/plugins/document/application/prelude.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/startup/tasks/device_info_task.dart';
import 'package:appflowy/util/color_generator/color_generator.dart'; import 'package:appflowy/util/color_generator/color_generator.dart';
import 'package:appflowy/util/json_print.dart'; import 'package:appflowy/util/json_print.dart';
@ -138,7 +139,15 @@ class DocumentCollabAdapter {
) async { ) async {
final List<RemoteSelection> remoteSelections = []; final List<RemoteSelection> remoteSelections = [];
final deviceId = ApplicationInfo.deviceId; 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 1 // the following code is only for version 1
if (state.version != 1) { if (state.version != 1) {
return; return;

View File

@ -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;
}
}

View File

@ -4,7 +4,8 @@ use crate::AppFlowyCoreConfig;
static INIT_LOG: AtomicBool = AtomicBool::new(false); static INIT_LOG: AtomicBool = AtomicBool::new(false);
pub(crate) fn init_log(config: &AppFlowyCoreConfig) { 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; return;
} }