Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Simplify marketplace rating helpers https://github.com/siyuan-note/siyuan/issues/19082

Daniel68d4cf608c00
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index 9b58de2280..1049ccac77 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -35,26 +35,16 @@ import {
import {genBazaarPackagePanelHTML} from "./bazaar/html";
import {bindBazaarEvents} from "./bazaar/events";
import {
- applyPackageRating,
- applyPackageRatingResponse,
bindRatingUserChange,
- fetchPackageRating,
genCardRatingHTML,
genRatePackageActionHTML,
- genRatingDistributionHTML,
- genRatingStarsHTML,
genReadmeRatingHTML,
- getRatingItem,
getRatingKey,
- getRatingSummaryText,
loadDownloadedRatings,
loadDownloadedUserRatings,
loadReadmeRating,
loadUpdatedRatings,
- openRatingDialog,
- refreshRatingUI,
refreshVisibleRatingUI,
- submitPackageRating,
syncRatingUser,
} from "./bazaar/rating";
@@ -77,8 +67,8 @@ export const mountBazaarTab = (root: HTMLElement, keywords?: string, app?: App)
bazaar.bindEvent(app);
}
}
- if (bazaar._syncRatingUser()) {
- bazaar._refreshVisibleRatingUI();
+ if (syncRatingUser(bazaar)) {
+ refreshVisibleRatingUI(bazaar);
}
if (keywords) {
switchSettingPanelSubTab(root, keywords, [
@@ -375,11 +365,8 @@ export const bazaar = {
</div>` : ""}
</section>`;
},
- _getInvalidPackageTip(reason: IBazaarItem["invalidReason"]) {
- return window.siyuan.languages[getBazaarPackageInvalidLanguageKey(reason)];
- },
_genInvalidDownloadedCardHTML(item: IBazaarItem, bazaarType: TBazaarType) {
- const tip = bazaar._getInvalidPackageTip(item.invalidReason);
+ const tip = window.siyuan.languages[getBazaarPackageInvalidLanguageKey(item.invalidReason)];
return `<div data-name="${escapeAttr(item.name)}" data-package-type="${bazaarType}" data-package-source="downloaded" class="b3-card">
<div class="b3-card__img">${bazaar._genPackageIconHTML("")}</div>
<div class="fn__flex-1 fn__flex-column">
@@ -505,36 +492,6 @@ export const bazaar = {
${primaryAction ? '<div class="fn__hr"></div>' : ""}
<button class="b3-button b3-button--remove fn__block" data-type="uninstall">${window.siyuan.languages.uninstall}</button>`;
},
- _getRatingKey(bazaarType: TBazaarType, packageName: string) {
- return getRatingKey(bazaarType, packageName);
- },
- _syncRatingUser() {
- return syncRatingUser(this);
- },
- _refreshVisibleRatingUI() {
- return refreshVisibleRatingUI(this);
- },
- _bindRatingUserChange() {
- return bindRatingUserChange(this);
- },
- _getRatingSummaryText(rating?: IBazaarRating) {
- return getRatingSummaryText(rating);
- },
- _genRatingStarsHTML(value: number) {
- return genRatingStarsHTML(value);
- },
- _genCardRatingHTML(item: Pick<IBazaarItem, "rating">, loaded = true) {
- return genCardRatingHTML(this, item, loaded);
- },
- _genRatePackageActionHTML(loaded: boolean, rating?: unknown) {
- return genRatePackageActionHTML(loaded, rating);
- },
- _genRatingDistributionHTML(rating?: IBazaarRating) {
- return genRatingDistributionHTML(rating);
- },
- _genReadmeRatingHTML(bazaarType: TBazaarType, item: IBazaarItem, loaded: boolean) {
- return genReadmeRatingHTML(this, bazaarType, item, loaded);
- },
_genCardHTML(item: IBazaarItem, bazaarType: TBazaarType) {
const showSwitch = item.installed && !item.current && ["icons", "themes"].includes(bazaarType);
const showDisable = item.installed && item.current && ["icons", "themes"].includes(bazaarType);
@@ -555,7 +512,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
<span class="fn__space--small"></span>
${formatCount(item.downloads)}
</span>
- ${bazaar._genCardRatingHTML(item,
+ ${genCardRatingHTML(item,
isBazaarPackageRatingLoaded("bazaar", false, item.ratingAvailable))}
<span class="block__icon block__icon--show block__icon--text">
<svg><use xlink:href="#iconAccount"></use></svg>
@@ -622,7 +579,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
_genUpdateItemHTML(item: IUpdatedBazaarItem, bazaarType: TBazaarType) {
const installed = item.installed;
const available = item.available;
- const ratingKey = bazaar._getRatingKey(bazaarType, installed.name);
+ const ratingKey = getRatingKey(bazaarType, installed.name);
const ratingLoaded = isBazaarPackageRatingLoaded("updated", bazaar._data.downloadedRatingKeys.has(ratingKey));
return `<div class="b3-card" data-name="${escapeAttr(installed.name)}" data-package-type="${bazaarType}" data-package-source="updated">
<div class="b3-card__img">${bazaar._genPackageIconHTML(installed.iconURL)}</div>
@@ -640,7 +597,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
<svg><use xlink:href="#iconFolder"></use></svg>
</span>
${bazaar._genUpdateButtonHTML(available, bazaarType)}
- ${bazaar._genRatePackageActionHTML(ratingLoaded, bazaar._data.userRatings.get(ratingKey))}
+ ${genRatePackageActionHTML(ratingLoaded, bazaar._data.userRatings.get(ratingKey))}
</div>
</div>`;
},
@@ -728,7 +685,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
installAllElement?.classList.toggle("fn__none",
!items.some(({item}) => !item.available.disallowUpdate));
contentElement.innerHTML = items.map(({type, item}) => this._genUpdateItemHTML(item, type)).join("");
- this._loadUpdatedRatings();
+ loadUpdatedRatings(this);
},
_syncDownloadedUpdateButtons() {
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card[data-package-source='downloaded']").forEach((card) => {
@@ -857,7 +814,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
<span class="fn__flex-center ft__on-surface">${window.siyuan.languages.publishService}</span>
</label>` : "";
const available = bazaar._getUpdatedItem(bazaarType, bazaarItem.name)?.available;
- const ratingKey = bazaar._getRatingKey(bazaarType, bazaarItem.name);
+ const ratingKey = getRatingKey(bazaarType, bazaarItem.name);
return `<div data-name="${escapeAttr(bazaarItem.name)}" data-package-type="${bazaarType}" data-package-source="downloaded" class="b3-card${bazaarItem.current ? " b3-card--current" : ""}">
<div class="b3-card__img">${bazaar._genPackageIconHTML(bazaarItem.iconURL)}</div>
<div class="fn__flex-1 fn__flex-column">
@@ -870,7 +827,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}
<div class="b3-card__actions b3-card__actions--right">
${isMobile() ? publishSwitchHTML : ""}
${bazaar._genUpdateButtonHTML(available, bazaarType, true)}
- ${bazaar._genRatePackageActionHTML(bazaar._data.downloadedRatingKeys.has(ratingKey), bazaar._data.userRatings.get(ratingKey))}
+ ${genRatePackageActionHTML(bazaar._data.downloadedRatingKeys.has(ratingKey), bazaar._data.userRatings.get(ratingKey))}
${bazaar._genIncompatibleChipHTML(bazaarItem, "installed", bazaarType)}
${bazaar._genDeprecatedChipHTML(bazaarItem, false)}
${bazaar._genFundingHTML(bazaarItem.preferredFunding, false)}
@@ -910,8 +867,8 @@ type="checkbox">
bazaar._downloadedPluginsReady = true;
bazaar._syncPluginGlobalSwitch();
}
- bazaar._loadDownloadedRatings(bazaarType, packageItems);
- bazaar._loadDownloadedUserRatings(bazaarType, packageItems);
+ loadDownloadedRatings(bazaar, bazaarType, packageItems);
+ loadDownloadedUserRatings(bazaar, bazaarType, packageItems);
bazaar._loadDownloadedDeprecations(bazaarType, app);
const sideElement = bazaar.element.querySelector("#configBazaarReadme.config__view--show .item__side");
// 仅刷新「已下载」详情,避免通过 URI 打开的在线详情被本地数据覆盖
@@ -992,7 +949,7 @@ type="checkbox">
const available = detail?.available || updatedDetail?.available ||
(from === "downloaded" ? bazaar._getUpdatedItem(bazaarType, data.name)?.available : data);
const displayData = from === "downloaded" ? installed || data : available || data;
- const ratingKey = bazaar._getRatingKey(bazaarType, displayData.name);
+ const ratingKey = getRatingKey(bazaarType, displayData.name);
const ratingLoaded = isBazaarPackageRatingLoaded(from, bazaar._data.downloadedRatingKeys.has(ratingKey),
displayData.ratingAvailable);
if (from !== "bazaar" && ratingLoaded) {
@@ -1090,7 +1047,7 @@ type="checkbox">
${installSection}
${marketSection}
${compatibilitySection}
- <div data-type="rating-detail-slot">${bazaar._genReadmeRatingHTML(bazaarType, displayData, ratingLoaded)}</div>
+ <div data-type="rating-detail-slot">${genReadmeRatingHTML(bazaar, bazaarType, displayData, ratingLoaded)}</div>
<section class="item__meta-section item__resources">
<div class="item__meta-title">${window.siyuan.languages.bazaarResources}</div>
<div class="fn__flex">
@@ -1168,7 +1125,7 @@ type="checkbox">
});
}
readmeElement.classList.add("config__view--show");
- bazaar._loadReadmeRating(bazaarType, displayData.name, from);
+ loadReadmeRating(bazaar, bazaarType, displayData.name, from);
if (needsPackageDetail) {
bazaar._fetchPackageDetail(bazaarType, data.name, (packageDetail) => {
if (!readmeElement.classList.contains("config__view--show")) {
@@ -1287,42 +1244,6 @@ type="checkbox">
contentElement.append(fragment);
bazaar._data.downloaded = packages;
},
- _applyPackageRating(bazaarType: TBazaarType, packageName: string, rating?: IBazaarRating, refreshUI = true) {
- return applyPackageRating(this, bazaarType, packageName, rating, refreshUI);
- },
- _applyPackageRatingResponse(bazaarType: TBazaarType, packageName: string, data: {
- ratingAvailable?: unknown;
- rating?: Partial<IBazaarRating> | null;
- }, refreshUI = true) {
- return applyPackageRatingResponse(this, bazaarType, packageName, data, refreshUI);
- },
- _getRatingItem(bazaarType: TBazaarType, packageName: string, from: "downloaded" | "updated" | "bazaar") {
- return getRatingItem(this, bazaarType, packageName, from);
- },
- _refreshRatingUI(bazaarType: TBazaarType, packageName: string) {
- return refreshRatingUI(this, bazaarType, packageName);
- },
- _loadDownloadedRatings(bazaarType: TBazaarType, packages: IBazaarItem[]) {
- return loadDownloadedRatings(this, bazaarType, packages);
- },
- _loadDownloadedUserRatings(bazaarType: TBazaarType, packages: IBazaarItem[]) {
- return loadDownloadedUserRatings(this, bazaarType, packages);
- },
- _loadUpdatedRatings() {
- return loadUpdatedRatings(this);
- },
- _fetchPackageRating(bazaarType: TBazaarType, packageName: string, callback?: () => void, silent = true) {
- return fetchPackageRating(this, bazaarType, packageName, callback, silent);
- },
- _loadReadmeRating(bazaarType: TBazaarType, packageName: string, from: "downloaded" | "updated" | "bazaar") {
- return loadReadmeRating(this, bazaarType, packageName, from);
- },
- _submitPackageRating(bazaarType: TBazaarType, packageName: string, rating: number, callback: (success: boolean) => void) {
- return submitPackageRating(this, bazaarType, packageName, rating, callback);
- },
- _openRatingDialog(bazaarType: TBazaarType, packageName: string) {
- return openRatingDialog(this, bazaarType, packageName);
- },
_refreshReadmeDetail(bazaarType: TBazaarType, packageName: string) {
const sideElement = bazaar.element.querySelector("#configBazaarReadme.config__view--show .item__side");
if (sideElement?.getAttribute("data-package-type") !== bazaarType ||
@@ -1705,8 +1626,8 @@ type="checkbox">
this._updateState = "idle";
this._updateRequestID++;
this._data.details.clear();
- this._syncRatingUser();
- this._bindRatingUserChange();
+ syncRatingUser(this);
+ bindRatingUserChange(this);
const mount = this._captureMount();
BAZAAR_PACKAGE_TYPES.forEach((type) => {
this._data.update[type] = [];
diff --git a/app/src/config/bazaar/events.ts b/app/src/config/bazaar/events.ts
index a3cf5d1288..a8a8e4e544 100644
--- a/app/src/config/bazaar/events.ts
+++ b/app/src/config/bazaar/events.ts
@@ -21,6 +21,7 @@ import {
getBazaarTypeByTab,
isBazaarPackageType,
} from "./packageConfig";
+import {openRatingDialog, refreshVisibleRatingUI, syncRatingUser} from "./rating";
type TBazaarController = typeof import("../bazaar").bazaar;
type TBazaarPackageSource = "downloaded" | "updated" | "bazaar";
@@ -89,7 +90,7 @@ const ACTION_HANDLERS = {
if (!pkgType || !packageName || !isBazaarPackageRatingEditable(packageSource, packageInstalled)) {
return CONTINUE;
}
- controller._openRatingDialog(pkgType, packageName);
+ openRatingDialog(controller, pkgType, packageName);
return HANDLED;
}) satisfies TBazaarActionHandler,
"copy-funding": ((context, target) => {
@@ -480,8 +481,8 @@ const bindBazaarClickEvent = (
mount: IBazaarMountSnapshot,
) => {
controller.element.firstElementChild.addEventListener("click", (event: MouseEvent) => {
- if (controller._syncRatingUser()) {
- controller._refreshVisibleRatingUI();
+ if (syncRatingUser(controller)) {
+ refreshVisibleRatingUI(controller);
}
const eventTarget = event.target as HTMLElement;
const context = resolveClickContext(controller, app, mount, eventTarget);
diff --git a/app/src/config/bazaar/rating.ts b/app/src/config/bazaar/rating.ts
index 48aa5a02ac..0d522f3cd2 100644
--- a/app/src/config/bazaar/rating.ts
+++ b/app/src/config/bazaar/rating.ts
@@ -49,25 +49,25 @@ export const refreshVisibleRatingUI = (controller: TBazaarController) => {
const bazaarType = element.dataset.packageType;
const packageName = element.dataset.name;
if (isBazaarPackageType(bazaarType) && packageName) {
- keys.add(controller._getRatingKey(bazaarType, packageName));
+ keys.add(getRatingKey(bazaarType, packageName));
}
});
keys.forEach((key) => {
const separator = key.indexOf(":");
- controller._refreshRatingUI(key.slice(0, separator) as TBazaarType, key.slice(separator + 1));
+ refreshRatingUI(controller, key.slice(0, separator) as TBazaarType, key.slice(separator + 1));
});
const sideElement = controller.element?.querySelector("#configBazaarReadme.config__view--show .item__side");
const bazaarType = sideElement?.getAttribute("data-package-type") as TBazaarType;
const packageName = sideElement?.getAttribute("data-name");
const from = sideElement?.getAttribute("data-from") as "downloaded" | "updated" | "bazaar";
if (bazaarType && packageName && from) {
- controller._loadReadmeRating(bazaarType, packageName, from);
+ loadReadmeRating(controller, bazaarType, packageName, from);
}
if (window.siyuan.user) {
if (controller._isUpdatePanelActive()) {
- controller._loadUpdatedRatings();
+ loadUpdatedRatings(controller);
} else if (controller._data.downloadedType) {
- controller._loadDownloadedUserRatings(controller._data.downloadedType, controller._data.downloadedDefault);
+ loadDownloadedUserRatings(controller, controller._data.downloadedType, controller._data.downloadedDefault);
}
}
};
@@ -81,8 +81,8 @@ export const bindRatingUserChange = (controller: TBazaarController) => {
if (!controller._isMountCurrent(mount)) {
return;
}
- controller._syncRatingUser();
- controller._refreshVisibleRatingUI();
+ syncRatingUser(controller);
+ refreshVisibleRatingUI(controller);
};
window.addEventListener("siyuan-login-success", controller._ratingUserChangeHandler);
};
@@ -110,10 +110,10 @@ ${inactiveStars}
</span>`;
};
-export const genCardRatingHTML = (controller: TBazaarController, item: Pick<IBazaarItem, "rating">, loaded = true) => {
+export const genCardRatingHTML = (item: Pick<IBazaarItem, "rating">, loaded = true) => {
const rating = getDisplayableBazaarRating(item.rating);
const hidden = !loaded || !rating;
- const summary = controller._getRatingSummaryText(rating);
+ const summary = getRatingSummaryText(rating);
const average = rating?.average.toLocaleString(undefined, {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
@@ -162,16 +162,16 @@ export const genReadmeRatingHTML = (controller: TBazaarController, bazaarType: T
if (!loaded) {
return "";
}
- controller._syncRatingUser();
+ syncRatingUser(controller);
const rating = getDisplayableBazaarRating(item.rating);
- const userRating = controller._data.userRatings.get(controller._getRatingKey(bazaarType, item.name)) || 0;
+ const userRating = controller._data.userRatings.get(getRatingKey(bazaarType, item.name)) || 0;
let action = "";
if (item.installed) {
if (window.siyuan.user) {
const actionText = userRating ? window.siyuan.languages.bazaarYourRatingValue.replace("${rating}", userRating.toString()) :
window.siyuan.languages.bazaarRatePackage;
action = `<button type="button" class="config-bazaar__rating-action" data-type="rate-package" aria-label="${escapeAttr(actionText)}">
-${controller._genRatingStarsHTML(userRating)}
+${genRatingStarsHTML(userRating)}
<span>${escapeHtml(actionText)}</span>
</button>`;
} else {
@@ -180,12 +180,12 @@ ${controller._genRatingStarsHTML(userRating)}
} else {
action = `<div class="config-bazaar__rating-tip">${window.siyuan.languages.bazaarRatingInstallTip}</div>`;
}
- const summary = rating ? controller._getRatingSummaryText(rating) : "";
+ const summary = rating ? getRatingSummaryText(rating) : "";
const aggregate = rating ? `<div class="config-bazaar__rating-summary" aria-label="${escapeAttr(summary)}">
- ${controller._genRatingStarsHTML(rating.average)}
+ ${genRatingStarsHTML(rating.average)}
<span>${escapeHtml(summary)}</span>
</div>
-<div class="config-bazaar__rating-distribution">${controller._genRatingDistributionHTML(rating)}</div>` : "";
+<div class="config-bazaar__rating-distribution">${genRatingDistributionHTML(rating)}</div>` : "";
return `<section class="item__meta-section config-bazaar__rating-detail">
<div class="item__meta-title">${window.siyuan.languages.bazaarRating}</div>
${aggregate}
@@ -194,7 +194,7 @@ ${action}
};
export const applyPackageRating = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string, rating?: IBazaarRating, refreshUI = true) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
if (rating) {
controller._data.ratings.set(key, rating);
} else {
@@ -216,7 +216,7 @@ export const applyPackageRating = (controller: TBazaarController, bazaarType: TB
updateItem(detail?.installed);
updateItem(detail?.available);
if (refreshUI) {
- controller._refreshRatingUI(bazaarType, packageName);
+ refreshRatingUI(controller, bazaarType, packageName);
}
};
@@ -224,15 +224,15 @@ export const applyPackageRatingResponse = (controller: TBazaarController, bazaar
ratingAvailable?: unknown;
rating?: Partial<IBazaarRating> | null;
}, refreshUI = true) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const publicRating = normalizeBazaarPackageRatingResponse(data);
if (publicRating.loaded) {
controller._data.downloadedRatingKeys.add(key);
- controller._applyPackageRating(bazaarType, packageName, publicRating.rating, refreshUI);
+ applyPackageRating(controller, bazaarType, packageName, publicRating.rating, refreshUI);
} else {
controller._data.downloadedRatingKeys.delete(key);
if (refreshUI) {
- controller._refreshRatingUI(bazaarType, packageName);
+ refreshRatingUI(controller, bazaarType, packageName);
}
}
return publicRating.loaded;
@@ -251,23 +251,23 @@ export const getRatingItem = (controller: TBazaarController, bazaarType: TBazaar
};
export const refreshRatingUI = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string) => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
controller.element?.querySelectorAll(`.b3-card[data-package-type="${bazaarType}"]`).forEach((card) => {
if (card.getAttribute("data-name") !== packageName) {
return;
}
const source = card.getAttribute("data-package-source") as "downloaded" | "updated" | "bazaar";
- const item = controller._getRatingItem(bazaarType, packageName, source);
+ const item = getRatingItem(controller, bazaarType, packageName, source);
const slot = card.querySelector<HTMLElement>("[data-rating-card-slot]");
if (item && slot) {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const loaded = isBazaarPackageRatingLoaded(source, controller._data.downloadedRatingKeys.has(key),
item.ratingAvailable);
if (source === "bazaar") {
const rating = loaded ? getDisplayableBazaarRating(item.rating) : undefined;
slot.classList.toggle("fn__none", !rating);
if (rating) {
- slot.setAttribute("aria-label", controller._getRatingSummaryText(rating));
+ slot.setAttribute("aria-label", getRatingSummaryText(rating));
const averageElement = slot.lastElementChild;
if (averageElement) {
averageElement.textContent = rating.average.toLocaleString(undefined, {
@@ -297,14 +297,14 @@ export const refreshRatingUI = (controller: TBazaarController, bazaarType: TBaza
return;
}
const from = sideElement.getAttribute("data-from") as "downloaded" | "updated" | "bazaar";
- const item = controller._getRatingItem(bazaarType, packageName, from);
+ const item = getRatingItem(controller, bazaarType, packageName, from);
const slot = sideElement.querySelector('[data-type="rating-detail-slot"]');
if (item && slot) {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const loaded = isBazaarPackageRatingLoaded(from, controller._data.downloadedRatingKeys.has(key),
item.ratingAvailable);
const displayItem = from === "bazaar" ? item : {...item, rating: controller._data.ratings.get(key)};
- slot.innerHTML = controller._genReadmeRatingHTML(bazaarType, displayItem, loaded);
+ slot.innerHTML = genReadmeRatingHTML(controller, bazaarType, displayItem, loaded);
}
};
@@ -316,7 +316,7 @@ export const loadDownloadedRatings = (controller: TBazaarController, bazaarType:
const requestID = (controller._data.ratingBatchRequestIDs.get(bazaarType) || 0) + 1;
controller._data.ratingBatchRequestIDs.set(bazaarType, requestID);
const mutationVersions = new Map(packageNames.map((packageName) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
return [packageName, getBazaarRatingMutationVersion(controller._data.ratingMutationVersions, key)];
}));
const mount = controller._captureMount();
@@ -333,24 +333,24 @@ export const loadDownloadedRatings = (controller: TBazaarController, bazaarType:
return;
}
ratings.forEach((ratingResponse, packageName) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
if (isBazaarRatingMutationVersionCurrent(controller._data.ratingMutationVersions, key,
mutationVersions.get(packageName) || 0)) {
- controller._applyPackageRatingResponse(bazaarType, packageName, ratingResponse);
+ applyPackageRatingResponse(controller, bazaarType, packageName, ratingResponse);
}
});
});
};
export const loadDownloadedUserRatings = (controller: TBazaarController, bazaarType: TBazaarType, packages: IBazaarItem[]) => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (!window.siyuan.user) {
return;
}
const requestedUserID = controller._ratingUserID;
const packageNames = Array.from(new Set(packages.filter((item) => !item.invalidReason).map((item) => item.name)))
.filter((packageName) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
return !controller._data.userRatingKeys.has(key) &&
!controller._data.userRatingLoadingKeys.has(`${requestedUserID}|${key}`);
});
@@ -361,12 +361,12 @@ export const loadDownloadedUserRatings = (controller: TBazaarController, bazaarT
const requestID = (controller._data.userRatingBatchRequestIDs.get(requestKey) || 0) + 1;
controller._data.userRatingBatchRequestIDs.set(requestKey, requestID);
const loadingKeys = packageNames.map((packageName) => {
- const loadingKey = `${requestedUserID}|${controller._getRatingKey(bazaarType, packageName)}`;
+ const loadingKey = `${requestedUserID}|${getRatingKey(bazaarType, packageName)}`;
controller._data.userRatingLoadingKeys.add(loadingKey);
return loadingKey;
});
const mutationVersions = new Map(packageNames.map((packageName) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
return [packageName, getBazaarRatingMutationVersion(controller._data.ratingMutationVersions, key)];
}));
const mount = controller._captureMount();
@@ -374,7 +374,7 @@ export const loadDownloadedUserRatings = (controller: TBazaarController, bazaarT
packageType: bazaarType,
packageNames,
}, response => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (response.code !== 0 || requestedUserID !== controller._ratingUserID ||
controller._data.userRatingBatchRequestIDs.get(requestKey) !== requestID ||
!controller._isMountCurrent(mount) || !controller.element?.isConnected) {
@@ -385,12 +385,12 @@ export const loadDownloadedUserRatings = (controller: TBazaarController, bazaarT
return;
}
userRatings.forEach((userRating, packageName) => {
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
if (isBazaarRatingMutationVersionCurrent(controller._data.ratingMutationVersions, key,
mutationVersions.get(packageName) || 0)) {
controller._data.userRatings.set(key, userRating);
controller._data.userRatingKeys.add(key);
- controller._refreshRatingUI(bazaarType, packageName);
+ refreshRatingUI(controller, bazaarType, packageName);
}
});
}).finally(() => {
@@ -406,19 +406,19 @@ export const loadUpdatedRatings = (controller: TBazaarController) => {
const items = controller._data.update[bazaarType];
const installed = items.map((item) => item.installed);
if (items.length && !items.every((item) => controller._data.downloadedRatingKeys.has(
- controller._getRatingKey(bazaarType, item.installed.name)))) {
- controller._loadDownloadedRatings(bazaarType, installed);
+ getRatingKey(bazaarType, item.installed.name)))) {
+ loadDownloadedRatings(controller, bazaarType, installed);
}
if (items.length && window.siyuan.user) {
- controller._loadDownloadedUserRatings(bazaarType, installed);
+ loadDownloadedUserRatings(controller, bazaarType, installed);
}
});
};
export const fetchPackageRating = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string, callback?: () => void, silent = true) => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
const requestedUserID = controller._ratingUserID;
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const loadingKey = `${requestedUserID}|${key}`;
controller._data.userRatingLoadingKeys.add(loadingKey);
const mount = controller._captureMount();
@@ -428,7 +428,7 @@ export const fetchPackageRating = (controller: TBazaarController, bazaarType: TB
packageName,
}, response => {
handled = true;
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (requestedUserID !== controller._ratingUserID || !controller._isMountCurrent(mount)) {
return;
}
@@ -443,7 +443,7 @@ export const fetchPackageRating = (controller: TBazaarController, bazaarType: TB
const userRating = response.data.userRating;
controller._data.userRatings.set(key, normalizeBazaarUserRating(userRating) || 0);
controller._data.userRatingKeys.add(key);
- if (!controller._applyPackageRatingResponse(bazaarType, packageName, response.data)) {
+ if (!applyPackageRatingResponse(controller, bazaarType, packageName, response.data)) {
if (!silent) {
showMessage(window.siyuan.languages.bazaarRatingFailed);
}
@@ -459,18 +459,18 @@ export const fetchPackageRating = (controller: TBazaarController, bazaarType: TB
};
export const loadReadmeRating = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string, from: "downloaded" | "updated" | "bazaar") => {
- controller._syncRatingUser();
- const key = controller._getRatingKey(bazaarType, packageName);
+ syncRatingUser(controller);
+ const key = getRatingKey(bazaarType, packageName);
const loadingKey = `${controller._ratingUserID}|${key}`;
- if (controller._getRatingItem(bazaarType, packageName, from)?.installed && window.siyuan.user &&
+ if (getRatingItem(controller, bazaarType, packageName, from)?.installed && window.siyuan.user &&
!controller._data.userRatingKeys.has(key) &&
!controller._data.userRatingLoadingKeys.has(loadingKey)) {
- controller._fetchPackageRating(bazaarType, packageName);
+ fetchPackageRating(controller, bazaarType, packageName);
}
};
export const submitPackageRating = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string, rating: number, callback: (success: boolean) => void) => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
const mount = controller._captureMount();
const removing = rating === 0;
const failureMessage = removing ? window.siyuan.languages.bazaarRemoveRatingFailed :
@@ -481,7 +481,7 @@ export const submitPackageRating = (controller: TBazaarController, bazaarType: T
return;
}
const requestedUserID = controller._ratingUserID;
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const requestKey = `${requestedUserID}|${key}`;
if (!beginBazaarRatingSubmission(controller._data.userRatingSubmittingKeys, requestKey)) {
showMessage(window.siyuan.languages.loading);
@@ -505,7 +505,7 @@ export const submitPackageRating = (controller: TBazaarController, bazaarType: T
rating,
}, response => {
handled = true;
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (!isLatestRequest()) {
settle(false);
return;
@@ -522,7 +522,7 @@ export const submitPackageRating = (controller: TBazaarController, bazaarType: T
controller._data.userRatingKeys.add(key);
beginBazaarRatingRequest(controller._data.ratingMutationVersions, key);
const refreshUI = controller._isMountCurrent(mount);
- controller._applyPackageRatingResponse(bazaarType, packageName, response.data, refreshUI);
+ applyPackageRatingResponse(controller, bazaarType, packageName, response.data, refreshUI);
const sortValue = window.siyuan.storage[Constants.LOCAL_BAZAAR][BAZAAR_PACKAGE_CONFIG[bazaarType].tabType];
if (refreshUI && ["4", "5"].includes(sortValue)) {
controller._renderBazaarCards(
@@ -540,7 +540,7 @@ export const submitPackageRating = (controller: TBazaarController, bazaarType: T
if (settled) {
return;
}
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (!handled && isLatestRequest()) {
showMessage(failureMessage);
}
@@ -549,12 +549,12 @@ export const submitPackageRating = (controller: TBazaarController, bazaarType: T
};
export const openRatingDialog = (controller: TBazaarController, bazaarType: TBazaarType, packageName: string) => {
- controller._syncRatingUser();
+ syncRatingUser(controller);
if (!window.siyuan.user) {
showMessage(window.siyuan.languages.bazaarRatingLoginTip);
return;
}
- const key = controller._getRatingKey(bazaarType, packageName);
+ const key = getRatingKey(bazaarType, packageName);
const submitKey = `${controller._ratingUserID}|${key}`;
if (controller._data.userRatingSubmittingKeys.has(submitKey)) {
showMessage(window.siyuan.languages.loading);
@@ -566,8 +566,8 @@ export const openRatingDialog = (controller: TBazaarController, bazaarType: TBaz
showMessage(window.siyuan.languages.loading);
return;
}
- controller._fetchPackageRating(bazaarType, packageName, () => {
- controller._openRatingDialog(bazaarType, packageName);
+ fetchPackageRating(controller, bazaarType, packageName, () => {
+ openRatingDialog(controller, bazaarType, packageName);
}, false);
return;
}
@@ -676,7 +676,7 @@ ${canRemoveRating ? `<button type="button" class="b3-button b3-button--remove" d
return;
}
setSubmitting(true);
- controller._submitPackageRating(bazaarType, packageName, 0, (success) => {
+ submitPackageRating(controller, bazaarType, packageName, 0, (success) => {
if (success) {
dialog.destroy();
} else {
@@ -689,7 +689,7 @@ ${canRemoveRating ? `<button type="button" class="b3-button b3-button--remove" d
return;
}
setSubmitting(true);
- controller._submitPackageRating(bazaarType, packageName, selectedRating, (success) => {
+ submitPackageRating(controller, bazaarType, packageName, selectedRating, (success) => {
if (success) {
dialog.destroy();
} else {