"Fossies" - the Fresh Open Source Software Archive 
Member "tdesktop-2.6.1/Telegram/SourceFiles/storage/storage_user_photos.h" (24 Feb 2021, 3361 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "storage_user_photos.h" see the
Fossies "Dox" file reference documentation.
1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9
10 #include <rpl/event_stream.h>
11 #include "storage/storage_facade.h"
12
13 namespace Storage {
14
15 struct UserPhotosAddNew {
16 UserPhotosAddNew(UserId userId, PhotoId photoId)
17 : userId(userId), photoId(photoId) {
18 }
19
20 UserId userId = 0;
21 PhotoId photoId = 0;
22
23 };
24
25 struct UserPhotosAddSlice {
26 UserPhotosAddSlice(
27 UserId userId,
28 std::vector<PhotoId> &&photoIds,
29 int count)
30 : userId(userId)
31 , photoIds(std::move(photoIds))
32 , count(count) {
33 }
34
35 UserId userId = 0;
36 std::vector<PhotoId> photoIds;
37 int count = 0;
38
39 };
40
41 struct UserPhotosRemoveOne {
42 UserPhotosRemoveOne(
43 UserId userId,
44 PhotoId photoId)
45 : userId(userId)
46 , photoId(photoId) {
47 }
48
49 UserId userId = 0;
50 PhotoId photoId = 0;
51
52 };
53
54 struct UserPhotosRemoveAfter {
55 UserPhotosRemoveAfter(
56 UserId userId,
57 PhotoId photoId)
58 : userId(userId)
59 , photoId(photoId) {
60 }
61
62 UserId userId = 0;
63 PhotoId photoId = 0;
64
65 };
66
67 struct UserPhotosKey {
68 UserPhotosKey(
69 UserId userId,
70 PhotoId photoId)
71 : userId(userId)
72 , photoId(photoId) {
73 }
74
75 bool operator==(const UserPhotosKey &other) const {
76 return (userId == other.userId)
77 && (photoId == other.photoId);
78 }
79 bool operator!=(const UserPhotosKey &other) const {
80 return !(*this == other);
81 }
82
83 UserId userId = 0;
84 PhotoId photoId = 0;
85
86 };
87
88 struct UserPhotosQuery {
89 UserPhotosQuery(
90 UserPhotosKey key,
91 int limitBefore,
92 int limitAfter)
93 : key(key)
94 , limitBefore(limitBefore)
95 , limitAfter(limitAfter) {
96 }
97
98 UserPhotosKey key;
99 int limitBefore = 0;
100 int limitAfter = 0;
101
102 };
103
104 struct UserPhotosResult {
105 std::optional<int> count;
106 std::optional<int> skippedBefore;
107 int skippedAfter = 0;
108 std::deque<PhotoId> photoIds;
109 };
110
111 struct UserPhotosSliceUpdate {
112 UserPhotosSliceUpdate(
113 UserId userId,
114 const std::deque<PhotoId> *photoIds,
115 std::optional<int> count)
116 : userId(userId)
117 , photoIds(photoIds)
118 , count(count) {
119 }
120
121 UserId userId = 0;
122 const std::deque<PhotoId> *photoIds = nullptr;
123 std::optional<int> count;
124 };
125
126 class UserPhotos {
127 public:
128 void add(UserPhotosAddNew &&query);
129 void add(UserPhotosAddSlice &&query);
130 void remove(UserPhotosRemoveOne &&query);
131 void remove(UserPhotosRemoveAfter &&query);
132
133 rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
134 rpl::producer<UserPhotosSliceUpdate> sliceUpdated() const;
135
136 private:
137 class List {
138 public:
139 void addNew(PhotoId photoId);
140 void addSlice(
141 std::vector<PhotoId> &&photoIds,
142 int count);
143 void removeOne(PhotoId photoId);
144 void removeAfter(PhotoId photoId);
145 rpl::producer<UserPhotosResult> query(UserPhotosQuery &&query) const;
146
147 struct SliceUpdate {
148 const std::deque<PhotoId> *photoIds = nullptr;
149 std::optional<int> count;
150 };
151 rpl::producer<SliceUpdate> sliceUpdated() const;
152
153 private:
154 void sendUpdate();
155
156 std::optional<int> _count;
157 std::deque<PhotoId> _photoIds;
158
159 rpl::event_stream<SliceUpdate> _sliceUpdated;
160
161 };
162 using SliceUpdate = List::SliceUpdate;
163
164 std::map<UserId, List>::iterator enforceLists(UserId user);
165
166 std::map<UserId, List> _lists;
167
168 rpl::event_stream<UserPhotosSliceUpdate> _sliceUpdated;
169
170 rpl::lifetime _lifetime;
171
172 };
173
174 } // namespace Storage