Skip to content

Commit

Permalink
change person photo url
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdu committed Mar 2, 2019
1 parent 8a3481d commit 6277e44
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/services/PeopleSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ import { cloneDeep, findIndex } from "@microsoft/sp-lodash-subset";
export default class SPPeopleSearchService {
private cachedPersonas: { [property: string]: IUserInfo[] };
private cachedLocalUsers: { [siteUrl: string]: IUserInfo[] };
private absoluteWebUrl: string;

/**
* Service constructor
*/
constructor(private context: WebPartContext | ExtensionContext) {
this.cachedPersonas = {};
this.cachedLocalUsers = {};
this.cachedLocalUsers[this.context.pageContext.web.absoluteUrl] = [];
this.absoluteWebUrl = this.context.pageContext.web.absoluteUrl;
this.cachedLocalUsers[this.absoluteWebUrl] = [];
}

/**
* Generate the user photo link
* Generate the user photo link using SharePoint user photo endpoint.
*
* @param value
*/
public generateUserPhotoLink(value: string): string {
return `https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=${value}&UA=0&size=HR96x96`;
return `${this.absoluteWebUrl}/_layouts/15/userphoto.aspx?accountname=${encodeURIComponent(value)}&size=M`;
}

/**
Expand All @@ -42,7 +44,7 @@ export default class SPPeopleSearchService {
* @param principalTypes
*/
public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
}

/**
Expand Down Expand Up @@ -228,7 +230,7 @@ export default class SPPeopleSearchService {
const userResults = values.map(element => {
switch (element.EntityType) {
case 'User':
let email : string = element.EntityData.Email !== null ? element.EntityData.Email : element.Description;
let email: string = element.EntityData.Email !== null ? element.EntityData.Email : element.Description;
return {
id: element.Key,
imageUrl: this.generateUserPhotoLink(email),
Expand Down Expand Up @@ -336,7 +338,7 @@ export default class SPPeopleSearchService {
*/
private searchPeopleFromMock(query: string): Promise<Array<IPeoplePickerUserItem>> {
let mockClient: PeoplePickerMockClient = new PeoplePickerMockClient();
let filterValue = { valToCompare: query };
let filterValue = { valToCompare: query };
return new Promise<Array<IPeoplePickerUserItem>>((resolve) => resolve(MockUsers.filter(mockClient.filterPeople, filterValue)));
}
}

2 comments on commit 6277e44

@gobigfoot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This fixes issues with Government tenants!

@AsunSanLo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think this resolves the issue #210 .
I would prefer it to show the user initials when there's no image instead of the default's SharePoint user image, but the ideas that I've tried don't work with 100% success and they add an ugly complexity to the code.

Please sign in to comment.