import * as messageServices from '@12333/services/api/Message';
|
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
import { MessageChatTypeEnum } from '@12333/constants';
|
import { MaybeRef, unref } from 'vue';
|
|
type UseMyMessageCountOptions = {
|
messageChatType?: MaybeRef<MessageChatTypeEnum>;
|
enabled?: MaybeRef<boolean>;
|
isContainLikeFavoriteAddFollowMessageCount?: MaybeRef<boolean>;
|
};
|
|
export function useMyMessageCount(options: UseMyMessageCountOptions = {}) {
|
const {
|
messageChatType,
|
enabled = true,
|
isContainLikeFavoriteAddFollowMessageCount = true,
|
} = options;
|
|
const { data } = useQuery({
|
queryKey: [
|
'messageCount',
|
'messageServices/getMyMessageCount',
|
messageChatType,
|
isContainLikeFavoriteAddFollowMessageCount,
|
],
|
queryFn: async () => {
|
return await messageServices.getMyMessageCount(
|
{
|
messageChatType: unref(messageChatType),
|
isContainLikeFavoriteAddFollowMessageCount: unref(
|
isContainLikeFavoriteAddFollowMessageCount
|
),
|
},
|
{ showLoading: false }
|
);
|
},
|
placeholderData: () => ({} as API.MyMessageCountOutput),
|
enabled: enabled,
|
});
|
|
return {
|
myMessageCount: data,
|
};
|
}
|
|
export function useSetMessageIsRead() {
|
const queryClient = useQueryClient();
|
|
async function setAllMessageIsRead(params: API.APIsetAllMessageIsReadParams) {
|
try {
|
let res = await messageServices.setAllMessageIsRead(params, {
|
showLoading: false,
|
});
|
if (res) {
|
queryClient.invalidateQueries({
|
queryKey: ['messageCount'],
|
});
|
}
|
} catch (error) {}
|
}
|
|
async function setAllMessageIsReadByChatType(params: API.MessageChatTypeEnum) {
|
try {
|
let res = await messageServices.setAllMessageIsReadByChatType(params, {
|
showLoading: false,
|
});
|
if (res) {
|
queryClient.invalidateQueries({
|
queryKey: ['messageCount'],
|
});
|
}
|
} catch (error) {}
|
}
|
|
return {
|
setAllMessageIsRead,
|
setAllMessageIsReadByChatType,
|
};
|
}
|