feat: add pagination to DM session

This commit is contained in:
zerosoul
2022-06-09 22:07:01 +08:00
parent 1506b27e99
commit 7571cc60ec
6 changed files with 67 additions and 47 deletions
+4 -4
View File
@@ -59,12 +59,12 @@ export const channelApi = createApi({
},
}),
getHistoryMessages: builder.query({
query: ({ gid, mid = null, limit = 100 }) => ({
query: ({ id, mid = null, limit = 100 }) => ({
url: mid
? `/group/${gid}/history?before=${mid}&limit=${limit}`
: `/group/${gid}/history?limit=${limit}`,
? `/group/${id}/history?before=${mid}&limit=${limit}`
: `/group/${id}/history?limit=${limit}`,
}),
async onQueryStarted(id, { dispatch, getState, queryFulfilled }) {
async onQueryStarted(params, { dispatch, getState, queryFulfilled }) {
const { data: messages } = await queryFulfilled;
if (messages?.length) {
messages.forEach((msg) => {
+18
View File
@@ -7,6 +7,8 @@ import { updateMute } from "../slices/footprint";
import { fullfillContacts } from "../slices/contacts";
import BASE_URL, { ContentTypes } from "../config";
import { onMessageSendStarted } from "./handlers";
import handleChatMessage from "../../common/hook/useStreaming/chat.handler";
export const contactApi = createApi({
reducerPath: "contactApi",
baseQuery,
@@ -110,10 +112,26 @@ export const contactApi = createApi({
await onMessageSendStarted.call(this, param1, param2, "user");
},
}),
getHistoryMessages: builder.query({
query: ({ id, mid = null, limit = 100 }) => ({
url: mid
? `/user/${id}/history?before=${mid}&limit=${limit}`
: `/user/${id}/history?limit=${limit}`,
}),
async onQueryStarted(params, { dispatch, getState, queryFulfilled }) {
const { data: messages } = await queryFulfilled;
if (messages?.length) {
messages.forEach((msg) => {
handleChatMessage(msg, dispatch, getState());
});
}
},
}),
}),
});
export const {
useLazyGetHistoryMessagesQuery,
useUpdateContactMutation,
useUpdateMuteSettingMutation,
useLazyDeleteContactQuery,