From 1f239b00dd85c2a6b98ed7692ffa12168033d55f Mon Sep 17 00:00:00 2001 From: Nikita Konev Date: Tue, 24 Dec 2024 12:30:36 +0300 Subject: [PATCH] userStatusRequestMixin --- frontend/src/ChatList.vue | 40 ++++++------------- frontend/src/ChatParticipantsModal.vue | 8 ++-- frontend/src/UserList.vue | 23 +++-------- frontend/src/UserProfile.vue | 22 +++------- frontend/src/mixins/userStatusRequestMixin.js | 23 +++++++++++ 5 files changed, 51 insertions(+), 65 deletions(-) create mode 100644 frontend/src/mixins/userStatusRequestMixin.js diff --git a/frontend/src/ChatList.vue b/frontend/src/ChatList.vue index b41c7088d..df03ef5d3 100644 --- a/frontend/src/ChatList.vue +++ b/frontend/src/ChatList.vue @@ -127,6 +127,7 @@ import { setTopChatPosition } from "@/store/localStore.js"; import onFocusMixin from "@/mixins/onFocusMixin.js"; +import userStatusRequestMixin from "@/mixins/userStatusRequestMixin.js"; const PAGE_SIZE = 40; const SCROLLING_THRESHHOLD = 200; // px @@ -140,6 +141,7 @@ export default { heightMixin(), searchString(SEARCH_MODE_CHATS), userStatusMixin('tetATetInChatList'), + userStatusRequestMixin(), onFocusMixin(), ], props:['embedded'], @@ -258,7 +260,9 @@ export default { } this.performMarking(); - this.requestInVideo(); + + this.requestStatuses(); + return Promise.resolve(true) }).finally(()=>{ this.chatStore.decrementProgressCount(); @@ -655,21 +659,16 @@ export default { } return obj; }, - + requestStatuses() { + this.$nextTick(()=> { + const userIds = this.tetAtetParticipants; + const joined = userIds.join(","); + this.triggerUsesStatusesEvents(joined, this.requestAbortController.signal); + }) + }, onFocus() { if (this.chatStore.currentUser && this.items) { - const list = this.items.filter(item => item.tetATet).flatMap(item => item.participantIds); - const uniqueUserIds = [...new Set(list)]; - const joined = uniqueUserIds.join(","); - axios.put(`/api/aaa/user/request-for-online`, null, { - params: { - userId: joined - }, - signal: this.requestAbortController.signal - }).then(()=>{ - this.requestInVideo(); - }); - + this.requestStatuses(); if (this.isScrolledToTop()) { const topNElements = this.items.slice(0, PAGE_SIZE); @@ -690,19 +689,6 @@ export default { } } }, - requestInVideo() { - this.$nextTick(()=>{ - const userIds = this.tetAtetParticipants; - const joined = userIds.join(","); - - axios.put("/api/video/user/request-in-video-status", null, { - params: { - userId: joined - }, - signal: this.requestAbortController.signal - }); - }) - }, hasItems() { return !!this.items?.length }, diff --git a/frontend/src/ChatParticipantsModal.vue b/frontend/src/ChatParticipantsModal.vue index 10fa8b80f..1d82888a9 100644 --- a/frontend/src/ChatParticipantsModal.vue +++ b/frontend/src/ChatParticipantsModal.vue @@ -181,10 +181,12 @@ import ChatParticipantsContextMenu from "@/ChatParticipantsContextMenu.vue"; import ChatListContextMenu from "@/ChatListContextMenu.vue"; import pageableModalMixin, {firstPage, pageSize} from "@/mixins/pageableModalMixin.js"; + import userStatusRequestMixin from "@/mixins/userStatusRequestMixin.js"; export default { mixins: [ userStatusMixin('chatParticipants'), + userStatusRequestMixin(), pageableModalMixin(), ], data () { @@ -226,11 +228,7 @@ const userIds = this.itemsDto?.items.map(item => item.id); const joined = userIds.join(","); - axios.put("/api/video/user/request-in-video-status", null, { - params: { - userId: joined - }, - }); + this.triggerUsesStatusesEvents(joined); }) }, changeChatAdmin(item) { diff --git a/frontend/src/UserList.vue b/frontend/src/UserList.vue index 956724686..ac1d12b3f 100644 --- a/frontend/src/UserList.vue +++ b/frontend/src/UserList.vue @@ -193,6 +193,7 @@ import { import UserListContextMenu from "@/UserListContextMenu.vue"; import UserRoleModal from "@/UserRoleModal.vue"; import onFocusMixin from "@/mixins/onFocusMixin.js"; +import userStatusRequestMixin from "@/mixins/userStatusRequestMixin.js"; const PAGE_SIZE = 40; const SCROLLING_THRESHHOLD = 200; // px @@ -210,6 +211,7 @@ export default { heightMixin(), searchString(SEARCH_MODE_USERS), userStatusMixin('userStatusInUserList'), // another subscription + userStatusRequestMixin(), onFocusMixin(), ], data() { @@ -325,7 +327,7 @@ export default { this.graphQlUserStatusSubscribe(); this.performMarking(); - this.requestInVideo(); + this.requestStatuses(); return Promise.resolve(true) }).finally(()=>{ this.chatStore.decrementProgressCount(); @@ -630,32 +632,19 @@ export default { return } - this.requestInVideo(); + this.requestStatuses(); } }, onWsRestoredRefresh() { this.saveLastVisibleElement(); this.initializeHashVariablesAndReloadItems(); }, - requestInVideo() { + requestStatuses() { this.$nextTick(()=>{ const list = this.items.map(item => item.id); const joined = list.join(","); - axios.put("/api/video/user/request-in-video-status", null, { - params: { - userId: joined - }, - signal: this.requestAbortController.signal - }); - - axios.put(`/api/aaa/user/request-for-online`, null, { - params: { - userId: joined - }, - signal: this.requestAbortController.signal - }) - + this.triggerUsesStatusesEvents(joined, this.requestAbortController.signal); }) }, getMaximumItemId() { diff --git a/frontend/src/UserProfile.vue b/frontend/src/UserProfile.vue index 205f77e80..5da1c65a9 100644 --- a/frontend/src/UserProfile.vue +++ b/frontend/src/UserProfile.vue @@ -172,6 +172,7 @@ import graphqlSubscriptionMixin from "@/mixins/graphqlSubscriptionMixin.js"; import UserListContextMenu from "@/UserListContextMenu.vue"; import UserRoleModal from "@/UserRoleModal.vue"; import onFocusMixin from "@/mixins/onFocusMixin.js"; +import userStatusRequestMixin from "@/mixins/userStatusRequestMixin.js"; export default { components: { @@ -180,6 +181,7 @@ export default { }, mixins: [ userStatusMixin('userStatusInUserProfile'), // another subscription + userStatusRequestMixin(), onFocusMixin(), ], data() { @@ -351,7 +353,7 @@ export default { this.loadUser(); this.graphQlUserStatusSubscribe(); this.userProfileEventsSubscription.graphQlSubscribe(); - this.requestInVideo(); + this.requestStatuses(); }, canDrawUsers() { return !!this.chatStore.currentUser @@ -387,24 +389,12 @@ export default { }, onFocus() { if (this.chatStore.currentUser) { - axios.put(`/api/aaa/user/request-for-online`, null, { - params: { - userId: this.userId - }, - signal: this.requestAbortController.signal - }).then(()=>{ - this.requestInVideo(); - }) + this.requestStatuses(); } }, - requestInVideo() { + requestStatuses() { this.$nextTick(()=>{ - axios.put("/api/video/user/request-in-video-status", null, { - params: { - userId: this.userId - }, - signal: this.requestAbortController.signal - }); + this.triggerUsesStatusesEvents(this.userId, this.requestAbortController.signal); }) }, onShowContextMenu(e) { diff --git a/frontend/src/mixins/userStatusRequestMixin.js b/frontend/src/mixins/userStatusRequestMixin.js new file mode 100644 index 000000000..c3ca6bf9f --- /dev/null +++ b/frontend/src/mixins/userStatusRequestMixin.js @@ -0,0 +1,23 @@ +import axios from "axios"; + +export default () => { + return { + methods: { + triggerUsesStatusesEvents(userIdsJoined, signal) { + axios.put(`/api/aaa/user/request-for-online`, null, { + params: { + userId: userIdsJoined + }, + signal: signal + }).then(()=>{ + axios.put("/api/video/user/request-in-video-status", null, { + params: { + userId: userIdsJoined + }, + signal: signal + }); + }) + } + } + } +} \ No newline at end of file