Files
habitica/website/client/src/store/actions/chat.js
T
Fiz 8134fa7c00 Chat optimization (#15545)
* fix(content): textual tweaks and updates

* fix(link): direct to FAQ instead of wiki

* fix(faq): correct Markdown

* Show orb of rebirth confirmation modal after use (window refresh)

* Set and check rebirth confirmation modal from localstorage

Set and check rebirth confirmation modal from localstorage after window reload

* Don't show orb of rebirth confirmation modal until page reloads

* message effective limit optimization

* Keep max limit for web (400 recent messages)

* Fix amount of messages initially being shown

* PM_PER_PAGE set to 50

* Increases number of messages in inbox test

* Increases number of messages for inbox pagination test

* Set and check rebirth confirmation modal from localstorage

Set and check rebirth confirmation modal from localstorage after window reload

* Don't show orb of rebirth confirmation modal until page reloads

* message effective limit optimization

* Keep max limit for web (400 recent messages)

* Add UUID validation for 'before' query parameter

* add party message stress test tool in admin panel

* lint

* add MAX_PM_COUNT of 400, admin tool for stress testing messages

* comment

* update stress test inbox message tool to use logged in user

* comment

---------

Co-authored-by: Kalista Payne <kalista@habitica.com>
2026-01-13 14:43:09 -06:00

93 lines
2.3 KiB
JavaScript

import axios from 'axios';
import Vue from 'vue';
import * as Analytics from '@/libs/analytics';
export async function getChat (store, payload) {
const response = await axios.get(`/api/v4/groups/${payload.groupId}/chat?limit=400`);
return response.data.data;
}
export async function postChat (store, payload) {
const { group } = payload;
let url = `/api/v4/groups/${group._id}/chat`;
if (payload.previousMsg) {
url += `?previousMsg=${payload.previousMsg}`;
}
if (group.type === 'party') {
Analytics.updateUser({
partyID: group.id,
partySize: group.memberCount,
});
}
const response = await axios.post(url, {
message: payload.message,
});
return response.data.data;
}
export async function deleteChat (store, payload) {
let url = `/api/v4/groups/${payload.groupId}/chat/${payload.chatId}`;
if (payload.previousMsg) {
url += `?previousMsg=${payload.previousMsg}`;
}
const response = await axios.delete(url);
return response.data.data;
}
export async function like (store, payload) {
let url = '';
if (payload.groupId === 'privateMessage') {
url = `/api/v4/inbox/like-private-message/${payload.chatMessageId}`;
} else {
url = `/api/v4/groups/${payload.groupId}/chat/${payload.chatMessageId}/like`;
}
const response = await axios.post(url);
return response.data.data;
}
export async function flag (store, payload) {
let url = '';
if (payload.groupId === 'privateMessage') {
url = `/api/v4/members/flag-private-message/${payload.chatId}`;
} else {
url = `/api/v4/groups/${payload.groupId}/chat/${payload.chatId}/flag`;
}
const response = await axios.post(url, {
comment: payload.comment,
});
return response.data.data;
}
export async function clearFlagCount (store, payload) {
const url = `/api/v4/groups/${payload.groupId}/chat/${payload.chatId}/clearflags`;
const response = await axios.post(url);
return response.data.data;
}
export async function markChatSeen (store, payload) {
const url = `/api/v4/groups/${payload.groupId}/chat/seen`;
const response = await axios.post(url);
if (store.state.user.data.newMessages[payload.groupId]) {
Vue.delete(store.state.user.data.newMessages, payload.groupId);
}
if (payload.notificationId) {
store.state.notificationsRemoved.push(payload.notificationId);
}
return response.data.data;
}