2017-08-29 19:52:52 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-08-29 19:52:52 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-08-29 19:52:52 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include <rpl/event_stream.h>
|
2017-08-29 19:52:52 +00:00
|
|
|
#include "storage/storage_facade.h"
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
|
2022-12-19 10:01:32 +00:00
|
|
|
struct UserPhotosSetBack {
|
|
|
|
UserPhotosSetBack(UserId userId, PhotoId photoId)
|
|
|
|
: userId(userId), photoId(photoId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
PhotoId photoId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-29 19:52:52 +00:00
|
|
|
struct UserPhotosAddNew {
|
|
|
|
UserPhotosAddNew(UserId userId, PhotoId photoId)
|
|
|
|
: userId(userId), photoId(photoId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
PhotoId photoId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosAddSlice {
|
|
|
|
UserPhotosAddSlice(
|
|
|
|
UserId userId,
|
|
|
|
std::vector<PhotoId> &&photoIds,
|
|
|
|
int count)
|
|
|
|
: userId(userId)
|
|
|
|
, photoIds(std::move(photoIds))
|
|
|
|
, count(count) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
std::vector<PhotoId> photoIds;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosRemoveOne {
|
|
|
|
UserPhotosRemoveOne(
|
|
|
|
UserId userId,
|
|
|
|
PhotoId photoId)
|
2021-04-01 21:04:10 +00:00
|
|
|
: userId(userId)
|
|
|
|
, photoId(photoId) {
|
2017-08-29 19:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
PhotoId photoId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosRemoveAfter {
|
|
|
|
UserPhotosRemoveAfter(
|
|
|
|
UserId userId,
|
|
|
|
PhotoId photoId)
|
|
|
|
: userId(userId)
|
|
|
|
, photoId(photoId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
PhotoId photoId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosKey {
|
|
|
|
UserPhotosKey(
|
|
|
|
UserId userId,
|
|
|
|
PhotoId photoId)
|
|
|
|
: userId(userId)
|
|
|
|
, photoId(photoId) {
|
|
|
|
}
|
2022-12-19 10:01:32 +00:00
|
|
|
UserPhotosKey(UserId userId, bool back) : userId(userId), back(back) {
|
|
|
|
}
|
2017-08-29 19:52:52 +00:00
|
|
|
|
|
|
|
bool operator==(const UserPhotosKey &other) const {
|
|
|
|
return (userId == other.userId)
|
2022-12-19 10:01:32 +00:00
|
|
|
&& (photoId == other.photoId)
|
|
|
|
&& (back == other.back);
|
2017-08-29 19:52:52 +00:00
|
|
|
}
|
|
|
|
bool operator!=(const UserPhotosKey &other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
UserId userId = 0;
|
2017-08-29 19:52:52 +00:00
|
|
|
PhotoId photoId = 0;
|
2022-12-19 10:01:32 +00:00
|
|
|
bool back = false;
|
2017-08-29 19:52:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosQuery {
|
|
|
|
UserPhotosQuery(
|
|
|
|
UserPhotosKey key,
|
|
|
|
int limitBefore,
|
|
|
|
int limitAfter)
|
|
|
|
: key(key)
|
|
|
|
, limitBefore(limitBefore)
|
|
|
|
, limitAfter(limitAfter) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserPhotosKey key;
|
|
|
|
int limitBefore = 0;
|
|
|
|
int limitAfter = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosResult {
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> count;
|
|
|
|
std::optional<int> skippedBefore;
|
2017-08-29 19:52:52 +00:00
|
|
|
int skippedAfter = 0;
|
|
|
|
std::deque<PhotoId> photoIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserPhotosSliceUpdate {
|
|
|
|
UserPhotosSliceUpdate(
|
|
|
|
UserId userId,
|
|
|
|
const std::deque<PhotoId> *photoIds,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> count)
|
2017-08-29 19:52:52 +00:00
|
|
|
: userId(userId)
|
|
|
|
, photoIds(photoIds)
|
|
|
|
, count(count) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UserId userId = 0;
|
|
|
|
const std::deque<PhotoId> *photoIds = nullptr;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> count;
|
2017-08-29 19:52:52 +00:00
|
|
|
};
|
|
|
|
|
2017-09-06 14:50:11 +00:00
|
|
|
class UserPhotos {
|
2017-08-29 19:52:52 +00:00
|
|
|
public:
|
2022-12-19 10:01:32 +00:00
|
|
|
void add(UserPhotosSetBack &&query);
|
2017-08-29 19:52:52 +00:00
|
|
|
void add(UserPhotosAddNew &&query);
|
|
|
|
void add(UserPhotosAddSlice &&query);
|
|
|
|
void remove(UserPhotosRemoveOne &&query);
|
|
|
|
void remove(UserPhotosRemoveAfter &&query);
|
|
|
|
|
2017-09-06 14:50:11 +00:00
|
|
|
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<UserPhotosSliceUpdate> sliceUpdated() const;
|
2017-08-29 19:52:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
class List {
|
|
|
|
public:
|
2022-12-19 10:01:32 +00:00
|
|
|
void setBack(PhotoId photoId);
|
2017-08-29 19:52:52 +00:00
|
|
|
void addNew(PhotoId photoId);
|
|
|
|
void addSlice(
|
|
|
|
std::vector<PhotoId> &&photoIds,
|
|
|
|
int count);
|
|
|
|
void removeOne(PhotoId photoId);
|
|
|
|
void removeAfter(PhotoId photoId);
|
2017-09-06 14:50:11 +00:00
|
|
|
rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
|
2017-08-29 19:52:52 +00:00
|
|
|
|
|
|
|
struct SliceUpdate {
|
|
|
|
const std::deque<PhotoId> *photoIds = nullptr;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> count;
|
2017-08-29 19:52:52 +00:00
|
|
|
};
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<SliceUpdate> sliceUpdated() const;
|
2017-08-29 19:52:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void sendUpdate();
|
2022-12-19 10:01:32 +00:00
|
|
|
void detachBack();
|
|
|
|
void attachBack();
|
2017-08-29 19:52:52 +00:00
|
|
|
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> _count;
|
2017-08-29 19:52:52 +00:00
|
|
|
std::deque<PhotoId> _photoIds;
|
|
|
|
|
2022-12-19 10:01:32 +00:00
|
|
|
PhotoId _backPhotoId = PhotoId(0);
|
|
|
|
|
2017-09-06 14:50:11 +00:00
|
|
|
rpl::event_stream<SliceUpdate> _sliceUpdated;
|
|
|
|
|
2017-08-29 19:52:52 +00:00
|
|
|
};
|
|
|
|
using SliceUpdate = List::SliceUpdate;
|
|
|
|
|
|
|
|
std::map<UserId, List>::iterator enforceLists(UserId user);
|
|
|
|
|
|
|
|
std::map<UserId, List> _lists;
|
|
|
|
|
2017-09-06 14:50:11 +00:00
|
|
|
rpl::event_stream<UserPhotosSliceUpdate> _sliceUpdated;
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-08-29 19:52:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Storage
|