timeline: add route to show timeline of other users
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

added experimental /timeline/npub... route, this currently does
not correctly reload as contacts of that npub are lost onload.
other than that it seems to work well, but needs more testing.
pull/85/head
OFF0 1 year ago
parent 4e5bf50e54
commit bb8790e949
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -66,13 +66,14 @@ const updateFollowing = (evt: Event) => {
case 'profile': case 'profile':
updateFollowBtn(view.id); updateFollowBtn(view.id);
if (view.id === evt.pubkey) { if (view.id === evt.pubkey) {
const npub = nip19.npubEncode(evt.pubkey);
// update following link // update following link
const following = getViewElem('following') as HTMLElement; const following = getViewElem('following') as HTMLElement;
if (following) { if (following) {
const count = evt.tags.filter(isPTag).length; const count = evt.tags.filter(isPTag).length;
const anchor = elem('a', { const anchor = elem('a', {
data: {following: evt.pubkey}, data: {following: evt.pubkey},
href: `/contacts/${nip19.npubEncode(evt.pubkey)}`, href: `/contacts/${npub}`,
title: dateTime.format(evt.created_at * 1000), title: dateTime.format(evt.created_at * 1000),
}, [ }, [
'following ', 'following ',
@ -81,6 +82,12 @@ const updateFollowing = (evt: Event) => {
following.replaceWith(anchor); following.replaceWith(anchor);
setViewElem('following', anchor); setViewElem('following', anchor);
} }
let timeline = getViewElem('timeline');
if (!timeline) {
timeline = elem('a', {href: `/timeline/${npub}`}, 'timeline');
getViewElem('header').querySelector('footer')?.append(timeline);
setViewElem('timeline', timeline);
}
} }
break; break;
} }

@ -82,7 +82,7 @@ const renderFeed = bounce(() => {
refreshFollowing(view.id); refreshFollowing(view.id);
break; break;
case 'home': case 'home':
const ids = getOwnContacts(); const ids = view.id ? getContacts(view.id) : getOwnContacts();
[ [
...textNoteList ...textNoteList
.filter(note => ids.includes(note.pubkey)), .filter(note => ids.includes(note.pubkey)),
@ -269,7 +269,7 @@ const route = (path: string) => {
const contactList = getOwnContacts(); const contactList = getOwnContacts();
if (contactList.length) { if (contactList.length) {
subPubkeys(contactList, onEvent); subPubkeys(contactList, onEvent);
view(`/`, {type: 'home'}); view('/', {type: 'home'});
} else { } else {
subGlobalFeed(onEvent); subGlobalFeed(onEvent);
view('/feed', {type: 'feed'}); view('/feed', {type: 'feed'});
@ -306,6 +306,14 @@ const route = (path: string) => {
subContactList(contactPubkey, onEvent); subContactList(contactPubkey, onEvent);
view(path, {type: 'contacts', id: contactPubkey}); view(path, {type: 'contacts', id: contactPubkey});
} }
} else if (path.length === 73 && path.match(/^\/timeline\/npub[0-9a-z]+$/)) {
const timelineNpub = path.slice(10);
const {type: timelineType, data: timelinePubkey} = nip19.decode(timelineNpub);
if (timelineType === 'npub') {
const timelinePubkeys = getContacts(timelinePubkey);
subPubkeys(timelinePubkeys, onEvent);
view(path, {type: 'home', id: timelinePubkey});
}
} else if (path.length === 65) { } else if (path.length === 65) {
const eventID = path.slice(1); const eventID = path.slice(1);
subEventID(eventID, onEventDetails); subEventID(eventID, onEventDetails);
@ -346,6 +354,7 @@ const handleLink = (a: HTMLAnchorElement, e: MouseEvent) => {
|| href.startsWith('/note') || href.startsWith('/note')
|| href.startsWith('/npub') || href.startsWith('/npub')
|| href.startsWith('/contacts/npub') || href.startsWith('/contacts/npub')
|| href.startsWith('/timeline/npub')
|| (href.startsWith('/') && href.length === 65) || (href.startsWith('/') && href.length === 65)
) { ) {
route(href); route(href);

@ -193,6 +193,8 @@ nav a {
} }
.hero footer { .hero footer {
display: flex;
gap: var(--gap-half);
padding-left: var(--extra-space); padding-left: var(--extra-space);
} }

@ -8,6 +8,7 @@ export type DOMMap = {
export type ViewTemplateOptions = { export type ViewTemplateOptions = {
type: 'home'; type: 'home';
id?: string;
} | { } | {
type: 'feed'; type: 'feed';
} | { } | {

Loading…
Cancel
Save