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

View File

@@ -1,17 +1,5 @@
import { useGalleryStore, useNotificationStore } from '../stores';
import { notificationRequest } from '.';
import { request } from '../service/request';
/**
* @returns {any}
*/
function getGalleryStore() {
return useGalleryStore();
}
function getNotificationStore() {
return useNotificationStore();
}
import { useGalleryStore } from '../stores';
const notificationReq = {
/** @typedef {{
@@ -120,7 +108,7 @@ const notificationReq = {
return request(`invite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage
imageData: useGalleryStore().uploadImage
}).then((json) => {
const args = {
json,
@@ -149,7 +137,7 @@ const notificationReq = {
return request(`requestInvite/${receiverUserId}/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage
imageData: useGalleryStore().uploadImage
}).then((json) => {
const args = {
json,
@@ -178,7 +166,7 @@ const notificationReq = {
return request(`invite/${inviteId}/response/photo`, {
uploadImageLegacy: true,
postData: JSON.stringify(params),
imageData: getGalleryStore().uploadImage,
imageData: useGalleryStore().uploadImage,
inviteId
}).then((json) => {
const args = {
@@ -200,27 +188,13 @@ const notificationReq = {
{
method: 'PUT'
}
)
.then((json) => {
const args = {
json,
params
};
getNotificationStore().handleNotificationAccept(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
};
});
).then((json) => {
const args = {
json,
params
};
return args;
});
},
/**
@@ -238,9 +212,6 @@ const notificationReq = {
json,
params
};
getNotificationStore().handleNotificationHide(
params.notificationId
);
return args;
});
},
@@ -289,24 +260,13 @@ const notificationReq = {
return request(`notifications/${params.notificationId}/respond`, {
method: 'POST',
params
})
.then((json) => {
const args = {
json,
params
};
return args;
})
.catch(() => {
getNotificationStore().handleNotificationV2Hide(
params.notificationId
);
notificationRequest.hideNotificationV2(params.notificationId);
return {
json: null,
params
};
});
}).then((json) => {
const args = {
json,
params
};
return args;
});
},
hideNotificationV2(notificationId) {
@@ -322,35 +282,6 @@ const notificationReq = {
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;

View File

@@ -1303,6 +1303,7 @@
useLocationStore,
useModalStore,
useModerationStore,
useNotificationStore,
useUiStore,
useUserStore,
useWorldStore
@@ -1971,9 +1972,18 @@
});
handleSendFriendRequest(args);
} else {
notificationRequest.acceptFriendRequestNotification({
notificationId: key
});
notificationRequest
.acceptFriendRequestNotification({
notificationId: key
})
.then((args) => {
useNotificationStore().handleNotificationAccept(args);
})
.catch((err) => {
if (err && err.message && err.message.includes('404')) {
useNotificationStore().handleNotificationHide(key);
}
});
}
break;
case 'Decline Friend Request':
@@ -1984,9 +1994,13 @@
});
handleCancelFriendRequest(args);
} else {
notificationRequest.hideNotification({
notificationId: key
});
notificationRequest
.hideNotification({
notificationId: key
})
.then(() => {
useNotificationStore().handleNotificationHide(key);
});
}
break;
case 'Cancel Friend Request': {

View File

@@ -358,9 +358,13 @@ export const useNotificationStore = defineStore('Notification', () => {
});
AppDebug.errorNoty.show();
console.log(text);
notificationRequest.hideNotification({
notificationId: ref.id
});
notificationRequest
.hideNotification({
notificationId: ref.id
})
.then(() => {
handleNotificationHide(ref.id);
});
return _args;
})
.catch((err) => {
@@ -1173,9 +1177,18 @@ export const useNotificationStore = defineStore('Notification', () => {
})
.then(({ ok }) => {
if (!ok) return;
notificationRequest.acceptFriendRequestNotification({
notificationId: row.id
});
notificationRequest
.acceptFriendRequestNotification({
notificationId: row.id
})
.then((args) => {
handleNotificationAccept(args);
})
.catch((err) => {
if (err && err.message && err.message.includes('404')) {
handleNotificationHide(row.id);
}
});
})
.catch(() => {});
}
@@ -1188,9 +1201,13 @@ export const useNotificationStore = defineStore('Notification', () => {
);
handleNotificationHide(row.id);
} else {
notificationRequest.hideNotification({
notificationId: row.id
});
notificationRequest
.hideNotification({
notificationId: row.id
})
.then(() => {
handleNotificationHide(row.id);
});
}
}
@@ -1237,9 +1254,13 @@ export const useNotificationStore = defineStore('Notification', () => {
)
.then((_args) => {
toast(t('message.invite.sent'));
notificationRequest.hideNotification({
notificationId: row.id
});
notificationRequest
.hideNotification({
notificationId: row.id
})
.then(() => {
handleNotificationHide(row.id);
});
return _args;
});
});
@@ -1257,15 +1278,21 @@ export const useNotificationStore = defineStore('Notification', () => {
}
}
const params = { notificationId, responseType, responseData };
notificationRequest.sendNotificationResponse(params).then((args) => {
console.log('Notification response', args);
if (!args.json) return;
handleNotificationV2Hide(notificationId);
new Noty({
type: 'success',
text: escapeTag(args.json)
}).show();
});
notificationRequest
.sendNotificationResponse(params)
.then((args) => {
console.log('Notification response', args);
if (!args.json) return;
handleNotificationV2Hide(notificationId);
new Noty({
type: 'success',
text: escapeTag(args.json)
}).show();
})
.catch(() => {
handleNotificationV2Hide(notificationId);
notificationRequest.hideNotificationV2(notificationId);
});
}
function deleteNotificationLog(row) {

View File

@@ -39,7 +39,7 @@
import { useI18n } from 'vue-i18n';
import { inviteMessagesRequest, notificationRequest } from '../../../api';
import { useGalleryStore } from '../../../stores';
import { useGalleryStore, useNotificationStore } from '../../../stores';
const { t } = useI18n();
const galleryStore = useGalleryStore();
@@ -101,9 +101,13 @@
toast.error(t('message.error'));
})
.then((args) => {
notificationRequest.hideNotification({
notificationId: I.invite.id
});
notificationRequest
.hideNotification({
notificationId: I.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(I.invite.id);
});
toast.success(t('message.invite.response_sent'));
return args;
})
@@ -118,9 +122,13 @@
toast.error(t('message.error'));
})
.then((args) => {
notificationRequest.hideNotification({
notificationId: I.invite.id
});
notificationRequest
.hideNotification({
notificationId: I.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(I.invite.id);
});
toast.success(t('message.invite.response_sent'));
return args;
})

View File

@@ -26,8 +26,8 @@
import { toast } from 'vue-sonner';
import { useI18n } from 'vue-i18n';
import { useGalleryStore, useNotificationStore } from '../../../stores';
import { notificationRequest } from '../../../api';
import { useGalleryStore } from '../../../stores';
const { t } = useI18n();
@@ -65,9 +65,13 @@
toast.error(t('message.error'));
})
.then((args) => {
notificationRequest.hideNotification({
notificationId: D.invite.id
});
notificationRequest
.hideNotification({
notificationId: D.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(D.invite.id);
});
toast.success(t('message.invite.response_photo_sent'));
return args;
})
@@ -82,9 +86,13 @@
toast.error(t('message.error'));
})
.then((args) => {
notificationRequest.hideNotification({
notificationId: D.invite.id
});
notificationRequest
.hideNotification({
notificationId: D.invite.id
})
.then(() => {
useNotificationStore().handleNotificationHide(D.invite.id);
});
toast.success(t('message.invite.response_sent'));
return args;
})