| 193 | } |
| 194 | |
| 195 | void PeerColors::applyProfile(const MTPDhelp_peerColors &data) { |
| 196 | const auto parseColors = [](const MTPhelp_PeerColorSet &set) { |
| 197 | const auto toUint = [](const MTPint &c) { |
| 198 | return (uint32(1) << 24) | uint32(c.v); |
| 199 | }; |
| 200 | return set.match([&](const MTPDhelp_peerColorSet &) { |
| 201 | LOG(("API Error: peerColorSet in profile colors result!")); |
| 202 | return Data::ColorProfileSet(); |
| 203 | }, [&](const MTPDhelp_peerColorProfileSet &data) { |
| 204 | auto set = Data::ColorProfileSet(); |
| 205 | set.palette.reserve(data.vpalette_colors().v.size()); |
| 206 | set.bg.reserve(data.vbg_colors().v.size()); |
| 207 | set.story.reserve(data.vstory_colors().v.size()); |
| 208 | for (const auto &c : data.vpalette_colors().v) { |
| 209 | set.palette.push_back(Ui::ColorFromSerialized(toUint(c))); |
| 210 | } |
| 211 | for (const auto &c : data.vbg_colors().v) { |
| 212 | set.bg.push_back(Ui::ColorFromSerialized(toUint(c))); |
| 213 | } |
| 214 | for (const auto &c : data.vstory_colors().v) { |
| 215 | set.story.push_back(Ui::ColorFromSerialized(toUint(c))); |
| 216 | } |
| 217 | return set; |
| 218 | }); |
| 219 | }; |
| 220 | |
| 221 | auto suggested = std::vector<Data::ColorProfileData>(); |
| 222 | const auto &list = data.vcolors().v; |
| 223 | suggested.reserve(list.size()); |
| 224 | for (const auto &color : list) { |
| 225 | const auto &data = color.data(); |
| 226 | const auto colorIndexBare = data.vcolor_id().v; |
| 227 | if (colorIndexBare < 0 || colorIndexBare >= Ui::kColorIndexCount) { |
| 228 | LOG(("API Error: Bad color index: %1").arg(colorIndexBare)); |
| 229 | continue; |
| 230 | } |
| 231 | const auto colorIndex = uint8(colorIndexBare); |
| 232 | auto result = ProfileColorOption(); |
| 233 | result.isHidden = data.is_hidden(); |
| 234 | if (const auto min = data.vgroup_min_level()) { |
| 235 | result.requiredLevelsGroup = min->v; |
| 236 | } |
| 237 | if (const auto min = data.vchannel_min_level()) { |
| 238 | result.requiredLevelsChannel = min->v; |
| 239 | } |
| 240 | if (const auto light = data.vcolors()) { |
| 241 | result.data.light = parseColors(*light); |
| 242 | } |
| 243 | if (const auto dark = data.vdark_colors()) { |
| 244 | result.data.dark = parseColors(*dark); |
| 245 | } |
| 246 | _profileColors[colorIndex] = std::move(result); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | std::optional<Data::ColorProfileSet> PeerColors::colorProfileFor( |
| 251 | not_null<PeerData*> peer) const { |
nothing calls this directly
no test coverage detected