From 6c84d0d66865ae00850e4ddd7f1d3af13aa4fb9d Mon Sep 17 00:00:00 2001 From: JelianRadoev Date: Fri, 5 Jun 2020 12:36:01 +0300 Subject: [PATCH 1/4] NY-10135 Admin of the group gets host abilities --- .../resource/audioVideo/sagas/AudioVideo.saga.js | 3 +++ .../resource/roomlist/modules/RoomList.module.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js index 85c7d7d1c..c228954aa 100644 --- a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js +++ b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js @@ -120,6 +120,9 @@ function* callUpdate(action) { try { const phoneId = yield select(profileSelectors.getPhoneId); isAdmin = payload.ownerAccountId === phoneId; + if (!isAdmin && callData && callData.chatRoomId) { + isAdmin = yield select(roomListSelectors.isAdminInGroup, callData.chatRoomId, phoneId); + } } catch (e) { } if (payload.replaceCallId) { const clientId = payload.deviceId || callData.clientId || null; diff --git a/src/core/resource/roomlist/modules/RoomList.module.js b/src/core/resource/roomlist/modules/RoomList.module.js index a9204f2d1..a284c5b4e 100644 --- a/src/core/resource/roomlist/modules/RoomList.module.js +++ b/src/core/resource/roomlist/modules/RoomList.module.js @@ -254,7 +254,18 @@ const getUnreadCountInGroup = (state, groupId) => { } return 0; -} +}; + +const isAdminInGroup = (state, groupId, phoneId) => { + const group = getRoomById(state, groupId); + if (group && group.admins) { + const adminMember = group.admins[phoneId]; + if (adminMember) { + return true; + } + } + return false; +}; const pullReceivedRoomList = ({ rosters = [] }) => { const data = {}; @@ -816,6 +827,7 @@ const roomListSelectors = { getTotalUnreadMentionsCount, getTotalUnreadCount, getGroupsByRosterIdRaw, + isAdminInGroup, }; export default roomList; -- GitLab From 3ec8cca71e9e1093e0881ee9f9163c5884229a44 Mon Sep 17 00:00:00 2001 From: JelianRadoev Date: Fri, 5 Jun 2020 15:15:23 +0300 Subject: [PATCH 2/4] NY-10135 Change Call Admin Status when you have been promoted/demoted from group --- .../audioVideo/modules/AudioVideo.module.js | 8 ++++- .../resource/roomlist/sagas/Rooms.saga.js | 36 +++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/core/resource/audioVideo/modules/AudioVideo.module.js b/src/core/resource/audioVideo/modules/AudioVideo.module.js index a55a6cad4..d9a1d09b4 100644 --- a/src/core/resource/audioVideo/modules/AudioVideo.module.js +++ b/src/core/resource/audioVideo/modules/AudioVideo.module.js @@ -58,6 +58,7 @@ const updateRoomCallInfo = createAction('AUDIO_VIDEO_UPDATE_ROOM_INFO'); const checkRoomCallInfo = createAction('AUDIO_VIDEO_CHECK_ROOM_INFO'); // payload: true / false const requestMinimize = createAction('AUDIO_VIDEO_REQUEST_MINIMIZE'); +const updateAdminStatusCurrentUser = createAction('AUDIO_VIDEO_UPDATE_ADMIN_STATUS_CURRENT_USER'); const initHandlerBase = (state, payload) => Object.assign( {}, @@ -183,10 +184,13 @@ const handleRequestMinimise = (state, payload) => { if (!state.conferenceId) { return state; } - return { ...state, minimizeRequested: !!payload }; + return { ...state, minimizeRequested: !!payload }; }; +const updateAdminStatusCurrentUserHandler = (state, payload) => { + return { ...state, isAdmin: payload.isAdmin }; +}; const audioVideo = createReducer((on) => { on(incomingCall, initIncomingCall); @@ -205,6 +209,7 @@ const audioVideo = createReducer((on) => { on(startP2pCallInit, initHandlerBase); on(updateRoomCallInfo, initUpdateRoomInfo); on(requestMinimize, handleRequestMinimise); + on(updateAdminStatusCurrentUser, updateAdminStatusCurrentUserHandler); }, initialState); const getCallData = (state, conferenceId) => { @@ -357,6 +362,7 @@ const audioVideoActions = { updateRoomCallInfo, checkRoomCallInfo, requestMinimize, + updateAdminStatusCurrentUser, }; const audioVideoSelectors = { diff --git a/src/core/resource/roomlist/sagas/Rooms.saga.js b/src/core/resource/roomlist/sagas/Rooms.saga.js index 99c0b89bc..377ab2edb 100644 --- a/src/core/resource/roomlist/sagas/Rooms.saga.js +++ b/src/core/resource/roomlist/sagas/Rooms.saga.js @@ -653,18 +653,22 @@ function* responseIncommingRoomMember() { const addMembersJobKey = `room-add-members-${groupId}`; const updateStatusJobKey = `room-update-member-status-${groupId}`; const isInCall = yield select(audioVideoSelectors.hasActiveCall); + const callData = yield select(audioVideoSelectors.getCallData); let isSoundsEnabled = allAppSound && notifications && show; if (isInCall) { isSoundsEnabled = isSoundsEnabled && !muteUnmuteDuringCallNotifications; } + const shouldShowNotifications = allGroupEventsNotifications && notifications && show; + const isCallInGroup = callData && callData.chatRoomId === groupId; + /** * The response status from the server for adding new members/promoting members to admins/demoting admins to members * is the same for all three actions so some magic have to be done in order to deduce for which action is the response * MAGIC START */ - if (allGroupEventsNotifications && notifications && show) { + if (shouldShowNotifications || isCallInGroup) { const isAddMembersJob = yield call(getQueueJob, addMembersJobKey); const isUpdateStatusJob = yield call(getQueueJob, updateStatusJobKey); const type = notificationTypes.GROUP_EVENT_MESSAGE; @@ -690,10 +694,16 @@ function* responseIncommingRoomMember() { } if (isMyPromotion) { - const body = i18n - .t('groupsSystemMessages.adminPromotedYou') - .replace('$1', groupName); - showNotification(body, type, redirectLink, null, null, callback); + if (shouldShowNotifications) { + const body = i18n + .t('groupsSystemMessages.adminPromotedYou') + .replace('$1', groupName); + showNotification(body, type, redirectLink, null, null, callback); + } + + if (isCallInGroup) { + yield put(audioVideoActions.updateAdminStatusCurrentUser({ isAdmin: true })); + } } } else { const groupBeforeUpdate = yield select(roomListSelectors.getRoomById, groupId); @@ -740,13 +750,19 @@ function* responseIncommingRoomMember() { } if (isDemoting && isAboutMe) { - const body = i18n - .t('groupsSystemMessages.adminDemotedYou') - .replace('$1', groupName); - showNotification(body, type, redirectLink, null, null, callback); + if (shouldShowNotifications) { + const body = i18n + .t('groupsSystemMessages.adminDemotedYou') + .replace('$1', groupName); + showNotification(body, type, redirectLink, null, null, callback); + } + + if (isCallInGroup) { + yield put(audioVideoActions.updateAdminStatusCurrentUser({ isAdmin: false })); + } } - if (isAdding) { + if (isAdding && shouldShowNotifications) { let body = ''; if (isAboutMe) { -- GitLab From b0cbf69fac242e4bc33fa198a11348785366b6b4 Mon Sep 17 00:00:00 2001 From: JelianRadoev Date: Fri, 5 Jun 2020 15:57:50 +0300 Subject: [PATCH 3/4] Check for group admin in update call fix --- src/core/resource/audioVideo/sagas/AudioVideo.saga.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js index c228954aa..327a8396f 100644 --- a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js +++ b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js @@ -120,8 +120,9 @@ function* callUpdate(action) { try { const phoneId = yield select(profileSelectors.getPhoneId); isAdmin = payload.ownerAccountId === phoneId; - if (!isAdmin && callData && callData.chatRoomId) { - isAdmin = yield select(roomListSelectors.isAdminInGroup, callData.chatRoomId, phoneId); + if (!isAdmin && (payload.chatRoomId || (callData && callData.chatRoomId))) { + const roomId = payload.chatRoomId || allData.chatRoomId; + isAdmin = yield select(roomListSelectors.isAdminInGroup, roomId, phoneId); } } catch (e) { } if (payload.replaceCallId) { -- GitLab From f03f92d5ea522f62ce82450dee5f978c8cc8a0d0 Mon Sep 17 00:00:00 2001 From: JelianRadoev Date: Fri, 5 Jun 2020 16:00:01 +0300 Subject: [PATCH 4/4] fix typo --- src/core/resource/audioVideo/sagas/AudioVideo.saga.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js index 327a8396f..ddd14bf92 100644 --- a/src/core/resource/audioVideo/sagas/AudioVideo.saga.js +++ b/src/core/resource/audioVideo/sagas/AudioVideo.saga.js @@ -121,7 +121,7 @@ function* callUpdate(action) { const phoneId = yield select(profileSelectors.getPhoneId); isAdmin = payload.ownerAccountId === phoneId; if (!isAdmin && (payload.chatRoomId || (callData && callData.chatRoomId))) { - const roomId = payload.chatRoomId || allData.chatRoomId; + const roomId = payload.chatRoomId || callData.chatRoomId; isAdmin = yield select(roomListSelectors.isAdminInGroup, roomId, phoneId); } } catch (e) { } -- GitLab