Add last_message_id param to API

This commit is contained in:
Justin 2022-08-30 10:10:31 -04:00
parent 2a02f6dcc7
commit 5dd44d3094
3 changed files with 10 additions and 8 deletions

View File

@ -56,12 +56,6 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize, inputRef }
const isSubmitDisabled = content.length === 0 && !attachment; const isSubmitDisabled = content.length === 0 && !attachment;
const markAsRead = useMutation(() => markChatAsRead(), {
onSuccess: () => {
queryClient.invalidateQueries(['chats']);
},
});
const submitMessage = useMutation(({ chatId, content }: any) => { const submitMessage = useMutation(({ chatId, content }: any) => {
return createChatMessage(chatId, content); return createChatMessage(chatId, content);
}, { }, {

View File

@ -347,7 +347,11 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat, autosize }) => {
}, [formattedChatMessages.length]); }, [formattedChatMessages.length]);
useEffect(() => { useEffect(() => {
markChatAsRead(); const lastMessageId = formattedChatMessages.pop()?.id;
if (lastMessageId) {
markChatAsRead(lastMessageId);
}
}, [formattedChatMessages.length]); }, [formattedChatMessages.length]);
useEffect(() => { useEffect(() => {

View File

@ -135,7 +135,11 @@ const useChat = (chatId: string) => {
const api = useApi(); const api = useApi();
const { setChat, setEditing } = useChatContext(); const { setChat, setEditing } = useChatContext();
const markChatAsRead = () => api.post<IChat>(`/api/v1/pleroma/chats/${chatId}/read`); const markChatAsRead = (lastReadId: string) => {
api.post<IChat>(`/api/v1/pleroma/chats/${chatId}/read`, { last_read_id: lastReadId })
.then(() => queryClient.invalidateQueries(['chats']))
.catch(() => null);
};
const createChatMessage = (chatId: string, content: string) => { const createChatMessage = (chatId: string, content: string) => {
return api.post<IChat>(`/api/v1/pleroma/chats/${chatId}/messages`, { content }); return api.post<IChat>(`/api/v1/pleroma/chats/${chatId}/messages`, { content });