in src/extension/services/tipsNotificationsService/tipsNotificationService.ts [291:361]
private async showRandomGeneralTipNotification(): Promise<GeneratedTipResponse> {
let generalTipsForRandom: Array<string>;
const generalTips: Tips = this.tipsConfig.tips.generalTips;
const generalTipsKeys: Array<string> = Object.keys(this.tipsConfig.tips.generalTips);
if (!this.tipsConfig.allTipsShownFirstly) {
generalTipsForRandom = generalTipsKeys.filter(
tipId => !generalTips[tipId].knownDate && !generalTips[tipId].shownDate,
);
if (generalTipsForRandom.length === 1) {
this.tipsConfig.allTipsShownFirstly = true;
}
} else {
generalTipsForRandom = generalTipsKeys.sort(
(tipId1, tipId2) =>
// According to ECMAScript standard: The exact moment of midnight at the beginning of
// 01 January, 1970 UTC is represented by the value +0.
(generalTips[tipId2].shownDate ?? new Date(+0)).getTime() -
(generalTips[tipId1].shownDate ?? new Date(+0)).getTime(),
);
}
let leftIndex: number;
switch (generalTipsForRandom.length) {
case 0:
return {
selection: undefined,
tipKey: "",
};
case 1:
leftIndex = 0;
break;
case 2:
leftIndex = 1;
break;
default:
leftIndex = 2;
}
const randIndex: number = getRandomIntInclusive(leftIndex, generalTipsForRandom.length - 1);
const selectedGeneralTipKey: string = generalTipsForRandom[randIndex];
const tipNotificationText = this.getGeneralTipNotificationTextByKey(selectedGeneralTipKey);
this.tipsConfig.tips.generalTips[selectedGeneralTipKey].shownDate = new Date();
this._tipsConfig = await this.mergeRemoteConfigToLocal(this.tipsConfig);
const daysBeforeNextTip: number = this.tipsConfig.allTipsShownFirstly
? getRandomIntInclusive(
this.tipsConfig.minDaysToRemind,
this.tipsConfig.maxDaysToRemind,
)
: getRandomIntInclusive(
this.tipsConfig.firstTimeMinDaysToRemind,
this.tipsConfig.firstTimeMaxDaysToRemind,
);
this.tipsConfig.daysLeftBeforeGeneralTip = daysBeforeNextTip;
ExtensionConfigManager.config.set(this.TIPS_CONFIG_NAME, this.tipsConfig);
this.sendShowTipNotificationTelemetry(selectedGeneralTipKey);
return {
selection: await vscode.window.showInformationMessage(
tipNotificationText,
...[this.getMoreInfoButtonText, this.doNotShowTipsAgainButtonText],
),
tipKey: selectedGeneralTipKey,
};
}