Skip to content

Commit 39c451e

Browse files
vogtnnmetulev
andauthored
[mgt-person][mgt-people-picker] Photo for Person Type "Group"/ missing AD member (#1366)
Co-authored-by: Nikola Metulev <[email protected]>
1 parent 4e37983 commit 39c451e

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

packages/mgt-components/src/components/mgt-people-picker/mgt-people-picker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ export class MgtPeoplePicker extends MgtTemplatedComponent {
748748
*/
749749
protected renderSearchResults(people?: IDynamicPerson[]) {
750750
people = people || this._foundPeople;
751-
751+
let filteredPeople = people.filter(person => person.id);
752752
return html`
753753
<div class="people-list" @mouseenter=${this.handleMouseEnter} @mouseleave=${this.handleMouseLeave}>
754754
${repeat(
755-
people,
755+
filteredPeople,
756756
person => person.id,
757757
person => {
758758
const listPersonClasses = {

packages/mgt-components/src/components/mgt-person/mgt-person.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Contact, Presence } from '@microsoft/microsoft-graph-types';
99
import { customElement, html, internalProperty, property, TemplateResult } from 'lit-element';
1010
import { classMap } from 'lit-html/directives/class-map';
1111
import { findPeople, getEmailFromGraphEntity } from '../../graph/graph.people';
12-
import { getPersonImage } from '../../graph/graph.photos';
12+
import { getGroupImage, getPersonImage } from '../../graph/graph.photos';
1313
import { getUserPresence } from '../../graph/graph.presence';
1414
import { getUserWithPhoto } from '../../graph/graph.userWithPhoto';
1515
import { findUsers, getMe, getUser } from '../../graph/graph.user';
@@ -963,7 +963,13 @@ export class MgtPerson extends MgtTemplatedComponent {
963963
!this.personImage &&
964964
!this._fetchedImage
965965
) {
966-
const image = await getPersonImage(graph, this.personDetails, MgtPerson.config.useContactApis);
966+
this.personDetails;
967+
let image;
968+
if ('personType' in this.personDetails) {
969+
image = await getPersonImage(graph, this.personDetails, MgtPerson.config.useContactApis);
970+
} else {
971+
image = await getGroupImage(graph, this.personDetails, MgtPerson.config.useContactApis);
972+
}
967973
if (image) {
968974
this.personDetails.personImage = image;
969975
this._fetchedImage = image;

packages/mgt-components/src/graph/cacheStores.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export const schemas = {
2828
name: 'photos',
2929
stores: {
3030
contacts: 'contacts',
31-
users: 'users'
31+
users: 'users',
32+
groups: 'groups'
3233
},
3334
version: 1
3435
},

packages/mgt-components/src/graph/graph.photos.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,43 @@ export async function getPersonImage(graph: IGraph, person: IDynamicPerson, useC
231231
return null;
232232
}
233233

234+
export async function getGroupImage(graph: IGraph, group: any, useContactsApis: boolean = true) {
235+
let photoDetails: CachePhoto;
236+
let cache: CacheStore<CachePhoto>;
237+
238+
let groupId = group.id;
239+
240+
if (getIsPhotosCacheEnabled()) {
241+
cache = CacheService.getCache<CachePhoto>(schemas.photos, schemas.photos.stores.groups);
242+
photoDetails = await cache.getValue(groupId);
243+
if (photoDetails && getPhotoInvalidationTime() > Date.now() - photoDetails.timeCached) {
244+
return photoDetails.photo;
245+
} else if (photoDetails) {
246+
// there is a photo in the cache, but it's stale
247+
try {
248+
const response = await graph.api(`group/${groupId}/photo`).get();
249+
if (
250+
response &&
251+
(response['@odata.mediaEtag'] !== photoDetails.eTag ||
252+
(response['@odata.mediaEtag'] === null && response.eTag === null))
253+
) {
254+
// set photoDetails to null so that photo gets pulled from the graph later
255+
photoDetails = null;
256+
}
257+
} catch {
258+
return null;
259+
}
260+
}
261+
}
262+
263+
// if there is a photo in the cache, we got here because it was stale
264+
photoDetails = photoDetails || (await getPhotoForResource(graph, `groups/${groupId}`, ['user.readbasic.all']));
265+
if (getIsPhotosCacheEnabled() && photoDetails) {
266+
cache.putValue(groupId, photoDetails);
267+
}
268+
return photoDetails ? photoDetails.photo : null;
269+
}
270+
234271
/**
235272
* checks if user has a photo in the cache
236273
* @param userId

0 commit comments

Comments
 (0)