From 850025815fcfeff0b310ea1ceaffe0e444631aae Mon Sep 17 00:00:00 2001 From: Daniel Avila Date: Fri, 24 Mar 2023 18:26:59 -0400 Subject: [PATCH 1/3] fix: correctly searches bing messages --- api/lib/utils/misc.js | 2 +- api/lib/utils/reduceHits.js | 12 +++++++----- api/models/Conversation.js | 3 +-- api/server/routes/search.js | 7 +++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api/lib/utils/misc.js b/api/lib/utils/misc.js index 3d971751fc3..91982947f5e 100644 --- a/api/lib/utils/misc.js +++ b/api/lib/utils/misc.js @@ -1,6 +1,6 @@ const cleanUpPrimaryKeyValue = (value) => { // For Bing convoId handling - return value.replace(/--/g, '-'); + return value.replace(/--/g, '|'); }; function replaceSup(text) { diff --git a/api/lib/utils/reduceHits.js b/api/lib/utils/reduceHits.js index 8c93f724041..63ca0491ff7 100644 --- a/api/lib/utils/reduceHits.js +++ b/api/lib/utils/reduceHits.js @@ -1,4 +1,5 @@ const mergeSort = require('./mergeSort'); +const { cleanUpPrimaryKeyValue } = require('./misc'); function reduceMessages(hits) { const counts = {}; @@ -29,15 +30,16 @@ function reduceHits(hits, titles = []) { const convos = [...hits, ...titles]; for (const convo of convos) { - if (!counts[convo.conversationId]) { - counts[convo.conversationId] = 1; + const currentId = cleanUpPrimaryKeyValue(convo.conversationId); + if (!counts[currentId]) { + counts[currentId] = 1; } else { - counts[convo.conversationId]++; + counts[currentId]++; } if (convo.title) { - // titleMap[convo.conversationId] = convo._formatted.title; - titleMap[convo.conversationId] = convo.title; + // titleMap[currentId] = convo._formatted.title; + titleMap[currentId] = convo.title; } } diff --git a/api/models/Conversation.js b/api/models/Conversation.js index 732005b9682..b5716add017 100644 --- a/api/models/Conversation.js +++ b/api/models/Conversation.js @@ -1,6 +1,5 @@ // const { Conversation } = require('./plugins'); const Conversation = require('./schema/convoSchema'); -const { cleanUpPrimaryKeyValue } = require('../lib/utils/misc'); const { getMessages, deleteMessages } = require('./Message'); const getConvo = async (user, conversationId) => { @@ -90,7 +89,7 @@ module.exports = { promises.push( Conversation.findOne({ user, - conversationId: cleanUpPrimaryKeyValue(convo.conversationId) + conversationId: convo.conversationId, }).exec() ) ); diff --git a/api/server/routes/search.js b/api/server/routes/search.js index 5583efeabca..076e4093c9a 100644 --- a/api/server/routes/search.js +++ b/api/server/routes/search.js @@ -15,7 +15,8 @@ router.get('/sync', async function (req, res) { router.get('/', async function (req, res) { try { - const user = req?.session?.user?.username; + let user = req?.session?.user?.username; + user = user ?? null; const { q } = req.query; const pageNumber = req.query.pageNumber || 1; const key = `${user || ''}${q}`; @@ -50,8 +51,10 @@ router.get('/', async function (req, res) { }; }); const titles = (await Conversation.meiliSearch(q)).hits; - console.log('message hits:', messages.length, 'convo hits:', titles.length); const sortedHits = reduceHits(messages, titles); + // debugging: + // console.log('user:', user, 'message hits:', messages.length, 'convo hits:', titles.length); + // console.log('sorted hits:', sortedHits.length); const result = await getConvosQueried(user, sortedHits, pageNumber); const activeMessages = []; From 226306b53f36211c48176d14f1bae9c236419f89 Mon Sep 17 00:00:00 2001 From: Daniel Avila Date: Fri, 24 Mar 2023 18:27:51 -0400 Subject: [PATCH 2/3] chore: expose mongodb on port 27018 --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 569af4602f5..c15825c3147 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,8 @@ services: - ./api:/api - /api/node_modules mongodb: + ports: + - 27018:27017 image: mongo restart: always container_name: mongodb From a708bd13db3c4be0c2ff72f10e30687af27f9314 Mon Sep 17 00:00:00 2001 From: Daniel Avila Date: Fri, 24 Mar 2023 18:44:12 -0400 Subject: [PATCH 3/3] fix: correctly escapes user content in search results --- client/src/components/Messages/Content/Content.jsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/src/components/Messages/Content/Content.jsx b/client/src/components/Messages/Content/Content.jsx index 03f565175dd..e240c9986fb 100644 --- a/client/src/components/Messages/Content/Content.jsx +++ b/client/src/components/Messages/Content/Content.jsx @@ -8,8 +8,8 @@ import rehypeRaw from 'rehype-raw' import CodeBlock from './CodeBlock'; import { langSubset } from '~/utils/languages'; -const Content = React.memo(({ content, isCreatedByUser = false }) => { - const rehypePlugins = [ +const Content = React.memo(({ content, isCreatedByUser = true }) => { + let rehypePlugins = [ [rehypeKatex, { output: 'mathml' }], [ rehypeHighlight, @@ -20,12 +20,15 @@ const Content = React.memo(({ content, isCreatedByUser = false }) => { } ], [rehypeRaw], - ] + ]; + + rehypePlugins = isCreatedByUser ? rehypePlugins.slice(0, -1) : rehypePlugins; + return ( <>