Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): customize message reactions #177

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading