diff --git a/lib/src/entities/channel.ts b/lib/src/entities/channel.ts index 20bd3f1..aa75763 100644 --- a/lib/src/entities/channel.ts +++ b/lib/src/entities/channel.ts @@ -19,7 +19,7 @@ import { import { ExponentialRateLimiter } from "../rate-limiter" import { Membership } from "./membership" import { User } from "./user" -import { MessagePartsUtils } from "../MessagePartsUtils" +import { MessageElementsUtils } from "../message-elements-utils" import { MessageDraft } from "./message-draft" import { getErrorProxiedEntity } from "../error-logging" import { INTERNAL_MODERATION_PREFIX } from "../constants" @@ -600,7 +600,7 @@ export class Channel { text: string, options: { limit: number } = { limit: 10 } ): Promise { - const cacheKey = MessagePartsUtils.getPhraseToLookFor(text) + const cacheKey = MessageElementsUtils.getPhraseToLookFor(text) if (!cacheKey) { return [] diff --git a/lib/src/entities/chat.ts b/lib/src/entities/chat.ts index 63d5e86..1205b34 100644 --- a/lib/src/entities/chat.ts +++ b/lib/src/entities/chat.ts @@ -16,7 +16,7 @@ import { Event } from "./event" import { Membership } from "./membership" import { MESSAGE_THREAD_ID_PREFIX, INTERNAL_MODERATION_PREFIX } from "../constants" import { ThreadChannel } from "./thread-channel" -import { MessagePartsUtils } from "../MessagePartsUtils" +import { MessageElementsUtils } from "../message-elements-utils" import { getErrorProxiedEntity, ErrorLogger } from "../error-logging" import { cyrb53a } from "../hash" import { uuidv4 } from "../uuidv4" @@ -842,7 +842,7 @@ export class Chat { text: string, options: { limit: number } = { limit: 10 } ): Promise { - const cacheKey = MessagePartsUtils.getPhraseToLookFor(text) + const cacheKey = MessageElementsUtils.getPhraseToLookFor(text) if (!cacheKey) { return [] @@ -866,7 +866,7 @@ export class Chat { text: string, options: { limit: number } = { limit: 10 } ): Promise { - const cacheKey = MessagePartsUtils.getChannelPhraseToLookFor(text) + const cacheKey = MessageElementsUtils.getChannelPhraseToLookFor(text) if (!cacheKey) { return [] diff --git a/lib/src/entities/message-draft.ts b/lib/src/entities/message-draft.ts index 1264c2b..2c8c4fb 100644 --- a/lib/src/entities/message-draft.ts +++ b/lib/src/entities/message-draft.ts @@ -4,7 +4,7 @@ import { User } from "./user" import { Channel } from "./channel" import { MessageDraftConfig, MessageDraftOptions, TextLink } from "../types" import { Validator } from "../validator" -import { MessagePartsUtils } from "../MessagePartsUtils" +import { MessageElementsUtils } from "../message-elements-utils" import { Message } from "./message" declare global { @@ -609,7 +609,7 @@ export class MessageDraft { } getMessagePreview() { - return MessagePartsUtils.getMessageElements({ + return MessageElementsUtils.getMessageElements({ text: this.value, textLinks: this.textLinks, mentionedUsers: this.transformMentionedUsersToSend(), diff --git a/lib/src/entities/message.ts b/lib/src/entities/message.ts index d3f7b15..2202217 100644 --- a/lib/src/entities/message.ts +++ b/lib/src/entities/message.ts @@ -9,7 +9,7 @@ import { } from "../types" import { INTERNAL_ADMIN_CHANNEL } from "../constants" import { getErrorProxiedEntity } from "../error-logging" -import { MessagePartsUtils } from "../MessagePartsUtils" +import { MessageElementsUtils } from "../message-elements-utils" export type MessageFields = Pick< Message, @@ -182,7 +182,7 @@ export class Message { getMessageElements() { const text = this.text - return MessagePartsUtils.getMessageElements({ + return MessageElementsUtils.getMessageElements({ text, textLinks: this.textLinks, mentionedUsers: this.mentionedUsers, diff --git a/lib/src/MessagePartsUtils.ts b/lib/src/message-elements-utils.ts similarity index 99% rename from lib/src/MessagePartsUtils.ts rename to lib/src/message-elements-utils.ts index 9dd699e..f543c91 100644 --- a/lib/src/MessagePartsUtils.ts +++ b/lib/src/message-elements-utils.ts @@ -17,7 +17,7 @@ type GetLinkedTextParams = { const range = (start: number, stop: number, step = 1) => Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step) -export class MessagePartsUtils { +export class MessageElementsUtils { static getPhraseToLookFor(text: string) { const lastAtIndex = text.lastIndexOf("@") const charactersAfterAt = text.split("@").slice(-1)[0] @@ -82,7 +82,7 @@ export class MessagePartsUtils { const relevantIndex = startIndices.indexOf(i) const substring = text.substring(i, endIndices[relevantIndex]) - resultWithTextLinks += `${substring}` + resultWithTextLinks += substring indicesOfWordsWithTextLinks.push({ start: spacesSoFar,