Browse Source

Handle unknown contacts when checking feature mask (#719)

When sending an image to a group, if a group contact cannot be found,
then that would result in the contact being `undefined`.

Thus, in that case we may not access the `displayName` attribute.

Hopefully fixes #718.
Danilo Bargen 6 years ago
parent
commit
2b38529faa
1 changed files with 15 additions and 8 deletions
  1. 15 8
      src/services/webclient.ts

+ 15 - 8
src/services/webclient.ts

@@ -1612,8 +1612,7 @@ export class WebClientService {
                             if (this.mimeService.isAudio(mime)) {
                             if (this.mimeService.isAudio(mime)) {
                                 requiredFeature = ContactReceiverFeature.AUDIO;
                                 requiredFeature = ContactReceiverFeature.AUDIO;
                                 invalidFeatureMessage = 'error.AUDIO_MESSAGES_NOT_SUPPORTED';
                                 invalidFeatureMessage = 'error.AUDIO_MESSAGES_NOT_SUPPORTED';
-                            } else if (this.mimeService.isImage(mime)
-                                || this.mimeService.isVideo(mime)) {
+                            } else if (this.mimeService.isImage(mime) || this.mimeService.isVideo(mime)) {
                                 requiredFeature = ContactReceiverFeature.AUDIO;
                                 requiredFeature = ContactReceiverFeature.AUDIO;
                                 invalidFeatureMessage = 'error.MESSAGE_NOT_SUPPORTED';
                                 invalidFeatureMessage = 'error.MESSAGE_NOT_SUPPORTED';
                             }
                             }
@@ -1624,8 +1623,9 @@ export class WebClientService {
                         // check receiver
                         // check receiver
                         switch (receiver.type) {
                         switch (receiver.type) {
                             case 'distributionList':
                             case 'distributionList':
-                                return reject(this.$translate.instant(invalidFeatureMessage, {
-                                    receiverName: receiver.displayName}));
+                                return reject(this.$translate.instant(
+                                    invalidFeatureMessage, {receiverName: receiver.displayName},
+                                ));
                             case 'group':
                             case 'group':
                                 const unsupportedMembers = [];
                                 const unsupportedMembers = [];
                                 const group = this.groups.get(receiver.id);
                                 const group = this.groups.get(receiver.id);
@@ -1637,16 +1637,23 @@ export class WebClientService {
                                     if (identity !== this.me.id) {
                                     if (identity !== this.me.id) {
                                         // tslint:disable-next-line: no-shadowed-variable
                                         // tslint:disable-next-line: no-shadowed-variable
                                         const contact = this.contacts.get(identity);
                                         const contact = this.contacts.get(identity);
-                                        if (contact === undefined
-                                            || !hasFeature(contact, requiredFeature, this.$log)) {
+                                        if (contact === undefined) {
+                                            // This shouldn't actually happen. But if it happens, log an error
+                                            // and assume image support. It's much more likely that the contact
+                                            // can receive images (feature flag 0x01) than otherwise. And if one
+                                            // of the contacts really cannot receive images, the app will return
+                                            // an error message.
+                                            this.$log.error(`Cannot retrieve contact ${identity}`);
+                                        } else if (!hasFeature(contact, requiredFeature, this.$log)) {
                                             unsupportedMembers.push(contact.displayName);
                                             unsupportedMembers.push(contact.displayName);
                                         }
                                         }
                                     }
                                     }
                                 });
                                 });
 
 
                                 if (unsupportedMembers.length > 0) {
                                 if (unsupportedMembers.length > 0) {
-                                    return reject(this.$translate.instant(invalidFeatureMessage, {
-                                        receiverName: unsupportedMembers.join(',')}));
+                                    return reject(this.$translate.instant(
+                                        invalidFeatureMessage, {receiverName: unsupportedMembers.join(',')},
+                                    ));
                                 }
                                 }
                                 break;
                                 break;
                             case 'contact':
                             case 'contact':