Skip to content

Commit

Permalink
feat(lib): customize message reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Aug 19, 2024
1 parent 05eb006 commit 32891e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/src/default-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export function defaultGetMessageResponseBody(messageParams: MessageDTOParams) {

export const defaultEditActionName = MessageActionType.EDITED
export const defaultDeleteActionName = MessageActionType.DELETED

export const defaultReactionsName = MessageActionType.REACTIONS
10 changes: 9 additions & 1 deletion lib/src/entities/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { MessageElementsUtils } from "../message-elements-utils"
import { getErrorProxiedEntity, ErrorLogger } from "../error-logging"
import { cyrb53a } from "../hash"
import { uuidv4 } from "../uuidv4"
import { defaultEditActionName, defaultDeleteActionName } from "../default-values"
import {
defaultEditActionName,
defaultDeleteActionName,
defaultReactionsName,
} from "../default-values"
import { AccessManager } from "../access-manager"

export type ChatConfig = {
Expand All @@ -47,6 +51,7 @@ export type ChatConfig = {
getMessageResponseBody?: (m: MessageDTOParams) => TextMessageContent
editMessageActionName?: string
deleteMessageActionName?: string
reactionsActionName?: string
}
authKey?: string
}
Expand All @@ -72,6 +77,8 @@ export class Chat {
/** @internal */
readonly deleteMessageActionName: string
/** @internal */
readonly reactionsActionName: string
/** @internal */
readonly accessManager: AccessManager

/** @internal */
Expand All @@ -93,6 +100,7 @@ export class Chat {
this.editMessageActionName = customPayloads?.editMessageActionName || defaultEditActionName
this.deleteMessageActionName =
customPayloads?.deleteMessageActionName || defaultDeleteActionName
this.reactionsActionName = customPayloads?.reactionsActionName || defaultReactionsName

try {
if (storeUserActivityInterval && storeUserActivityInterval < 60000) {
Expand Down
12 changes: 3 additions & 9 deletions lib/src/entities/message.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Chat } from "./chat"
import PubNub from "pubnub"
import {
DeleteParameters,
MessageActions,
MessageDTOParams,
TextMessageContent,
MessageActionType,
} from "../types"
import { DeleteParameters, MessageActions, MessageDTOParams, TextMessageContent } from "../types"
import { INTERNAL_ADMIN_CHANNEL, INTERNAL_MODERATION_PREFIX } from "../constants"
import { getErrorProxiedEntity } from "../error-logging"
import { MessageElementsUtils } from "../message-elements-utils"
Expand Down Expand Up @@ -319,7 +313,7 @@ export class Message {
* Reactions
*/
get reactions() {
const type = MessageActionType.REACTIONS
const type = this.chat.reactionsActionName
return this.actions?.[type] || {}
}

Expand All @@ -328,7 +322,7 @@ export class Message {
}

async toggleReaction(reaction: string) {
const type = MessageActionType.REACTIONS
const type = this.chat.reactionsActionName
const uuid = this.chat.sdk.getUUID()
const messageTimetoken = this.timetoken
const channel = this.channelId
Expand Down

0 comments on commit 32891e5

Please sign in to comment.