| 124 | } |
| 125 | |
| 126 | void PeerColors::apply(const MTPDhelp_peerColors &data) { |
| 127 | auto suggested = std::vector<uint8>(); |
| 128 | auto colors = std::make_shared< |
| 129 | std::array<Ui::ColorIndexData, Ui::kColorIndexCount>>(); |
| 130 | |
| 131 | using ParsedColor = std::array<uint32, Ui::kColorPatternsCount>; |
| 132 | const auto parseColors = [](const MTPhelp_PeerColorSet &set) { |
| 133 | return set.match([&](const MTPDhelp_peerColorSet &data) { |
| 134 | auto result = ParsedColor(); |
| 135 | const auto &list = data.vcolors().v; |
| 136 | if (list.empty() || list.size() > Ui::kColorPatternsCount) { |
| 137 | LOG(("API Error: Bad count for PeerColorSet.colors: %1" |
| 138 | ).arg(list.size())); |
| 139 | return ParsedColor(); |
| 140 | } |
| 141 | auto fill = result.data(); |
| 142 | for (const auto &color : list) { |
| 143 | *fill++ = (uint32(1) << 24) | uint32(color.v); |
| 144 | } |
| 145 | return result; |
| 146 | }, [](const MTPDhelp_peerColorProfileSet &) { |
| 147 | LOG(("API Error: peerColorProfileSet in colors result!")); |
| 148 | return ParsedColor(); |
| 149 | }); |
| 150 | }; |
| 151 | |
| 152 | const auto &list = data.vcolors().v; |
| 153 | _requiredLevelsGroup.clear(); |
| 154 | _requiredLevelsChannel.clear(); |
| 155 | suggested.reserve(list.size()); |
| 156 | for (const auto &color : list) { |
| 157 | const auto &data = color.data(); |
| 158 | const auto colorIndexBare = data.vcolor_id().v; |
| 159 | if (colorIndexBare < 0 || colorIndexBare >= Ui::kColorIndexCount) { |
| 160 | LOG(("API Error: Bad color index: %1").arg(colorIndexBare)); |
| 161 | continue; |
| 162 | } |
| 163 | const auto colorIndex = uint8(colorIndexBare); |
| 164 | if (const auto min = data.vgroup_min_level()) { |
| 165 | _requiredLevelsGroup[colorIndex] = min->v; |
| 166 | } |
| 167 | if (const auto min = data.vchannel_min_level()) { |
| 168 | _requiredLevelsChannel[colorIndex] = min->v; |
| 169 | } |
| 170 | if (!data.is_hidden()) { |
| 171 | suggested.push_back(colorIndex); |
| 172 | } |
| 173 | if (const auto light = data.vcolors()) { |
| 174 | auto &fields = (*colors)[colorIndex]; |
| 175 | fields.light = parseColors(*light); |
| 176 | if (const auto dark = data.vdark_colors()) { |
| 177 | fields.dark = parseColors(*dark); |
| 178 | } else { |
| 179 | fields.dark = fields.light; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 |
no test coverage detected