mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 14:56:06 +02:00
Refactor: Delegate notification store updates to calling components after API responses.
This commit is contained in:
+6
-75
@@ -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,26 +188,12 @@ const notificationReq = {
|
||||
{
|
||||
method: 'PUT'
|
||||
}
|
||||
)
|
||||
.then((json) => {
|
||||
).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
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@@ -238,9 +212,6 @@ const notificationReq = {
|
||||
json,
|
||||
params
|
||||
};
|
||||
getNotificationStore().handleNotificationHide(
|
||||
params.notificationId
|
||||
);
|
||||
return args;
|
||||
});
|
||||
},
|
||||
@@ -289,23 +260,12 @@ const notificationReq = {
|
||||
return request(`notifications/${params.notificationId}/respond`, {
|
||||
method: 'POST',
|
||||
params
|
||||
})
|
||||
.then((json) => {
|
||||
}).then((json) => {
|
||||
const args = {
|
||||
json,
|
||||
params
|
||||
};
|
||||
return args;
|
||||
})
|
||||
.catch(() => {
|
||||
getNotificationStore().handleNotificationV2Hide(
|
||||
params.notificationId
|
||||
);
|
||||
notificationRequest.hideNotificationV2(params.notificationId);
|
||||
return {
|
||||
json: null,
|
||||
params
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1303,6 +1303,7 @@
|
||||
useLocationStore,
|
||||
useModalStore,
|
||||
useModerationStore,
|
||||
useNotificationStore,
|
||||
useUiStore,
|
||||
useUserStore,
|
||||
useWorldStore
|
||||
@@ -1971,8 +1972,17 @@
|
||||
});
|
||||
handleSendFriendRequest(args);
|
||||
} else {
|
||||
notificationRequest.acceptFriendRequestNotification({
|
||||
notificationRequest
|
||||
.acceptFriendRequestNotification({
|
||||
notificationId: key
|
||||
})
|
||||
.then((args) => {
|
||||
useNotificationStore().handleNotificationAccept(args);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err && err.message && err.message.includes('404')) {
|
||||
useNotificationStore().handleNotificationHide(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1984,8 +1994,12 @@
|
||||
});
|
||||
handleCancelFriendRequest(args);
|
||||
} else {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: key
|
||||
})
|
||||
.then(() => {
|
||||
useNotificationStore().handleNotificationHide(key);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -358,8 +358,12 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
});
|
||||
AppDebug.errorNoty.show();
|
||||
console.log(text);
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: ref.id
|
||||
})
|
||||
.then(() => {
|
||||
handleNotificationHide(ref.id);
|
||||
});
|
||||
return _args;
|
||||
})
|
||||
@@ -1173,8 +1177,17 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
})
|
||||
.then(({ ok }) => {
|
||||
if (!ok) return;
|
||||
notificationRequest.acceptFriendRequestNotification({
|
||||
notificationRequest
|
||||
.acceptFriendRequestNotification({
|
||||
notificationId: row.id
|
||||
})
|
||||
.then((args) => {
|
||||
handleNotificationAccept(args);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err && err.message && err.message.includes('404')) {
|
||||
handleNotificationHide(row.id);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
@@ -1188,8 +1201,12 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
);
|
||||
handleNotificationHide(row.id);
|
||||
} else {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: row.id
|
||||
})
|
||||
.then(() => {
|
||||
handleNotificationHide(row.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1237,8 +1254,12 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
)
|
||||
.then((_args) => {
|
||||
toast(t('message.invite.sent'));
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: row.id
|
||||
})
|
||||
.then(() => {
|
||||
handleNotificationHide(row.id);
|
||||
});
|
||||
return _args;
|
||||
});
|
||||
@@ -1257,7 +1278,9 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
}
|
||||
}
|
||||
const params = { notificationId, responseType, responseData };
|
||||
notificationRequest.sendNotificationResponse(params).then((args) => {
|
||||
notificationRequest
|
||||
.sendNotificationResponse(params)
|
||||
.then((args) => {
|
||||
console.log('Notification response', args);
|
||||
if (!args.json) return;
|
||||
handleNotificationV2Hide(notificationId);
|
||||
@@ -1265,6 +1288,10 @@ export const useNotificationStore = defineStore('Notification', () => {
|
||||
type: 'success',
|
||||
text: escapeTag(args.json)
|
||||
}).show();
|
||||
})
|
||||
.catch(() => {
|
||||
handleNotificationV2Hide(notificationId);
|
||||
notificationRequest.hideNotificationV2(notificationId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,8 +101,12 @@
|
||||
toast.error(t('message.error'));
|
||||
})
|
||||
.then((args) => {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: I.invite.id
|
||||
})
|
||||
.then(() => {
|
||||
useNotificationStore().handleNotificationHide(I.invite.id);
|
||||
});
|
||||
toast.success(t('message.invite.response_sent'));
|
||||
return args;
|
||||
@@ -118,8 +122,12 @@
|
||||
toast.error(t('message.error'));
|
||||
})
|
||||
.then((args) => {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: I.invite.id
|
||||
})
|
||||
.then(() => {
|
||||
useNotificationStore().handleNotificationHide(I.invite.id);
|
||||
});
|
||||
toast.success(t('message.invite.response_sent'));
|
||||
return args;
|
||||
|
||||
@@ -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,8 +65,12 @@
|
||||
toast.error(t('message.error'));
|
||||
})
|
||||
.then((args) => {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: D.invite.id
|
||||
})
|
||||
.then(() => {
|
||||
useNotificationStore().handleNotificationHide(D.invite.id);
|
||||
});
|
||||
toast.success(t('message.invite.response_photo_sent'));
|
||||
return args;
|
||||
@@ -82,8 +86,12 @@
|
||||
toast.error(t('message.error'));
|
||||
})
|
||||
.then((args) => {
|
||||
notificationRequest.hideNotification({
|
||||
notificationRequest
|
||||
.hideNotification({
|
||||
notificationId: D.invite.id
|
||||
})
|
||||
.then(() => {
|
||||
useNotificationStore().handleNotificationHide(D.invite.id);
|
||||
});
|
||||
toast.success(t('message.invite.response_sent'));
|
||||
return args;
|
||||
|
||||
Reference in New Issue
Block a user