Fix reshare regression so that updates to reshare appear.

codemagic-setup
Hank Grabowski 2023-11-19 08:05:49 -05:00
rodzic 6e011f9ef9
commit 68772cf122
5 zmienionych plików z 103 dodań i 44 usunięć

Wyświetl plik

@ -14,6 +14,8 @@ class EntryTreeItem {
_children.addAll(initialChildren ?? {});
}
factory EntryTreeItem.empty() => EntryTreeItem(TimelineEntry());
EntryTreeItem copy({required TimelineEntry entry}) => EntryTreeItem(
entry,
isMine: isMine,

Wyświetl plik

@ -5,6 +5,7 @@ import 'package:result_monad/result_monad.dart';
import '../friendica_client/friendica_client.dart';
import '../friendica_client/paging_data.dart';
import '../globals.dart';
import '../models/TimelineIdentifiers.dart';
import '../models/auth/profile.dart';
import '../models/entry_tree_item.dart';
@ -13,7 +14,9 @@ import '../models/image_entry.dart';
import '../models/media_attachment_uploads/new_entry_media_items.dart';
import '../models/timeline_entry.dart';
import '../models/visibility.dart';
import '../utils/active_profile_selector.dart';
import 'media_upload_attachment_helper.dart';
import 'reshared_via_service.dart';
class EntryManagerService extends ChangeNotifier {
static final _logger = Logger('$EntryManagerService');
@ -425,33 +428,55 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<EntryTreeItem, ExecError> resharePost(String id) async {
_logger.finest('Resharing post: $id');
final resharedViaService = getIt<ActiveProfileSelector<ReshareViaService>>()
.getForProfile(profile)
.fold(
onSuccess: (s) => s,
onError: (error) {
_logger.severe('Error getting reshared via service: $error');
return null;
});
final client = StatusesClient(profile);
final idForCall = id;
final result =
await client.resharePost(idForCall).andThenSuccessAsync((item) async {
resharedViaService?.upsertResharedVia(postId: id, resharerId: profile.id);
await processNewItems([item], client.profile.username, null);
});
return result.mapValue((_) {
_logger.finest('$id post updated after reshare');
return _nodeToTreeItem(_postNodes[id]!, client.profile.userId);
}).mapError(
(error) {
_logger.finest('$id error updating: $error');
return ExecError(
type: ErrorType.localError,
message: error.toString(),
return result
.mapValue((_) {
_logger.finest('$id post updated after reshare');
return _nodeToTreeItem(_postNodes[id]!, client.profile.userId);
})
.withResult((_) => notifyListeners())
.mapError(
(error) {
_logger.finest('$id error updating: $error');
return ExecError(
type: ErrorType.localError,
message: error.toString(),
);
},
);
},
);
}
FutureResult<bool, ExecError> unResharePost(String id) async {
FutureResult<EntryTreeItem, ExecError> unResharePost(String id) async {
_logger.finest('Unresharing post: $id');
final resharedViaService = getIt<ActiveProfileSelector<ReshareViaService>>()
.getForProfile(profile)
.fold(
onSuccess: (s) => s,
onError: (error) {
_logger.severe('Error getting reshared via service: $error');
return null;
});
final client = StatusesClient(profile);
final idForCall = id;
final result =
await client.unResharePost(idForCall).andThenSuccessAsync((item) async {
resharedViaService?.upsertRemovedSharer(
postId: id, resharerId: profile.id);
await processNewItems([item], client.profile.username, null);
});
@ -459,10 +484,21 @@ class EntryManagerService extends ChangeNotifier {
return Result.error(result.error);
}
_cleanupEntriesForId(id);
notifyListeners();
return Result.ok(true);
return result
.mapValue((_) {
_logger.finest('$id post updated after reshare');
return _nodeToTreeItem(_postNodes[id]!, client.profile.userId);
})
.withResult((_) => notifyListeners())
.mapError(
(error) {
_logger.finest('$id error updating: $error');
return ExecError(
type: ErrorType.localError,
message: error.toString(),
);
},
);
}
FutureResult<EntryTreeItem, ExecError> toggleFavorited(

Wyświetl plik

@ -11,6 +11,16 @@ class ReshareViaService {
_postsVia[postId] = resharedData.withUpsertedResharer(resharerId);
}
void upsertRemovedSharer(
{required String postId, required String resharerId}) {
final resharedData = _postsVia.putIfAbsent(
postId,
() => ResharedViaData(postId: postId),
);
_postsVia[postId] = resharedData.withRemovedResharer(resharerId);
}
}
class ResharedViaData {
@ -28,4 +38,9 @@ class ResharedViaData {
postId: postId,
resharers: {resharerId, ...resharers},
);
ResharedViaData withRemovedResharer(String resharerId) => ResharedViaData(
postId: postId,
resharers: resharers..remove(resharerId),
);
}

Wyświetl plik

@ -154,15 +154,29 @@ class TimelineManager extends ChangeNotifier {
FutureResult<EntryTreeItem, ExecError> resharePost(String id) async {
final result = await entryManagerService.resharePost(id);
final empty = EntryTreeItem.empty();
if (result.isSuccess) {
for (final t in cachedTimelines.values) {
if (t.posts.firstWhere((p) => p.id == id, orElse: () => empty) !=
empty) {
t.addOrUpdate([result.value]);
}
}
notifyListeners();
}
return result;
}
FutureResult<bool, ExecError> unResharePost(String id) async {
FutureResult<EntryTreeItem, ExecError> unResharePost(String id) async {
final result = await entryManagerService.unResharePost(id);
final empty = EntryTreeItem.empty();
if (result.isSuccess) {
for (final t in cachedTimelines.values) {
if (t.posts.firstWhere((p) => p.id == id, orElse: () => empty) !=
empty) {
t.addOrUpdate([result.value]);
}
}
notifyListeners();
}
return result;

Wyświetl plik

@ -181,10 +181,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.1"
color_blindness:
dependency: "direct main"
description:
@ -705,10 +705,10 @@ packages:
dependency: transitive
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6
url: "https://pub.dev"
source: hosted
version: "0.18.1"
version: "0.18.0"
io:
dependency: transitive
description:
@ -761,18 +761,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.15"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.2.0"
media_kit:
dependency: "direct main"
description:
@ -849,10 +849,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.9.1"
mime:
dependency: transitive
description:
@ -1239,10 +1239,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.9.1"
sprintf:
dependency: transitive
description:
@ -1279,18 +1279,18 @@ packages:
dependency: "direct main"
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
stream_transform:
dependency: transitive
description:
@ -1335,10 +1335,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.5.1"
time_machine:
dependency: "direct main"
description:
@ -1555,14 +1555,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
@ -1620,5 +1612,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0"