Skip to content

Commit ce3ad8e

Browse files
authored
Forms: show Gravatar for IP (#45726)
* Forms: load Gravatar also for rows without emails * explain * changelog * Use mystery person for IP & URL
1 parent 9cb06cb commit ce3ad8e

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Forms: show gravatars also for rows without emails

projects/packages/forms/src/dashboard/components/gravatar/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import { sha256 } from 'js-sha256';
99
import './style.scss';
1010

1111
type GravatarProps = {
12+
defaultImage?: // https://docs.gravatar.com/sdk/images/#default-image
13+
| 'blank'
14+
| 'color'
15+
| 'identicon'
16+
| 'initials'
17+
| 'monsterid'
18+
| 'mp'
19+
| 'retro'
20+
| 'robohash'
21+
| 'wavatar';
1222
displayName?: string;
1323
email: string;
1424
size?: number;
@@ -25,6 +35,7 @@ type GravatarProps = {
2535
* @return {JSX.Element} The Gravatar component
2636
*/
2737
export default function Gravatar( {
38+
defaultImage = 'initials',
2839
displayName,
2940
email,
3041
size = 48,
@@ -74,7 +85,7 @@ export default function Gravatar( {
7485
alt={ displayName || '' }
7586
className="jp-forms__gravatar"
7687
ref={ profileImageRef }
77-
src={ `https://0.gravatar.com/avatar/${ hashedEmail }?d=initials&name=${ displayName }` }
88+
src={ `https://0.gravatar.com/avatar/${ hashedEmail }?d=${ defaultImage }&name=${ displayName }` }
7889
width={ size }
7990
height={ size }
8091
/>

projects/packages/forms/src/dashboard/inbox/dataviews/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export default function InboxView() {
227227
const authorInfo = decodeEntities(
228228
item.author_name || item.author_email || item.author_url || item.ip
229229
);
230+
const defaultImage = item.author_name || item.author_email ? 'initials' : 'mp';
230231
return (
231232
<div className="jp-forms__inbox__author-field">
232233
{ item.is_unread && (
@@ -237,15 +238,14 @@ export default function InboxView() {
237238
238239
</span>
239240
) }
240-
{ item.author_email && (
241-
<Gravatar
242-
email={ item.author_email }
243-
displayName={ authorInfo }
244-
key={ decodeEntities( item.author_email ) }
245-
size={ 32 }
246-
useHovercard={ false }
247-
/>
248-
) }
241+
<Gravatar
242+
email={ item.author_email || item.ip } // With IP we still return placeholder image
243+
defaultImage={ defaultImage }
244+
displayName={ authorInfo }
245+
key={ item.id }
246+
size={ 32 }
247+
useHovercard={ false }
248+
/>
249249
{ wrapperUnread( item.is_unread, authorInfo ) }
250250
</div>
251251
);

0 commit comments

Comments
 (0)