summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/common/grouping/shelf-controllers/grouping-game-center-reengagement-shelf-controller.js
blob: f4b3d744d03e50f20885aba17554f48fb81b9f41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import * as validation from "@jet/environment/json/validation";
import * as models from "../../../api/models";
import * as actions from "../../../api/models/actions";
import * as serverData from "../../../foundation/json-parsing/server-data";
import * as mediaDataFetching from "../../../foundation/media/data-fetching";
import * as mediaNetwork from "../../../foundation/media/network";
import { ResponseMetadata } from "../../../foundation/network/network";
import { Parameters, Path, Protocol } from "../../../foundation/network/url-constants";
import * as urls from "../../../foundation/network/urls";
import * as color from "../../../foundation/util/color-util";
import * as content from "../../content/content";
import * as lockups from "../../lockups/lockups";
import * as metricsHelpersClicks from "../../metrics/helpers/clicks";
import * as metricsHelpersImpressions from "../../metrics/helpers/impressions";
import * as metricsHelpersLocation from "../../metrics/helpers/location";
import { GroupingShelfController } from "./grouping-shelf-controller";
import * as groupingShelfControllerCommon from "./grouping-shelf-controller-common";
import { injectCrossfireFlowForGameCenter } from "./grouping-game-center-popular-with-your-friends-shelf-controller";
export class GroupingGameCenterReengagementShelfController extends GroupingShelfController {
    // region Constructors
    constructor() {
        super("GroupingGameCenterReengagementShelfController");
        this.batchGroupKey = "gameCenter";
        this.supportedFeaturedContentIds = new Set([494 /* groupingTypes.FeaturedContentID.AppStore_GameCenterReengagement */]);
    }
    // endregion
    // region Shelf Builder
    shelfRoute(objectGraph) {
        return [
            ...super.shelfRoute(objectGraph),
            {
                protocol: Protocol.internal,
                path: `/${Path.grouping}/${Path.shelf}/{token}`,
                query: [Parameters.isGameCenterReengagementShelf],
            },
        ];
    }
    // endregion
    // region Shelf Creation Prerequisites
    /**
     * For a given mediaApiData extract the actual shelfContents array needed to render this shelf
     *
     * @param mediaApiData The outer shelfContents object containing the shelf contents
     */
    initialShelfDataFromGroupingMediaApiData(objectGraph, mediaApiData) {
        return {
            shelfContents: [],
            achievementData: null,
            achievementSummaryData: null,
        };
    }
    /**
     * For a given url that this controller handles, we should return a promise that will result in the `ShelfData`
     * needed to render this shelf
     *
     * @param objectGraph The App Store dependency graph
     * @param shelfUrl The url that this controller handled on a secondary fetch
     * @param parameters The extracted parameters from the shelf url
     */
    async secondaryShelfDataForShelfUrl(objectGraph, shelfUrl, shelfToken, parameters) {
        return await objectGraph.gameCenter.fetchRengagementDataForLocalPlayer().then(async (reengagementData) => {
            const adamID = serverData.asString(reengagementData, "adamId");
            const achievement = serverData.asJSONData(reengagementData["achievement"]);
            const achievementSummary = serverData.asJSONData(reengagementData["achievementSummary"]);
            if (serverData.isNullOrEmpty(adamID)) {
                // One of the few exceptions where TS minifiers cannot derive data container type
                // without some help, in this case using explicit type for the value passed to promise.
                const emptyShelfData = {
                    shelfContents: [],
                    responseTimingValues: null,
                    achievementData: null,
                    achievementSummaryData: null,
                };
                return await Promise.resolve(emptyShelfData);
            }
            const request = new mediaDataFetching.Request(objectGraph)
                .withIdOfType(adamID, "apps")
                .includingAgeRestrictions();
            groupingShelfControllerCommon.prepareGroupingShelfRequest(objectGraph, request);
            return await mediaNetwork
                .fetchData(objectGraph, request, {})
                .then((dataContainer) => {
                return {
                    shelfContents: dataContainer.data,
                    responseTimingValues: dataContainer[ResponseMetadata.timingValues],
                    achievementData: achievement,
                    achievementSummaryData: achievementSummary,
                };
            });
        });
    }
    /**
     * For a given mediaApiData create an updated shelf token that contains all the additional data for this specific shelf type
     *
     * @param objectGraph The App Store dependency graph
     * @param baseShelfToken The base grouping shelf token created by the grouping-controller
     * @param mediaApiData The outer data object containing the FC properties and data
     * @param groupingParseContext The parse context for the grouping page so far
     */
    shelfTokenFromBaseTokenAndMediaApiData(objectGraph, mediaApiData, baseShelfToken, groupingParseContext) {
        return baseShelfToken;
    }
    // endregion
    // region Shelf Creation
    /**
     *
     * @param objectGraph The App Store dependency graph
     * @param shelfToken The shelf shelfToken for this current shelf creation request
     * @param shelfData The media api shelfContents array for this shelf
     * @param groupingParseContext The parse context used to generate the grouping page on the initial page load,
     * this will be missing when this controller renders a secondary or incomplete shelf fetch.
     */
    _createShelf(objectGraph, shelfToken, shelfData, groupingParseContext) {
        if (shelfToken.isFirstRender) {
            return this.pendingGameCenterReengagementShelf(objectGraph, shelfData, shelfToken, groupingParseContext === null || groupingParseContext === void 0 ? void 0 : groupingParseContext.isArcadePage);
        }
        else {
            return this.gameCenterReengagementShelf(objectGraph, shelfData, shelfToken, groupingParseContext === null || groupingParseContext === void 0 ? void 0 : groupingParseContext.isArcadePage);
        }
    }
    pendingGameCenterReengagementShelf(objectGraph, shelfData, shelfToken, isArcadePage) {
        const shelf = this.gameCenterReengagementShelf(objectGraph, shelfData, shelfToken, isArcadePage);
        if (!shelf) {
            return null;
        }
        const groupingShelfUrl = urls.URL.from(groupingShelfControllerCommon.groupingShelfUrl(shelfToken));
        shelf.url = groupingShelfUrl.param(Parameters.isGameCenterReengagementShelf, "true").build();
        shelf.batchGroup = this.batchGroupKey;
        return shelf;
    }
    gameCenterReengagementShelf(objectGraph, shelfData, shelfToken, isArcadePage = false) {
        return validation.context("gameCenterReengagementShelf", () => {
            if (!serverData.isDefinedNonNullNonEmpty(shelfData.shelfContents)) {
                return null;
            }
            const shelf = new models.Shelf("gameCenterReengagement");
            shelf.isHorizontal = false;
            shelf.mergeWhenFetched = false; // Always replace
            shelf.batchGroup = this.batchGroupKey;
            const heroMetricsOptions = {
                id: shelfToken.id,
                kind: null,
                softwareType: isArcadePage ? "Arcade" : null,
                targetType: "achievements",
                title: "Achievements Hero",
                pageInformation: shelfToken.metricsPageInformation,
                locationTracker: shelfToken.metricsLocationTracker,
                idType: "its_contentId",
                fcKind: shelfToken.featuredContentId,
                badges: {
                    gameCenter: true,
                },
            };
            // Hero Background / Artwork
            const artwork = content.productEditorialVideoFromData(objectGraph, shelfData.shelfContents[0], 21 /* content.ArtworkUseCase.Uber */);
            let backgroundColor = color.named("componentBackground");
            let preview = null;
            if (serverData.isDefinedNonNullNonEmpty(artwork)) {
                preview = artwork.preview;
                backgroundColor = preview.backgroundColor;
            }
            // Build lockup used by reegnagement shelf
            const lockupListOptions = {
                lockupOptions: {
                    metricsOptions: {
                        pageInformation: shelfToken.metricsPageInformation,
                        locationTracker: shelfToken.metricsLocationTracker,
                    },
                    offerStyle: "white",
                    artworkUseCase: content.artworkUseCaseFromShelfStyle(objectGraph, "smallLockup"),
                    isSubtitleHidden: true,
                },
            };
            metricsHelpersLocation.pushContentLocation(objectGraph, heroMetricsOptions, heroMetricsOptions.title);
            const heroLockup = lockups.lockupsFromData(objectGraph, shelfData.shelfContents, lockupListOptions)[0];
            heroLockup.clickAction = injectCrossfireFlowForGameCenter(objectGraph, heroLockup.clickAction);
            metricsHelpersLocation.popLocation(shelfToken.metricsLocationTracker);
            // Click action used by hero view (achievement card)
            let heroAction = null;
            if (serverData.isDefinedNonNullNonEmpty(heroLockup)) {
                heroAction = new actions.GameCenterAchievementsAction(heroLockup.bundleId);
                heroAction.title = "Achievements Hero"; // `addClickEventToAction` uses `title` for `name` field currently.
                metricsHelpersClicks.addClickEventToAction(objectGraph, heroAction, heroMetricsOptions);
            }
            const shelfBadge = objectGraph.loc.string("GameCenter.Reengagement.Badge.GameCenter");
            const achievement = this.achievementFromData(objectGraph, shelfData.achievementData);
            const achievementCounts = this.achievementCountsFromData(objectGraph, shelfData.achievementSummaryData);
            const shelfMetadata = this.shelfMetadataForAchievement(objectGraph, achievement, achievementCounts);
            const heroItem = new models.GameCenterReengagement("gamecenter.fill", shelfBadge, shelfMetadata.title, shelfMetadata.subtitle, achievement, heroLockup, backgroundColor, preview, heroAction);
            shelf.items = [heroItem];
            /**
             * For reengagement, the shelf is a container fully fulled by `heroItem`.
             * Match what breakouts do by impressing `heroItem` directly instead of the `shelf`.
             */
            metricsHelpersImpressions.addImpressionFields(objectGraph, heroItem, heroMetricsOptions);
            return shelf;
        });
    }
    // region Helpers
    achievementStatusFromData(objectGraph, data) {
        const statusType = serverData.asString(data, "type");
        const status = new models.GameCenterAchievementStatus(statusType);
        status.percent = serverData.asNumber(data, "percent");
        status.date = serverData.asString(data, "date");
        status.artwork = new models.Artwork(serverData.asString(data, "artwork.template"), serverData.asNumber(data, "artwork.width"), serverData.asNumber(data, "artwork.height"), []);
        return status;
    }
    achievementFromData(objectGraph, data) {
        const id = serverData.asString(data, "id");
        const title = serverData.asString(data, "title");
        const subtitle = serverData.asString(data, "subtitle");
        const status = this.achievementStatusFromData(objectGraph, serverData.asDictionary(data, "status"));
        return new models.GameCenterAchievement(id, title, subtitle, status);
    }
    achievementCountsFromData(objectGraph, data) {
        const completedAchievements = serverData.asNumber(data, "completedAchievements");
        const totalAchievements = serverData.asNumber(data, "totalAchievements");
        return { completed: completedAchievements, total: totalAchievements };
    }
    shelfMetadataForAchievement(objectGraph, achievement, achievementCounts) {
        if (!serverData.isDefinedNonNull(achievement)) {
            return { title: "", subtitle: null };
        }
        if (achievementCounts.completed === 0) {
            return {
                title: objectGraph.loc.string("GameCenter.Reengagement.Achievement.First.Title"),
                subtitle: objectGraph.loc.string("GameCenter.Reengagement.Achievement.First.Subtitle"),
            };
        }
        switch (achievement.status.type) {
            case "locked":
            case "hidden":
            case "inprogress":
                return {
                    title: objectGraph.loc.string("GameCenter.Reengagement.Achievement.KeepPlaying.Title"),
                    subtitle: objectGraph.loc.string("GameCenter.Reengagement.Achievement.KeepPlaying.Subtitle"),
                };
            case "completed":
                const achievementsTotalCount = objectGraph.loc.stringWithCount("GameCenter.AchievementSummary.TotalToCompleteCount", achievementCounts.total);
                const achievementsCompletedCount = objectGraph.loc.stringWithCount("GameCenter.AchievementSummary.NumberCompletedCount", achievementCounts.completed);
                const subtitle = objectGraph.loc
                    .string("GameCenter.AchievementSummary.CompletedCount.Subtitle")
                    .replace("@@completedCount@@", achievementsCompletedCount)
                    .replace("@@totalCount@@", achievementsTotalCount);
                return {
                    title: objectGraph.loc.string("GameCenter.Reengagement.Achievement.CompletedCount.Title"),
                    subtitle: subtitle,
                };
            default:
                return { title: "", subtitle: null };
        }
    }
}
//# sourceMappingURL=grouping-game-center-reengagement-shelf-controller.js.map