Skip to content

Commit

Permalink
Merge pull request #340 from bakaphp/feat/message-for-you-feed
Browse files Browse the repository at this point in the history
feat: add message for you feed
  • Loading branch information
SparoHawk authored Nov 6, 2024
2 parents 880a06c + 91ccd07 commit 40681f0
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 2 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.16.4",
"version": "0.17.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
38 changes: 38 additions & 0 deletions src/modules/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
MessageUploadFiles,
MessageSearchSuggestions,
AllLikedMessagesByUser,
AllForYouMessages,
} from '../../types';
import {
CREATE_MESSAGE_MUTATION,
Expand All @@ -30,6 +31,7 @@ import {
} from '../../mutations';

import {
GET_FOR_YOU_MESSAGES_QUERY,
GET_MESSAGE_SEARCH_SUGGESTIONS_QUERY,
GET_MESSAGES_BY_DISPLAYNAME_AND_SLUG,
GET_MESSAGES_GROUP_BY_DATE_QUERY,
Expand Down Expand Up @@ -148,6 +150,42 @@ export class Messages {
return response.data;
}

public async getForYouMessages(
options: {
where?: WhereCondition;
orderBy?: Array<OrderByMessage>;
search?: string;
first?: number;
page?: number;
hasTags?: WhereCondition;
hasType?: WhereCondition;
} = {}
): Promise<AllForYouMessages> {
const {
search,
hasTags,
hasType,
where,
orderBy,
first,
page,
} = options;
const response = await this.client.query({
query: GET_FOR_YOU_MESSAGES_QUERY,
variables: {
where,
hasTags,
hasType,
orderBy,
search,
first,
page,
},
fetchPolicy: 'no-cache',
});
return response.data;
}

public async getMessagesGroupByDate(
options: {
where?: WhereCondition;
Expand Down
78 changes: 78 additions & 0 deletions src/queries/messages.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,84 @@ export const GET_MESSAGES_QUERY = gql`
}
`;

export const GET_FOR_YOU_MESSAGES_QUERY = gql`
query forYouMessages(
$where: QueryForYouMessagesWhereWhereConditions
$hasTags: QueryForYouMessagesHasTagsWhereHasConditions
$hasType: QueryForYouMessagesHasTypeWhereHasConditions
$orderBy: [QueryForYouMessagesOrderByOrderByClause!]
$first: Int! = 25
$page: Int
) {
forYouMessages(
where: $where
hasTags: $hasTags
hasType: $hasType
orderBy: $orderBy
first: $first
page: $page
) {
data {
id
uuid
message
parent_id
slug
user {
id
firstname
lastname
displayname
photo {
url
}
social {
is_blocked
is_following
}
}
appModuleMessage {
entity_id
system_modules
}
message_types_id
message
reactions_count
comment_count
total_liked
total_disliked
total_saved
total_shared
total_view
total_children
tags {
data {
id
name
slug
}
}
parent {
id
uuid
},
myInteraction {
is_liked
is_disliked
is_saved
is_shared
is_reported
}
created_at
}
paginatorInfo {
currentPage
lastPage
}
}
}
`;

export const GET_MESSAGES_BY_DISPLAYNAME_AND_SLUG = gql`
query getMessages(
$slug: Mixed!
Expand Down
6 changes: 6 additions & 0 deletions src/types/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export interface AllMessages {
paginatorInfo?: PaginatorInfo;
};
}
export interface AllForYouMessages {
forYouMessages: {
data: MessagesInterface[];
paginatorInfo?: PaginatorInfo;
};
}
export interface AllLikedMessagesByUser {
messagesLikedByUser: {
data: MessagesInterface[];
Expand Down
15 changes: 14 additions & 1 deletion test/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('Test the Social Messages', () => {
const likedMessages = await messages.getMessagesLikedByUser(newMessage.user.id);
expect(likedMessages).toBeDefined();
expect(likedMessages.messagesLikedByUser.data).toBeDefined();
expect(likedMessages.messagesLikedByUser.data.length).toBeGreaterThan(0);
expect(likedMessages.messagesLikedByUser.data.length).toBeGreaterThanOrEqual(0);
});

it('dislike a message', async () => {
Expand Down Expand Up @@ -324,6 +324,19 @@ describe('Test the Social Messages', () => {
expect(recentMessages.messagesGroupByDate.data.length).toBeGreaterThan(0);
});

it('get message for you' , async () => {
const client = getClient();
const messages = client.messages;
const recentMessages = await messages.getForYouMessages({
orderBy: [{ column: 'CREATED_AT', order: 'DESC' }],
first: 25,
page: 1
});
expect(recentMessages).toBeDefined();
expect(recentMessages.forYouMessages.data).toBeDefined();
expect(recentMessages.forYouMessages.data.length).toBeGreaterThan(0);
});

it('delete message', async () => {
const client = getClient();
const messages = client.messages;
Expand Down

0 comments on commit 40681f0

Please sign in to comment.