| 34 | } // namespace |
| 35 | |
| 36 | CloudTheme CloudTheme::Parse( |
| 37 | not_null<Main::Session*> session, |
| 38 | const MTPDtheme &data, |
| 39 | bool parseSettings) { |
| 40 | const auto document = data.vdocument(); |
| 41 | const auto paper = [&](const MTPThemeSettings &settings) { |
| 42 | const auto &data = settings.data(); |
| 43 | return data.vwallpaper() |
| 44 | ? WallPaper::Create(session, *data.vwallpaper()) |
| 45 | : std::nullopt; |
| 46 | }; |
| 47 | const auto outgoingMessagesColors = [&]( |
| 48 | const MTPThemeSettings &settings) { |
| 49 | auto result = std::vector<QColor>(); |
| 50 | const auto &data = settings.data(); |
| 51 | if (const auto colors = data.vmessage_colors()) { |
| 52 | for (const auto &color : colors->v) { |
| 53 | result.push_back(Ui::ColorFromSerialized(color)); |
| 54 | } |
| 55 | } |
| 56 | return result; |
| 57 | }; |
| 58 | const auto accentColor = [&](const MTPThemeSettings &settings) { |
| 59 | const auto &data = settings.data(); |
| 60 | return Ui::ColorFromSerialized(data.vaccent_color()); |
| 61 | }; |
| 62 | const auto outgoingAccentColor = [&](const MTPThemeSettings &settings) { |
| 63 | const auto &data = settings.data(); |
| 64 | return Ui::MaybeColorFromSerialized(data.voutbox_accent_color()); |
| 65 | }; |
| 66 | const auto basedOnDark = [&](const MTPThemeSettings &settings) { |
| 67 | const auto &data = settings.data(); |
| 68 | return data.vbase_theme().match([](const MTPDbaseThemeNight &) { |
| 69 | return true; |
| 70 | }, [](const MTPDbaseThemeTinted &) { |
| 71 | return true; |
| 72 | }, [](const auto &) { |
| 73 | return false; |
| 74 | }); |
| 75 | }; |
| 76 | const auto settings = [&] { |
| 77 | auto result = base::flat_map<Type, Settings>(); |
| 78 | const auto settings = data.vsettings(); |
| 79 | if (!settings) { |
| 80 | return result; |
| 81 | } |
| 82 | for (const auto &fields : settings->v) { |
| 83 | const auto type = basedOnDark(fields) ? Type::Dark : Type::Light; |
| 84 | result.emplace(type, Settings{ |
| 85 | .paper = paper(fields), |
| 86 | .accentColor = accentColor(fields), |
| 87 | .outgoingAccentColor = outgoingAccentColor(fields), |
| 88 | .outgoingMessagesColors = outgoingMessagesColors(fields), |
| 89 | }); |
| 90 | } |
| 91 | return result; |
| 92 | }; |
| 93 | return { |
nothing calls this directly
no test coverage detected