Added ability to replace user photo entry in storage.
This commit is contained in:
@@ -34,6 +34,7 @@ public:
|
||||
void add(UserPhotosAddSlice &&query);
|
||||
void remove(UserPhotosRemoveOne &&query);
|
||||
void remove(UserPhotosRemoveAfter &&query);
|
||||
void replace(UserPhotosReplace &&query);
|
||||
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
||||
rpl::producer<UserPhotosSliceUpdate> userPhotosSliceUpdated() const;
|
||||
|
||||
@@ -119,6 +120,10 @@ void Facade::Impl::remove(UserPhotosRemoveAfter &&query) {
|
||||
return _userPhotos.remove(std::move(query));
|
||||
}
|
||||
|
||||
void Facade::Impl::replace(UserPhotosReplace &&query) {
|
||||
return _userPhotos.replace(std::move(query));
|
||||
}
|
||||
|
||||
rpl::producer<UserPhotosResult> Facade::Impl::query(UserPhotosQuery &&query) const {
|
||||
return _userPhotos.query(std::move(query));
|
||||
}
|
||||
@@ -206,6 +211,10 @@ void Facade::remove(UserPhotosRemoveAfter &&query) {
|
||||
return _impl->remove(std::move(query));
|
||||
}
|
||||
|
||||
void Facade::replace(UserPhotosReplace &&query) {
|
||||
return _impl->replace(std::move(query));
|
||||
}
|
||||
|
||||
rpl::producer<UserPhotosResult> Facade::query(UserPhotosQuery &&query) const {
|
||||
return _impl->query(std::move(query));
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ struct UserPhotosAddNew;
|
||||
struct UserPhotosAddSlice;
|
||||
struct UserPhotosRemoveOne;
|
||||
struct UserPhotosRemoveAfter;
|
||||
struct UserPhotosReplace;
|
||||
struct UserPhotosQuery;
|
||||
struct UserPhotosResult;
|
||||
struct UserPhotosSliceUpdate;
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
void add(UserPhotosAddSlice &&query);
|
||||
void remove(UserPhotosRemoveOne &&query);
|
||||
void remove(UserPhotosRemoveAfter &&query);
|
||||
void replace(UserPhotosReplace &&query);
|
||||
|
||||
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
||||
rpl::producer<UserPhotosSliceUpdate> userPhotosSliceUpdated() const;
|
||||
|
||||
@@ -90,6 +90,17 @@ void UserPhotos::List::removeAfter(PhotoId photoId) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
void UserPhotos::List::replace(PhotoId oldPhotoId, PhotoId newPhotoId) {
|
||||
auto position = ranges::find(_photoIds, oldPhotoId);
|
||||
if (position != _photoIds.end()) {
|
||||
*position = newPhotoId;
|
||||
}
|
||||
if (_backPhotoId == oldPhotoId) {
|
||||
_backPhotoId = newPhotoId;
|
||||
}
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
void UserPhotos::List::sendUpdate() {
|
||||
auto update = SliceUpdate();
|
||||
update.photoIds = &_photoIds;
|
||||
@@ -188,6 +199,13 @@ void UserPhotos::remove(UserPhotosRemoveAfter &&query) {
|
||||
}
|
||||
}
|
||||
|
||||
void UserPhotos::replace(UserPhotosReplace &&query) {
|
||||
auto userIt = _lists.find(query.userId);
|
||||
if (userIt != _lists.end()) {
|
||||
userIt->second.replace(query.oldPhotoId, query.newPhotoId);
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<UserPhotosResult> UserPhotos::query(
|
||||
UserPhotosQuery &&query) const {
|
||||
auto userIt = _lists.find(query.key.userId);
|
||||
|
||||
@@ -74,6 +74,22 @@ struct UserPhotosRemoveAfter {
|
||||
|
||||
};
|
||||
|
||||
struct UserPhotosReplace {
|
||||
UserPhotosReplace(
|
||||
UserId userId,
|
||||
PhotoId oldPhotoId,
|
||||
PhotoId newPhotoId)
|
||||
: userId(userId)
|
||||
, oldPhotoId(oldPhotoId)
|
||||
, newPhotoId(newPhotoId) {
|
||||
}
|
||||
|
||||
UserId userId = 0;
|
||||
PhotoId oldPhotoId = 0;
|
||||
PhotoId newPhotoId = 0;
|
||||
|
||||
};
|
||||
|
||||
struct UserPhotosKey {
|
||||
UserPhotosKey(
|
||||
UserId userId,
|
||||
@@ -144,6 +160,7 @@ public:
|
||||
void add(UserPhotosAddSlice &&query);
|
||||
void remove(UserPhotosRemoveOne &&query);
|
||||
void remove(UserPhotosRemoveAfter &&query);
|
||||
void replace(UserPhotosReplace &&query);
|
||||
|
||||
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
||||
rpl::producer<UserPhotosSliceUpdate> sliceUpdated() const;
|
||||
@@ -158,6 +175,7 @@ private:
|
||||
int count);
|
||||
void removeOne(PhotoId photoId);
|
||||
void removeAfter(PhotoId photoId);
|
||||
void replace(PhotoId oldPhotoId, PhotoId newPhotoId);
|
||||
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
||||
|
||||
struct SliceUpdate {
|
||||
|
||||
Reference in New Issue
Block a user