Skip to content

Commit

Permalink
feat(lib): rm normalizeParams channel function
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Dec 4, 2023
1 parent 9872275 commit 59ae13d
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions lib/src/entities/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ export type ChannelFields = Pick<
"id" | "name" | "custom" | "description" | "updated" | "status" | "type"
>

function normalizeChannelParams(params: ChannelDTOParams | ChannelMetadataObject<ObjectCustom>) {
return {
...params,
id: params.id,
name: params.name || undefined,
custom: params.custom || undefined,
description: params.description || undefined,
updated: params.updated || undefined,
status: params.status || undefined,
type:
params.type && ["direct", "group", "public"].includes(params.type)
? (params.type as ChannelType)
: "unknown",
}
}

export class Channel {
protected chat: Chat
readonly id: string
Expand Down Expand Up @@ -89,10 +73,13 @@ export class Channel {
description: params.description || undefined,
updated: params.updated || undefined,
status: params.status || undefined,
type: params.type || undefined,
type:
params.type && ["direct", "group", "public"].includes(params.type)
? (params.type as ChannelType)
: "unknown",
}

return getErrorProxiedEntity(new Channel(chat, normalizeChannelParams(data)), chat.errorLogger)
return getErrorProxiedEntity(new Channel(chat, data), chat.errorLogger)
}

/*
Expand All @@ -116,7 +103,7 @@ export class Channel {
if (event.message.type !== "channel") return
const channel = channels.find((c) => c.id === event.channel)
if (!channel) return
const newChannel = Channel.fromDTO(channel.chat, normalizeChannelParams(event.message.data))
const newChannel = Channel.fromDTO(channel.chat, event.message.data)
const newChannels = channels.map((channel) =>
channel.id === newChannel.id ? newChannel : channel
)
Expand Down Expand Up @@ -574,12 +561,12 @@ export class Channel {

async pinMessage(message: Message) {
const response = await this.chat.pinMessageToChannel(message, this)
return Channel.fromDTO(this.chat, normalizeChannelParams(response.data))
return Channel.fromDTO(this.chat, response.data)
}

async unpinMessage() {
const response = await this.chat.pinMessageToChannel(null, this)
return Channel.fromDTO(this.chat, normalizeChannelParams(response.data))
return Channel.fromDTO(this.chat, response.data)
}

async getPinnedMessage() {
Expand Down

0 comments on commit 59ae13d

Please sign in to comment.