Quellcode durchsuchen

Merge pull request #9184 from jitsi/tavram/invite-types

fix(invite) fix notifications for phone invites
j8
Avram Tudor vor 4 Jahren
Ursprung
Commit
6e91665987
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 9
- 8
react/features/invite/actions.any.js Datei anzeigen

@@ -15,6 +15,7 @@ import {
15 15
     UPDATE_DIAL_IN_NUMBERS_FAILED,
16 16
     UPDATE_DIAL_IN_NUMBERS_SUCCESS
17 17
 } from './actionTypes';
18
+import { INVITE_TYPES } from './constants';
18 19
 import {
19 20
     getDialInConferenceID,
20 21
     getDialInNumbers,
@@ -76,7 +77,7 @@ export function invite(
76 77
         if (showCalleeInfo
77 78
                 && !calleeInfoVisible
78 79
                 && invitees.length === 1
79
-                && invitees[0].type === 'user'
80
+                && invitees[0].type === INVITE_TYPES.USER
80 81
                 && participants.length === 1) {
81 82
             dispatch(setCalleeInfoVisible(true, invitees[0]));
82 83
         }
@@ -110,7 +111,7 @@ export function invite(
110 111
 
111 112
         // First create all promises for dialing out.
112 113
         const phoneNumbers
113
-            = invitesLeftToSend.filter(({ type }) => type === 'phone');
114
+            = invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.PHONE);
114 115
 
115 116
         // For each number, dial out. On success, remove the number from
116 117
         // {@link invitesLeftToSend}.
@@ -131,7 +132,7 @@ export function invite(
131 132
 
132 133
         const usersAndRooms
133 134
             = invitesLeftToSend.filter(
134
-                ({ type }) => type === 'user' || type === 'room');
135
+                ({ type }) => [ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
135 136
 
136 137
         if (usersAndRooms.length) {
137 138
             // Send a request to invite all the rooms and users. On success,
@@ -146,7 +147,7 @@ export function invite(
146 147
                 .then(() => {
147 148
                     invitesLeftToSend
148 149
                         = invitesLeftToSend.filter(
149
-                            ({ type }) => type !== 'user' && type !== 'room');
150
+                            ({ type }) => ![ INVITE_TYPES.USER, INVITE_TYPES.ROOM ].includes(type));
150 151
                 })
151 152
                 .catch(error => {
152 153
                     dispatch(setCalleeInfoVisible(false));
@@ -159,17 +160,17 @@ export function invite(
159 160
         // Sipgw calls are fire and forget. Invite them to the conference, then
160 161
         // immediately remove them from invitesLeftToSend.
161 162
         const vrooms
162
-            = invitesLeftToSend.filter(({ type }) => type === 'videosipgw');
163
+            = invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.VIDEO_ROOM);
163 164
 
164 165
         conference
165 166
             && vrooms.length > 0
166 167
             && dispatch(inviteVideoRooms(conference, vrooms));
167 168
 
168 169
         invitesLeftToSend
169
-            = invitesLeftToSend.filter(({ type }) => type !== 'videosipgw');
170
+            = invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.VIDEO_ROOM);
170 171
 
171 172
         const sipEndpoints
172
-            = invitesLeftToSend.filter(({ type }) => type === 'sip');
173
+            = invitesLeftToSend.filter(({ type }) => type === INVITE_TYPES.SIP);
173 174
 
174 175
         conference && inviteSipEndpoints(
175 176
             sipEndpoints,
@@ -182,7 +183,7 @@ export function invite(
182 183
         );
183 184
 
184 185
         invitesLeftToSend
185
-            = invitesLeftToSend.filter(({ type }) => type !== 'sip');
186
+            = invitesLeftToSend.filter(({ type }) => type !== INVITE_TYPES.SIP);
186 187
 
187 188
         return (
188 189
             Promise.all(allInvitePromises)

+ 23
- 4
react/features/invite/components/add-people-dialog/AbstractAddPeopleDialog.js Datei anzeigen

@@ -8,6 +8,7 @@ import {
8 8
     showNotification
9 9
 } from '../../../notifications';
10 10
 import { invite } from '../../actions';
11
+import { INVITE_TYPES } from '../../constants';
11 12
 import {
12 13
     getInviteResultsForQuery,
13 14
     getInviteTypeCounts,
@@ -100,6 +101,24 @@ export default class AbstractAddPeopleDialog<P: Props, S: State>
100 101
         this._query = this._query.bind(this);
101 102
     }
102 103
 
104
+    /**
105
+     * Retrieves the notification display name for the invitee.
106
+     *
107
+     * @param {Object} invitee - The invitee object.
108
+     * @returns {string}
109
+     */
110
+    _getDisplayName(invitee) {
111
+        if (invitee.type === INVITE_TYPES.PHONE) {
112
+            return invitee.number;
113
+        }
114
+
115
+        if (invitee.type === INVITE_TYPES.SIP) {
116
+            return invitee.address;
117
+        }
118
+
119
+        return invitee.name;
120
+    }
121
+
103 122
     /**
104 123
      * Invite people and numbers to the conference. The logic works by inviting
105 124
      * numbers, people/rooms, sip endpoints and videosipgw in parallel. All invitees are
@@ -160,7 +179,7 @@ export default class AbstractAddPeopleDialog<P: Props, S: State>
160 179
                     if (invitedCount >= 3) {
161 180
                         notificationProps = {
162 181
                             titleArguments: {
163
-                                name: invitees[0].name || invitees[0].address,
182
+                                name: this._getDisplayName(invitees[0]),
164 183
                                 count: invitedCount - 1
165 184
                             },
166 185
                             titleKey: 'notify.invitedThreePlusMembers'
@@ -168,15 +187,15 @@ export default class AbstractAddPeopleDialog<P: Props, S: State>
168 187
                     } else if (invitedCount === 2) {
169 188
                         notificationProps = {
170 189
                             titleArguments: {
171
-                                first: invitees[0].name || invitees[0].address,
172
-                                second: invitees[1].name || invitees[1].address
190
+                                first: this._getDisplayName(invitees[0]),
191
+                                second: this._getDisplayName(invitees[1])
173 192
                             },
174 193
                             titleKey: 'notify.invitedTwoMembers'
175 194
                         };
176 195
                     } else if (invitedCount) {
177 196
                         notificationProps = {
178 197
                             titleArguments: {
179
-                                name: invitees[0].name || invitees[0].address
198
+                                name: this._getDisplayName(invitees[0])
180 199
                             },
181 200
                             titleKey: 'notify.invitedOneMember'
182 201
                         };

+ 7
- 7
react/features/invite/components/add-people-dialog/native/AddPeopleDialog.js Datei anzeigen

@@ -31,7 +31,7 @@ import {
31 31
 } from '../../../../base/react';
32 32
 import { connect } from '../../../../base/redux';
33 33
 import { beginShareRoom } from '../../../../share-room';
34
-import { ADD_PEOPLE_DIALOG_VIEW_ID } from '../../../constants';
34
+import { ADD_PEOPLE_DIALOG_VIEW_ID, INVITE_TYPES } from '../../../constants';
35 35
 import AbstractAddPeopleDialog, {
36 36
     type Props as AbstractProps,
37 37
     type State as AbstractState,
@@ -242,13 +242,13 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
242 242
         const { item } = flatListItem;
243 243
 
244 244
         switch (item.type) {
245
-        case 'phone':
245
+        case INVITE_TYPES.PHONE:
246 246
             return {
247 247
                 avatar: IconPhone,
248 248
                 key: item.number,
249 249
                 title: item.number
250 250
             };
251
-        case 'user':
251
+        case INVITE_TYPES.USER:
252 252
             return {
253 253
                 avatar: item.avatar,
254 254
                 key: item.id || item.user_id,
@@ -273,7 +273,7 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
273 273
      * @returns {string}
274 274
      */
275 275
     _keyExtractor(item) {
276
-        return item.type === 'user' ? item.id || item.user_id : item.number;
276
+        return item.type === INVITE_TYPES.USER ? item.id || item.user_id : item.number;
277 277
     }
278 278
 
279 279
     _onClearField: () => void
@@ -340,7 +340,7 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
340 340
     _onPressItem(item) {
341 341
         return () => {
342 342
             const { inviteItems } = this.state;
343
-            const finderKey = item.type === 'phone' ? 'number' : 'user_id';
343
+            const finderKey = item.type === INVITE_TYPES.PHONE ? 'number' : 'user_id';
344 344
 
345 345
             if (inviteItems.find(
346 346
                     _.matchesProperty(finderKey, item[finderKey]))) {
@@ -504,10 +504,10 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
504 504
         }
505 505
 
506 506
         switch (item.type) {
507
-        case 'phone':
507
+        case INVITE_TYPES.PHONE:
508 508
             selected = inviteItems.find(_.matchesProperty('number', item.number));
509 509
             break;
510
-        case 'user':
510
+        case INVITE_TYPES.USER:
511 511
             selected = item.id
512 512
                 ? inviteItems.find(_.matchesProperty('id', item.id))
513 513
                 : inviteItems.find(_.matchesProperty('user_id', item.user_id));

+ 6
- 5
react/features/invite/components/add-people-dialog/web/InviteContactsForm.js Datei anzeigen

@@ -12,6 +12,7 @@ import { MultiSelectAutocomplete } from '../../../../base/react';
12 12
 import { connect } from '../../../../base/redux';
13 13
 import { isVpaasMeeting } from '../../../../billing-counter/functions';
14 14
 import { hideAddPeopleDialog } from '../../../actions';
15
+import { INVITE_TYPES } from '../../../constants';
15 16
 import AbstractAddPeopleDialog, {
16 17
     type Props as AbstractProps,
17 18
     type State,
@@ -181,7 +182,7 @@ class InviteContactsForm extends AbstractAddPeopleDialog<Props, State> {
181 182
      * @returns {Object} The item to display as selected in the input.
182 183
      */
183 184
     _onItemSelected(item) {
184
-        if (item.item.type === 'phone') {
185
+        if (item.item.type === INVITE_TYPES.PHONE) {
185 186
             item.content = item.item.number;
186 187
         }
187 188
 
@@ -285,7 +286,7 @@ class InviteContactsForm extends AbstractAddPeopleDialog<Props, State> {
285 286
      */
286 287
     _parseQueryResults(response = []) {
287 288
         const { t, _dialOutEnabled } = this.props;
288
-        const users = response.filter(item => item.type !== 'phone' && item.type !== 'sip');
289
+        const users = response.filter(item => item.type === INVITE_TYPES.USER);
289 290
         const userDisplayItems = [];
290 291
 
291 292
         for (const user of users) {
@@ -309,7 +310,7 @@ class InviteContactsForm extends AbstractAddPeopleDialog<Props, State> {
309 310
                     content: `${phone} (${name})`,
310 311
                     elemBefore: elemAvatar,
311 312
                     item: {
312
-                        type: 'phone',
313
+                        type: INVITE_TYPES.PHONE,
313 314
                         number: phone
314 315
                     },
315 316
                     tag: {
@@ -320,7 +321,7 @@ class InviteContactsForm extends AbstractAddPeopleDialog<Props, State> {
320 321
             }
321 322
         }
322 323
 
323
-        const numbers = response.filter(item => item.type === 'phone');
324
+        const numbers = response.filter(item => item.type === INVITE_TYPES.PHONE);
324 325
         const telephoneIcon = this._renderTelephoneIcon();
325 326
 
326 327
         const numberDisplayItems = numbers.map(number => {
@@ -349,7 +350,7 @@ class InviteContactsForm extends AbstractAddPeopleDialog<Props, State> {
349 350
         });
350 351
 
351 352
 
352
-        const sipAddresses = response.filter(item => item.type === 'sip');
353
+        const sipAddresses = response.filter(item => item.type === INVITE_TYPES.SIP);
353 354
 
354 355
         const sipDisplayItems = sipAddresses.map(sip => {
355 356
             return {

+ 11
- 0
react/features/invite/constants.js Datei anzeigen

@@ -48,3 +48,14 @@ export const OUTGOING_CALL_START_SOUND_ID = 'OUTGOING_CALL_START_SOUND_ID';
48 48
  */
49 49
 // eslint-disable-next-line max-len
50 50
 export const SIP_ADDRESS_REGEX = /^[a-zA-Z]+(?:([^\s>:@]+)(?::([^\s@>]+))?@)?([\w\-.]+)(?::(\d+))?((?:;[^\s=?>;]+(?:=[^\s?;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
51
+
52
+/**
53
+ * Different invite types mapping
54
+ */
55
+export const INVITE_TYPES = {
56
+    PHONE: 'phone',
57
+    ROOM: 'room',
58
+    SIP: 'sip',
59
+    USER: 'user',
60
+    VIDEO_ROOM: 'videosipgw'
61
+};

+ 4
- 4
react/features/invite/functions.js Datei anzeigen

@@ -10,7 +10,7 @@ import { toState } from '../base/redux';
10 10
 import { doGetJSON, parseURIString } from '../base/util';
11 11
 import { isVpaasMeeting } from '../billing-counter/functions';
12 12
 
13
-import { SIP_ADDRESS_REGEX } from './constants';
13
+import { INVITE_TYPES, SIP_ADDRESS_REGEX } from './constants';
14 14
 import logger from './logger';
15 15
 
16 16
 declare var $: Function;
@@ -227,13 +227,13 @@ export function getInviteResultsForQuery(
227 227
              * the phone number can then be cleaned up when convenient.
228 228
              */
229 229
             const hasPhoneResult
230
-                = peopleResults.find(result => result.type === 'phone');
230
+                = peopleResults.find(result => result.type === INVITE_TYPES.PHONE);
231 231
 
232 232
             if (!hasPhoneResult && typeof phoneResults.allow === 'boolean') {
233 233
                 results.push({
234 234
                     allowed: phoneResults.allow,
235 235
                     country: phoneResults.country,
236
-                    type: 'phone',
236
+                    type: INVITE_TYPES.PHONE,
237 237
                     number: phoneResults.phone,
238 238
                     originalEntry: text,
239 239
                     showCountryCodeReminder: !hasCountryCode
@@ -242,7 +242,7 @@ export function getInviteResultsForQuery(
242 242
 
243 243
             if (sipInviteEnabled && isASipAddress(text)) {
244 244
                 results.push({
245
-                    type: 'sip',
245
+                    type: INVITE_TYPES.SIP,
246 246
                     address: text
247 247
                 });
248 248
             }

Laden…
Abbrechen
Speichern