Skip to content

Commit

Permalink
use DISABLE_MESSAGE_PARSER env
Browse files Browse the repository at this point in the history
  • Loading branch information
heitortanoue committed Dec 4, 2023
1 parent 32e76c3 commit b0a6544
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion apps/meteor/app/lib/server/functions/saveUserIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ async function updateUsernameReferences({
await Messages.updateUsernameOfEditByUserId(user._id, username);

const cursor = Messages.findByMention(previousUsername);
const isParserEnabled = process.env.DISABLE_MESSAGE_PARSER !== 'true';
for await (const msg of cursor) {
const updatedMsg = msg.msg.replace(new RegExp(`@${previousUsername}`, 'ig'), `@${username}`);
const updatedMd = messageTextToAstMarkdown(updatedMsg);

const updatedMd = isParserEnabled ? messageTextToAstMarkdown(updatedMsg) : null;
await Messages.updateUsernameAndMessageAndMdOfMentionByIdAndOldUsername(msg._id, previousUsername, username, updatedMsg, updatedMd);
}

Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/server/models/raw/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ export class MessagesRaw extends BaseRaw<IMessage> implements IMessagesModel {
oldUsername: string,
newUsername: string,
newMessage: string,
newMd: Root,
newMd: Root | null,
): Promise<UpdateResult> {
const query = {
_id,
Expand All @@ -1216,8 +1216,9 @@ export class MessagesRaw extends BaseRaw<IMessage> implements IMessagesModel {
$set: {
'mentions.$.username': newUsername,
'msg': newMessage,
'md': newMd,
...(newMd ? { md: newMd } : {}),
},
...(!newMd ? { $unset: { md: 1 } } : {}),
};

return this.updateOne(query, update);
Expand Down
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/IMessagesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export interface IMessagesModel extends IBaseModel<IMessage> {
oldUsername: string,
newUsername: string,
newMessage: string,
newMd: Root,
newMd: Root | null,
): Promise<UpdateResult>;
unlinkUserId(userId: string, newUserId: string, newUsername: string, newNameAlias: string): Promise<UpdateResult | Document>;
setSlackBotIdAndSlackTs(_id: string, slackBotId: string, slackTs: Date): Promise<UpdateResult>;
Expand Down

0 comments on commit b0a6544

Please sign in to comment.