Ver código fonte

Avatar change fixes

Danilo Bargen 7 anos atrás
pai
commit
bf103eeb98

+ 1 - 1
src/controller_model/avatar.ts

@@ -35,7 +35,7 @@ export class AvatarControllerModel {
                 $log.debug(this.logTag, 'loadAvatar: No receiver defined, no avatar');
                 resolve(null);
                 return;
-            } else if (receiver.avatar.high === undefined) {
+            } else if (receiver.avatar.high === undefined || receiver.avatar.high === null) {
                 $log.debug(this.logTag, 'loadAvatar: Requesting high res avatar from app');
                 webClientService.requestAvatar(receiver, true)
                     .then((data: ArrayBuffer) => resolve(data))

+ 23 - 6
src/directives/avatar.ts

@@ -46,7 +46,6 @@ export default [
 
                 this.avatarExists = () => {
                     if (this.receiver.avatar === undefined
-                        || this.receiver.avatar === null
                         || this.receiver.avatar[this.resolution] === undefined
                         || this.receiver.avatar[this.resolution] === null) {
                         return false;
@@ -64,15 +63,18 @@ export default [
                     switch (type) {
                         case 'group':
                             return highResolution ? 'img/ic_group_picture_big.png' : 'img/ic_group_t.png';
+                        case 'distributionList':
+                            return highResolution ? 'img/ic_distribution_list_t.png' : 'img/ic_distribution_list_t.png';
                         case 'contact':
                         case 'me':
+                        default:
                             return highResolution ? 'img/ic_contact_picture_big.png' : 'img/ic_contact_picture_t.png';
-                        case 'distributionList':
-                            return highResolution ? 'img/ic_distribution_list_t.png' : 'img/ic_distribution_list_t.png';
                     }
-                    return null;
                 };
 
+                /**
+                 * Convert avatar bytes to an URI.
+                 */
                 this.avatarToUri = (data: ArrayBuffer) => {
                     if (data === null || data === undefined) {
                         return '';
@@ -80,14 +82,29 @@ export default [
                     return ($filter('bufferToUrl') as (data: ArrayBuffer, mime: string) => string)(data, 'image/png');
                 };
 
+                /**
+                 * Return an avatar URI.
+                 *
+                 * This will fall back to a low resolution version or to the
+                 * default avatar if no avatar for the desired resolution could
+                 * be found.
+                 */
                 this.getAvatarUri = () => {
+                    /// If an avatar for the chosen resolution exists, convert it to an URI and return
                     if (this.avatarExists()) {
                         return this.avatarToUri(this.receiver.avatar[this.resolution]);
-                    } else if (this.highResolution
+                    }
+
+                    // Otherwise, if we requested a high res avatar but
+                    // there is only a low-res version, show that.
+                    if (this.highResolution
                         && this.receiver.avatar !== undefined
-                        && this.receiver.avatar.low !== undefined) {
+                        && this.receiver.avatar.low !== undefined
+                        && this.receiver.avatar.low !== null) {
                         return this.avatarToUri(this.receiver.avatar.low);
                     }
+
+                    // As a fallback, get the default avatar.
                     return this.getDefaultAvatarUri(this.type, this.highResolution);
                 };
 

+ 2 - 2
src/partials/messenger.receiver/me.html

@@ -9,13 +9,13 @@
 		<md-card-content>
 			<dl class="key-values">
 				<dt>Threema ID</dt>
-				<dd>{{ctrl.receiver.id}}
+				<dd>{{ ctrl.receiver.id }}
 					<eee-verification-level
 							contact="ctrl.receiver">
 					</eee-verification-level></dd>
 
 				<dt><span translate>messenger.KEY_FINGERPRINT</span></dt>
-				<dd>{{ctrl.fingerPrint}}</dd>
+				<dd>{{ ctrl.fingerPrint }}</dd>
 
 				<dt><span translate>messenger.MY_PUBLIC_NICKNAME</span></dt>
 				<dd>{{ ctrl.controllerModel.nickname || "-" }}</dd>

+ 2 - 2
src/services/battery.ts

@@ -116,7 +116,7 @@ export class BatteryStatusService {
         }
 
         const title = this.$translate.instant('common.WARNING');
-        const avatar = 'img/ic_battery_alert-64x64.png';
+        const picture = 'img/ic_battery_alert-64x64.png';
         let tag: string;
         let body: string;
         if (level === 'low') {
@@ -128,7 +128,7 @@ export class BatteryStatusService {
             body = this.$translate.instant('battery.LEVEL_CRITICAL', { percent: this.percent });
             this.notificationService.hideNotification('battery-low');
         }
-        this.notificationService.showNotification(tag, title, body, avatar, undefined, true, true);
+        this.notificationService.showNotification(tag, title, body, picture, undefined, true, true);
     }
 
     public toString(): string {