From 9fab329a70df8a9eacc52aa6f2219e30673d64d9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 13 Aug 2015 17:07:34 +0100 Subject: [PATCH] Add option to prevent the SDK from returning default avatar URLs. --- lib/client.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 63fc27959..44365c500 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1393,17 +1393,21 @@ MatrixClient.prototype.setAvatarUrl = function(url, callback) { * @param {Number} height The desired height of the thumbnail. * @param {string} resizeMethod The thumbnail resize method to use, either * "crop" or "scale". + * @param {Boolean} allowDefault (optional) Passing false causes this method to + * return null if the user has no avatar image. Otherwise, a default image URL + * will be returned. * @return {?string} the avatar URL or null. */ MatrixClient.prototype.getAvatarUrlForMember = - function(member, width, height, resizeMethod) { + function(member, width, height, resizeMethod, allowDefault) { if (!member || !member.events.member) { return null; } + if (allowDefault === undefined) { allowDefault = true; } var rawUrl = member.events.member.getContent().avatar_url; if (rawUrl) { return this._http.getHttpUriForMxc(rawUrl, width, height, resizeMethod); - } else { + } else if (allowDefault) { return this._http.getIdenticonUri(member.userId, width, height); } return null;