Refactor: Delegate notification store updates to calling components after API responses.

This commit is contained in:
pa
2026-03-04 21:48:28 +09:00
parent c522ab21f1
commit 905999b9ae
5 changed files with 116 additions and 128 deletions
+6 -75
View File
@@ -1,17 +1,5 @@
import { useGalleryStore, useNotificationStore } from '../stores';
import { notificationRequest } from '.';
import { request } from '../service/request'; import { request } from '../service/request';
import { useGalleryStore } from '../stores';
/**
* @returns {any}
*/
function getGalleryStore() {
return useGalleryStore();
}
function getNotificationStore() {
return useNotificationStore();
}
const notificationReq = { const notificationReq = {
/** @typedef {{ /** @typedef {{
@@ -120,7 +108,7 @@ const notificationReq = {
return request(`invite/${receiverUserId}/photo`, { return request(`invite/${receiverUserId}/photo`, {
uploadImageLegacy: true, uploadImageLegacy: true,
postData: JSON.stringify(params), postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage imageData: useGalleryStore().uploadImage
}).then((json) => { }).then((json) => {
const args = { const args = {
json, json,
@@ -149,7 +137,7 @@ const notificationReq = {
return request(`requestInvite/${receiverUserId}/photo`, { return request(`requestInvite/${receiverUserId}/photo`, {
uploadImageLegacy: true, uploadImageLegacy: true,
postData: JSON.stringify(params), postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage imageData: useGalleryStore().uploadImage
}).then((json) => { }).then((json) => {
const args = { const args = {
json, json,
@@ -178,7 +166,7 @@ const notificationReq = {
return request(`invite/${inviteId}/response/photo`, { return request(`invite/${inviteId}/response/photo`, {
uploadImageLegacy: true, uploadImageLegacy: true,
postData: JSON.stringify(params), postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage, imageData: useGalleryStore().uploadImage,
inviteId inviteId
}).then((json) => { }).then((json) => {
const args = { const args = {
@@ -200,26 +188,12 @@ const notificationReq = {
{ {
method: 'PUT' method: 'PUT'
} }
) ).then((json) => {
.then((json) => {
const args = { const args = {
json, json,
params params
}; };
getNotificationStore().handleNotificationAccept(args);
return args; return args;
})
.catch((err) => {
// if friend request could not be found, delete it
if (err && err.message && err.message.includes('404')) {
getNotificationStore().handleNotificationHide(
params.notificationId
);
}
return {
json: null,
params
};
}); });
}, },
@@ -238,9 +212,6 @@ const notificationReq = {
json, json,
params params
}; };
getNotificationStore().handleNotificationHide(
params.notificationId
);
return args; return args;
}); });
}, },
@@ -289,23 +260,12 @@ const notificationReq = {
return request(`notifications/${params.notificationId}/respond`, { return request(`notifications/${params.notificationId}/respond`, {
method: 'POST', method: 'POST',
params params
}) }).then((json) => {
.then((json) => {
const args = { const args = {
json, json,
params params
}; };
return args; return args;
})
.catch(() => {
getNotificationStore().handleNotificationV2Hide(
params.notificationId
);
notificationRequest.hideNotificationV2(params.notificationId);
return {
json: null,
params
};
}); });
}, },
@@ -322,35 +282,6 @@ const notificationReq = {
return args; return args;
}); });
} }
// sendInviteGalleryPhoto(params, receiverUserId) {
// return request(`invite/${receiverUserId}/photo`, {
// method: 'POST',
// params
// }).then((json) => {
// const args = {
// json,
// params,
// receiverUserId
// };
// API.$emit('NOTIFICATION:INVITE:GALLERYPHOTO:SEND', args);
// return args;
// });
// },
// API.clearNotifications = function () {
// return request('auth/user/notifications/clear', {
// method: 'PUT'
// }).then((json) => {
// var args = {
// json
// };
// // FIXME: NOTIFICATION:CLEAR 핸들링
// this.$emit('NOTIFICATION:CLEAR', args);
// return args;
// });
// };
}; };
// #endregion
export default notificationReq; export default notificationReq;
@@ -1303,6 +1303,7 @@
useLocationStore, useLocationStore,
useModalStore, useModalStore,
useModerationStore, useModerationStore,
useNotificationStore,
useUiStore, useUiStore,
useUserStore, useUserStore,
useWorldStore useWorldStore
@@ -1971,8 +1972,17 @@
}); });
handleSendFriendRequest(args); handleSendFriendRequest(args);
} else { } else {
notificationRequest.acceptFriendRequestNotification({ notificationRequest
.acceptFriendRequestNotification({
notificationId: key notificationId: key
})
.then((args) => {
useNotificationStore().handleNotificationAccept(args);
})
.catch((err) => {
if (err && err.message && err.message.includes('404')) {
useNotificationStore().handleNotificationHide(key);
}
}); });
} }
break; break;
@@ -1984,8 +1994,12 @@
}); });
handleCancelFriendRequest(args); handleCancelFriendRequest(args);
} else { } else {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: key notificationId: key
})
.then(() => {
useNotificationStore().handleNotificationHide(key);
}); });
} }
break; break;
+32 -5
View File
@@ -358,8 +358,12 @@ export const useNotificationStore = defineStore('Notification', () => {
}); });
AppDebug.errorNoty.show(); AppDebug.errorNoty.show();
console.log(text); console.log(text);
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: ref.id notificationId: ref.id
})
.then(() => {
handleNotificationHide(ref.id);
}); });
return _args; return _args;
}) })
@@ -1173,8 +1177,17 @@ export const useNotificationStore = defineStore('Notification', () => {
}) })
.then(({ ok }) => { .then(({ ok }) => {
if (!ok) return; if (!ok) return;
notificationRequest.acceptFriendRequestNotification({ notificationRequest
.acceptFriendRequestNotification({
notificationId: row.id notificationId: row.id
})
.then((args) => {
handleNotificationAccept(args);
})
.catch((err) => {
if (err && err.message && err.message.includes('404')) {
handleNotificationHide(row.id);
}
}); });
}) })
.catch(() => {}); .catch(() => {});
@@ -1188,8 +1201,12 @@ export const useNotificationStore = defineStore('Notification', () => {
); );
handleNotificationHide(row.id); handleNotificationHide(row.id);
} else { } else {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: row.id notificationId: row.id
})
.then(() => {
handleNotificationHide(row.id);
}); });
} }
} }
@@ -1237,8 +1254,12 @@ export const useNotificationStore = defineStore('Notification', () => {
) )
.then((_args) => { .then((_args) => {
toast(t('message.invite.sent')); toast(t('message.invite.sent'));
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: row.id notificationId: row.id
})
.then(() => {
handleNotificationHide(row.id);
}); });
return _args; return _args;
}); });
@@ -1257,7 +1278,9 @@ export const useNotificationStore = defineStore('Notification', () => {
} }
} }
const params = { notificationId, responseType, responseData }; const params = { notificationId, responseType, responseData };
notificationRequest.sendNotificationResponse(params).then((args) => { notificationRequest
.sendNotificationResponse(params)
.then((args) => {
console.log('Notification response', args); console.log('Notification response', args);
if (!args.json) return; if (!args.json) return;
handleNotificationV2Hide(notificationId); handleNotificationV2Hide(notificationId);
@@ -1265,6 +1288,10 @@ export const useNotificationStore = defineStore('Notification', () => {
type: 'success', type: 'success',
text: escapeTag(args.json) text: escapeTag(args.json)
}).show(); }).show();
})
.catch(() => {
handleNotificationV2Hide(notificationId);
notificationRequest.hideNotificationV2(notificationId);
}); });
} }
@@ -39,7 +39,7 @@
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { inviteMessagesRequest, notificationRequest } from '../../../api'; import { inviteMessagesRequest, notificationRequest } from '../../../api';
import { useGalleryStore } from '../../../stores'; import { useGalleryStore, useNotificationStore } from '../../../stores';
const { t } = useI18n(); const { t } = useI18n();
const galleryStore = useGalleryStore(); const galleryStore = useGalleryStore();
@@ -101,8 +101,12 @@
toast.error(t('message.error')); toast.error(t('message.error'));
}) })
.then((args) => { .then((args) => {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: I.invite.id notificationId: I.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(I.invite.id);
}); });
toast.success(t('message.invite.response_sent')); toast.success(t('message.invite.response_sent'));
return args; return args;
@@ -118,8 +122,12 @@
toast.error(t('message.error')); toast.error(t('message.error'));
}) })
.then((args) => { .then((args) => {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: I.invite.id notificationId: I.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(I.invite.id);
}); });
toast.success(t('message.invite.response_sent')); toast.success(t('message.invite.response_sent'));
return args; return args;
@@ -26,8 +26,8 @@
import { toast } from 'vue-sonner'; import { toast } from 'vue-sonner';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useGalleryStore, useNotificationStore } from '../../../stores';
import { notificationRequest } from '../../../api'; import { notificationRequest } from '../../../api';
import { useGalleryStore } from '../../../stores';
const { t } = useI18n(); const { t } = useI18n();
@@ -65,8 +65,12 @@
toast.error(t('message.error')); toast.error(t('message.error'));
}) })
.then((args) => { .then((args) => {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: D.invite.id notificationId: D.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(D.invite.id);
}); });
toast.success(t('message.invite.response_photo_sent')); toast.success(t('message.invite.response_photo_sent'));
return args; return args;
@@ -82,8 +86,12 @@
toast.error(t('message.error')); toast.error(t('message.error'));
}) })
.then((args) => { .then((args) => {
notificationRequest.hideNotification({ notificationRequest
.hideNotification({
notificationId: D.invite.id notificationId: D.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(D.invite.id);
}); });
toast.success(t('message.invite.response_sent')); toast.success(t('message.invite.response_sent'));
return args; return args;