From b60b08b7b3af281fa65d7a929e1c09c0df2cac3a Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Jan 2020 13:00:32 +0100 Subject: [PATCH] Add chat message pagination --- src/graphql/schema.graphql | 2 +- src/lib/models/ChatRoom.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index b4c2162..eb91a75 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -341,7 +341,7 @@ type ChatRoom { members(first: Int=10, offset: Int=0): [User!] "return a specfic range of messages posted in the chat" - messages(first: Int = 10, offset: Int, containing: String): [ChatMessage]! + messages(first: Int = 10, offset: Int): [ChatMessage]! "id of the chat" id: ID! diff --git a/src/lib/models/ChatRoom.ts b/src/lib/models/ChatRoom.ts index 5187843..f521387 100644 --- a/src/lib/models/ChatRoom.ts +++ b/src/lib/models/ChatRoom.ts @@ -37,8 +37,10 @@ export class ChatRoom extends Model { /** * Returns the messages that have been sent in the chatroom */ - public async messages(): Promise { - return await this.$get("rMessages") as ChatMessage[]; + public async messages({first, offset}: {first: number, offset: number}): Promise { + const limit = first ?? 10; + offset = offset ?? 0; + return await this.$get("rMessages", {limit, offset}) as ChatMessage[]; } /**