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:
+18
-87
@@ -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,27 +188,13 @@ const notificationReq = {
|
|||||||
{
|
{
|
||||||
method: 'PUT'
|
method: 'PUT'
|
||||||
}
|
}
|
||||||
)
|
).then((json) => {
|
||||||
.then((json) => {
|
const args = {
|
||||||
const args = {
|
json,
|
||||||
json,
|
params
|
||||||
params
|
};
|
||||||
};
|
return args;
|
||||||
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,
|
json,
|
||||||
params
|
params
|
||||||
};
|
};
|
||||||
getNotificationStore().handleNotificationHide(
|
|
||||||
params.notificationId
|
|
||||||
);
|
|
||||||
return args;
|
return args;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -289,24 +260,13 @@ 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
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hideNotificationV2(notificationId) {
|
hideNotificationV2(notificationId) {
|
||||||
@@ -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,9 +1972,18 @@
|
|||||||
});
|
});
|
||||||
handleSendFriendRequest(args);
|
handleSendFriendRequest(args);
|
||||||
} else {
|
} else {
|
||||||
notificationRequest.acceptFriendRequestNotification({
|
notificationRequest
|
||||||
notificationId: key
|
.acceptFriendRequestNotification({
|
||||||
});
|
notificationId: key
|
||||||
|
})
|
||||||
|
.then((args) => {
|
||||||
|
useNotificationStore().handleNotificationAccept(args);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err && err.message && err.message.includes('404')) {
|
||||||
|
useNotificationStore().handleNotificationHide(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Decline Friend Request':
|
case 'Decline Friend Request':
|
||||||
@@ -1984,9 +1994,13 @@
|
|||||||
});
|
});
|
||||||
handleCancelFriendRequest(args);
|
handleCancelFriendRequest(args);
|
||||||
} else {
|
} else {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: key
|
.hideNotification({
|
||||||
});
|
notificationId: key
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
useNotificationStore().handleNotificationHide(key);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Cancel Friend Request': {
|
case 'Cancel Friend Request': {
|
||||||
|
|||||||
@@ -358,9 +358,13 @@ export const useNotificationStore = defineStore('Notification', () => {
|
|||||||
});
|
});
|
||||||
AppDebug.errorNoty.show();
|
AppDebug.errorNoty.show();
|
||||||
console.log(text);
|
console.log(text);
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: ref.id
|
.hideNotification({
|
||||||
});
|
notificationId: ref.id
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
handleNotificationHide(ref.id);
|
||||||
|
});
|
||||||
return _args;
|
return _args;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -1173,9 +1177,18 @@ export const useNotificationStore = defineStore('Notification', () => {
|
|||||||
})
|
})
|
||||||
.then(({ ok }) => {
|
.then(({ ok }) => {
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
notificationRequest.acceptFriendRequestNotification({
|
notificationRequest
|
||||||
notificationId: row.id
|
.acceptFriendRequestNotification({
|
||||||
});
|
notificationId: row.id
|
||||||
|
})
|
||||||
|
.then((args) => {
|
||||||
|
handleNotificationAccept(args);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err && err.message && err.message.includes('404')) {
|
||||||
|
handleNotificationHide(row.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
@@ -1188,9 +1201,13 @@ export const useNotificationStore = defineStore('Notification', () => {
|
|||||||
);
|
);
|
||||||
handleNotificationHide(row.id);
|
handleNotificationHide(row.id);
|
||||||
} else {
|
} else {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: row.id
|
.hideNotification({
|
||||||
});
|
notificationId: row.id
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
handleNotificationHide(row.id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1237,9 +1254,13 @@ export const useNotificationStore = defineStore('Notification', () => {
|
|||||||
)
|
)
|
||||||
.then((_args) => {
|
.then((_args) => {
|
||||||
toast(t('message.invite.sent'));
|
toast(t('message.invite.sent'));
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: row.id
|
.hideNotification({
|
||||||
});
|
notificationId: row.id
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
handleNotificationHide(row.id);
|
||||||
|
});
|
||||||
return _args;
|
return _args;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1257,15 +1278,21 @@ export const useNotificationStore = defineStore('Notification', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const params = { notificationId, responseType, responseData };
|
const params = { notificationId, responseType, responseData };
|
||||||
notificationRequest.sendNotificationResponse(params).then((args) => {
|
notificationRequest
|
||||||
console.log('Notification response', args);
|
.sendNotificationResponse(params)
|
||||||
if (!args.json) return;
|
.then((args) => {
|
||||||
handleNotificationV2Hide(notificationId);
|
console.log('Notification response', args);
|
||||||
new Noty({
|
if (!args.json) return;
|
||||||
type: 'success',
|
handleNotificationV2Hide(notificationId);
|
||||||
text: escapeTag(args.json)
|
new Noty({
|
||||||
}).show();
|
type: 'success',
|
||||||
});
|
text: escapeTag(args.json)
|
||||||
|
}).show();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
handleNotificationV2Hide(notificationId);
|
||||||
|
notificationRequest.hideNotificationV2(notificationId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteNotificationLog(row) {
|
function deleteNotificationLog(row) {
|
||||||
|
|||||||
@@ -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,9 +101,13 @@
|
|||||||
toast.error(t('message.error'));
|
toast.error(t('message.error'));
|
||||||
})
|
})
|
||||||
.then((args) => {
|
.then((args) => {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: I.invite.id
|
.hideNotification({
|
||||||
});
|
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,9 +122,13 @@
|
|||||||
toast.error(t('message.error'));
|
toast.error(t('message.error'));
|
||||||
})
|
})
|
||||||
.then((args) => {
|
.then((args) => {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: I.invite.id
|
.hideNotification({
|
||||||
});
|
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,9 +65,13 @@
|
|||||||
toast.error(t('message.error'));
|
toast.error(t('message.error'));
|
||||||
})
|
})
|
||||||
.then((args) => {
|
.then((args) => {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: D.invite.id
|
.hideNotification({
|
||||||
});
|
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,9 +86,13 @@
|
|||||||
toast.error(t('message.error'));
|
toast.error(t('message.error'));
|
||||||
})
|
})
|
||||||
.then((args) => {
|
.then((args) => {
|
||||||
notificationRequest.hideNotification({
|
notificationRequest
|
||||||
notificationId: D.invite.id
|
.hideNotification({
|
||||||
});
|
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;
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user