mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: duplicated selections from remote (#5023)
* fix: duplicated selections from remote * fix: docker ci
This commit is contained in:
parent
932a403b5d
commit
893d23d6a3
@ -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 1
|
||||
if (state.version != 1) {
|
||||
return;
|
||||
|
8
frontend/appflowy_flutter/lib/shared/list_extension.dart
Normal file
8
frontend/appflowy_flutter/lib/shared/list_extension.dart
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user