2023-06-26 21:40:47 +00:00
|
|
|
class ReshareViaService {
|
|
|
|
final _postsVia = <String, ResharedViaData>{};
|
|
|
|
|
|
|
|
ResharedViaData? getForPost(String postId) => _postsVia[postId];
|
|
|
|
|
|
|
|
void upsertResharedVia({required String postId, required String resharerId}) {
|
|
|
|
final resharedData = _postsVia.putIfAbsent(
|
|
|
|
postId,
|
|
|
|
() => ResharedViaData(postId: postId),
|
|
|
|
);
|
|
|
|
|
|
|
|
_postsVia[postId] = resharedData.withUpsertedResharer(resharerId);
|
|
|
|
}
|
2023-11-19 13:05:49 +00:00
|
|
|
|
|
|
|
void upsertRemovedSharer(
|
|
|
|
{required String postId, required String resharerId}) {
|
|
|
|
final resharedData = _postsVia.putIfAbsent(
|
|
|
|
postId,
|
|
|
|
() => ResharedViaData(postId: postId),
|
|
|
|
);
|
|
|
|
|
|
|
|
_postsVia[postId] = resharedData.withRemovedResharer(resharerId);
|
|
|
|
}
|
2023-06-26 21:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ResharedViaData {
|
|
|
|
final String postId;
|
|
|
|
final Set<String> resharers;
|
|
|
|
|
|
|
|
bool get hasResharedVia => resharers.isNotEmpty;
|
|
|
|
|
|
|
|
const ResharedViaData({
|
|
|
|
required this.postId,
|
|
|
|
this.resharers = const {},
|
|
|
|
});
|
|
|
|
|
|
|
|
ResharedViaData withUpsertedResharer(String resharerId) => ResharedViaData(
|
|
|
|
postId: postId,
|
|
|
|
resharers: {resharerId, ...resharers},
|
|
|
|
);
|
2023-11-19 13:05:49 +00:00
|
|
|
|
|
|
|
ResharedViaData withRemovedResharer(String resharerId) => ResharedViaData(
|
|
|
|
postId: postId,
|
|
|
|
resharers: resharers..remove(resharerId),
|
|
|
|
);
|
2023-06-26 21:40:47 +00:00
|
|
|
}
|