improve display of contact names

This commit is contained in:
=
2023-04-08 21:16:43 +00:00
parent 72c746ae2a
commit 76ac861c08
4 changed files with 12 additions and 4 deletions

View File

@@ -55,7 +55,7 @@ const generateContactDetails = (pubkey:string):string => {
<div>
${m && !!m.picture ? `<img src="${m.picture}" /> ` : ''}
<div class="contactdetailsmain">
<strong>${m.name ? m.name : '[unknown name]'}</strong>
<strong>${getContactName(pubkey)}</strong>
${m.nip05 ? `<small id="nip05-${pubkey}">${m.nip05} </small>` : ''}<span id="nip05-${pubkey}-verified"></span>
${otherspetname && otherspetname !== m.name ? `<div>popular petname: ${otherspetname}</div>` : ''}
<div><small>${m.about ? m.about : ''}</small></div>

View File

@@ -4,6 +4,7 @@ import {
} from './LoadHistory';
import { MetadataFlex } from './LoadMetadataPage';
import SampleEvents from './SampleEvents';
import * as LocalStorage from './LocalStorage';
const weekago = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 7.1));
const monthsago = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 7 * 5));
@@ -118,6 +119,8 @@ describe('generateContactsChanges', () => {
test('is removed', () => {
const s = JSON.parse(JSON.stringify(SampleEvents.kind3));
delete s.tags[2][3];
jest.spyOn(LocalStorage, 'localStorageGetItem')
.mockImplementation((): string | null => JSON.stringify([s]));
const r = generateContactsChanges([
s,
{ ...SampleEvents.kind3 },
@@ -128,6 +131,8 @@ describe('generateContactsChanges', () => {
});
test('is added', () => {
const s = JSON.parse(JSON.stringify(SampleEvents.kind3));
jest.spyOn(LocalStorage, 'localStorageGetItem')
.mockImplementation((): string | null => JSON.stringify([{ ...SampleEvents.kind3 }]));
delete s.tags[2][3];
const r = generateContactsChanges([
{ ...SampleEvents.kind3 },

View File

@@ -1,6 +1,6 @@
import * as timeago from 'timeago.js';
import { Event } from 'nostr-tools';
import { fetchCachedMyProfileEventHistory, submitUnsignedEvent } from './fetchEvents';
import { fetchCachedMyProfileEventHistory, getContactName, submitUnsignedEvent } from './fetchEvents';
export type VersionChange = {
ago:number;
@@ -73,7 +73,7 @@ const sameContact = (
const getPetname = (a:['p', string, string, string]):string => {
if (a[3] && a[3].length > 0) return `<mark>${a[3]}</mark>`;
return `<mark>${(a[1]).substring(0, 10)}...</mark>`;
return `<mark>${getContactName(a[1])}</mark>`;
};
export const generateContactsChanges = (

View File

@@ -275,8 +275,11 @@ export const getContactName = (pubkey: string):string => {
// their kind 0 name
if (UserProfileEvents[pubkey]) {
if (UserProfileEvents[pubkey][0]) {
const { name } = JSON.parse(UserProfileEvents[pubkey][0].content);
// eslint-disable-next-line @typescript-eslint/naming-convention
const { name, display_name } = JSON.parse(UserProfileEvents[pubkey][0].content);
if (name) return name;
// name isn't present for Jack Dorsey and Vitor from Amethyst in Apr 2023.
if (display_name) return display_name;
}
}
}