Skip to content

Commit

Permalink
Merge pull request #367 from bakaphp/feat/message-channel
Browse files Browse the repository at this point in the history
refact/channel-query
  • Loading branch information
kaioken authored Dec 23, 2024
2 parents f3c3ec7 + 2bc91be commit 2116719
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.23.1",
"version": "0.23.2",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
14 changes: 12 additions & 2 deletions src/modules/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,38 @@ export class Messages {
orderBy?: Array<OrderByMessage>;
first?: number;
page?: number;
childrenOptions?: {
alias?: string; // Alias for the children field
first?: number; // Limit for children
};
} = {}
): Promise<AllChannelMessages> {
const {
channel_uuid,
channel_slug,
where,
orderBy,
first,
first = 25,
page,
childrenOptions = {},
} = options;

const { alias = 'children', first: childrenFirst } = childrenOptions;

const response = await this.client.query({
query: GET_CHANNEL_MESSAGES_QUERY,
query: GET_CHANNEL_MESSAGES_QUERY(childrenFirst !== undefined, alias),
variables: {
channel_uuid,
channel_slug,
where,
orderBy,
first,
page,
...(childrenFirst !== undefined && { childrenFirst }),
},
fetchPolicy: 'no-cache',
});

return response.data;
}

Expand Down
20 changes: 19 additions & 1 deletion src/queries/messages.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ export const GET_MESSAGES_BY_DISPLAYNAME_AND_SLUG = gql`
}
`;

export const GET_CHANNEL_MESSAGES_QUERY = gql`
export const GET_CHANNEL_MESSAGES_QUERY = (includeChildren: boolean, alias: string) => gql`
query channelMessages(
$channel_uuid: String
$channel_slug: String
$where: QueryChannelMessagesWhereWhereConditions
$orderBy: [QueryChannelMessagesOrderByOrderByClause!]
$first: Int! = 25
$page: Int
${includeChildren ? `$childrenFirst: Int!` : ''}
) {
channelMessages(
channel_uuid: $channel_uuid
Expand Down Expand Up @@ -335,6 +336,23 @@ export const GET_CHANNEL_MESSAGES_QUERY = gql`
is_reported
is_purchased
}
${includeChildren ? `${alias}: children(first: $childrenFirst) {
data {
id
uuid
message
slug
user {
id
firstname
lastname
displayname
photo {
url
}
}
}
}` : ''}
created_at
}
paginatorInfo {
Expand Down

0 comments on commit 2116719

Please sign in to comment.