Skip to content

Commit

Permalink
feat(lib): cr
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Nov 2, 2023
1 parent 08b3c3a commit 2a1954d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/src/entities/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -600,7 +600,7 @@ export class Channel {
text: string,
options: { limit: number } = { limit: 10 }
): Promise<Membership[]> {
const cacheKey = MessagePartsUtils.getPhraseToLookFor(text)
const cacheKey = MessageElementsUtils.getPhraseToLookFor(text)

if (!cacheKey) {
return []
Expand Down
6 changes: 3 additions & 3 deletions lib/src/entities/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -842,7 +842,7 @@ export class Chat {
text: string,
options: { limit: number } = { limit: 10 }
): Promise<User[]> {
const cacheKey = MessagePartsUtils.getPhraseToLookFor(text)
const cacheKey = MessageElementsUtils.getPhraseToLookFor(text)

if (!cacheKey) {
return []
Expand All @@ -866,7 +866,7 @@ export class Chat {
text: string,
options: { limit: number } = { limit: 10 }
): Promise<Channel[]> {
const cacheKey = MessagePartsUtils.getChannelPhraseToLookFor(text)
const cacheKey = MessageElementsUtils.getChannelPhraseToLookFor(text)

if (!cacheKey) {
return []
Expand Down
4 changes: 2 additions & 2 deletions lib/src/entities/message-draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -609,7 +609,7 @@ export class MessageDraft {
}

getMessagePreview() {
return MessagePartsUtils.getMessageElements({
return MessageElementsUtils.getMessageElements({
text: this.value,
textLinks: this.textLinks,
mentionedUsers: this.transformMentionedUsersToSend(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2a1954d

Please sign in to comment.