DEV: Add compatibility with the Glimmer Post Stream (#1230)

This commit is contained in:
Sérgio Saquetim
2025-04-29 23:55:54 -03:00
committed by GitHub
parent 09a6841480
commit ede65c971f
5 changed files with 250 additions and 211 deletions
@@ -0,0 +1,14 @@
import Component from "@glimmer/component";
import { isGPTBot } from "../../lib/ai-bot-helper";
export default class AiPersonaFlair extends Component {
static shouldRender(args) {
return isGPTBot(args.post.user);
}
<template>
<span class="persona-flair">
{{@outletArgs.post.topic.ai_persona_name}}
</span>
</template>
}
@@ -1,11 +1,29 @@
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { getOwnerWithFallback } from "discourse/lib/get-owner";
import Composer from "discourse/models/composer";
import { i18n } from "discourse-i18n";
import ShareFullTopicModal from "../components/modal/share-full-topic-modal";
const MAX_PERSONA_USER_ID = -1200;
let enabledChatBotIds;
export function isGPTBot(user) {
if (!user) {
return;
}
if (!enabledChatBotIds) {
const currentUser = getOwnerWithFallback(this).lookup(
"service:current-user"
);
enabledChatBotIds = currentUser.ai_enabled_chat_bots.map((bot) => bot.id);
}
return enabledChatBotIds.includes(user.id);
}
export function isPostFromAiBot(post, currentUser) {
return (
post.user_id <= MAX_PERSONA_USER_ID ||