2023-10-23 10:41:36 -04:00
|
|
|
export function showComposerAIHelper(outletArgs, helper) {
|
|
|
|
const enableHelper = _helperEnabled(helper.siteSettings);
|
|
|
|
const enableAssistant = _canUseAssistant(
|
|
|
|
helper.currentUser,
|
|
|
|
_findAllowedGroups(helper.siteSettings.ai_helper_allowed_groups)
|
2023-09-13 17:18:48 -04:00
|
|
|
);
|
|
|
|
const canShowInPM = helper.siteSettings.ai_helper_allowed_in_pm;
|
|
|
|
|
|
|
|
if (outletArgs?.composer?.privateMessage) {
|
2023-10-23 10:41:36 -04:00
|
|
|
return enableHelper && enableAssistant && canShowInPM;
|
2023-09-13 17:18:48 -04:00
|
|
|
}
|
|
|
|
|
2023-10-23 10:41:36 -04:00
|
|
|
return enableHelper && enableAssistant;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function showPostAIHelper(outletArgs, helper) {
|
|
|
|
return (
|
|
|
|
_helperEnabled(helper.siteSettings) &&
|
|
|
|
_canUseAssistant(
|
|
|
|
helper.currentUser,
|
|
|
|
_findAllowedGroups(helper.siteSettings.post_ai_helper_allowed_groups)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _helperEnabled(siteSettings) {
|
|
|
|
return (
|
|
|
|
siteSettings.discourse_ai_enabled && siteSettings.composer_ai_helper_enabled
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _findAllowedGroups(setting) {
|
|
|
|
return setting.split("|").map((id) => parseInt(id, 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
function _canUseAssistant(user, allowedGroups) {
|
|
|
|
return user?.groups.some((g) => allowedGroups.includes(g.id));
|
2023-09-13 17:18:48 -04:00
|
|
|
}
|