diff --git a/package.json b/package.json index dc22a5e..0ac8004 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.16.4", + "version": "0.17.0", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/modules/messages/index.ts b/src/modules/messages/index.ts index ba006ca..af2abf1 100644 --- a/src/modules/messages/index.ts +++ b/src/modules/messages/index.ts @@ -14,6 +14,7 @@ import { MessageUploadFiles, MessageSearchSuggestions, AllLikedMessagesByUser, + AllForYouMessages, } from '../../types'; import { CREATE_MESSAGE_MUTATION, @@ -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, @@ -148,6 +150,42 @@ export class Messages { return response.data; } + public async getForYouMessages( + options: { + where?: WhereCondition; + orderBy?: Array; + search?: string; + first?: number; + page?: number; + hasTags?: WhereCondition; + hasType?: WhereCondition; + } = {} + ): Promise { + 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; diff --git a/src/queries/messages.query.ts b/src/queries/messages.query.ts index df1899f..c0c9a1e 100644 --- a/src/queries/messages.query.ts +++ b/src/queries/messages.query.ts @@ -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! diff --git a/src/types/messages.ts b/src/types/messages.ts index 81d8b35..a710eb9 100644 --- a/src/types/messages.ts +++ b/src/types/messages.ts @@ -42,6 +42,12 @@ export interface AllMessages { paginatorInfo?: PaginatorInfo; }; } +export interface AllForYouMessages { + forYouMessages: { + data: MessagesInterface[]; + paginatorInfo?: PaginatorInfo; + }; +} export interface AllLikedMessagesByUser { messagesLikedByUser: { data: MessagesInterface[]; diff --git a/test/message.test.ts b/test/message.test.ts index 4865e22..9c5b7bd 100644 --- a/test/message.test.ts +++ b/test/message.test.ts @@ -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 () => { @@ -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;