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':
updateFollowBtn(view.id);
if (view.id === evt.pubkey) {
const npub = nip19.npubEncode(evt.pubkey);
// update following link
const following = getViewElem('following') as HTMLElement;
if (following) {
const count = evt.tags.filter(isPTag).length;
const anchor = elem('a', {
data: {following: evt.pubkey},
href: `/contacts/${nip19.npubEncode(evt.pubkey)}`,
href: `/contacts/${npub}`,
title: dateTime.format(evt.created_at * 1000),
}, [
'following ',
@ -81,6 +82,12 @@ const updateFollowing = (evt: Event) => {
following.replaceWith(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;
}

@ -82,7 +82,7 @@ const renderFeed = bounce(() => {
refreshFollowing(view.id);
break;
case 'home':
const ids = getOwnContacts();
const ids = view.id ? getContacts(view.id) : getOwnContacts();
[
...textNoteList
.filter(note => ids.includes(note.pubkey)),
@ -269,7 +269,7 @@ const route = (path: string) => {
const contactList = getOwnContacts();
if (contactList.length) {
subPubkeys(contactList, onEvent);
view(`/`, {type: 'home'});
view('/', {type: 'home'});
} else {
subGlobalFeed(onEvent);
view('/feed', {type: 'feed'});
@ -306,6 +306,14 @@ const route = (path: string) => {
subContactList(contactPubkey, onEvent);
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) {
const eventID = path.slice(1);
subEventID(eventID, onEventDetails);
@ -346,6 +354,7 @@ const handleLink = (a: HTMLAnchorElement, e: MouseEvent) => {
|| href.startsWith('/note')
|| href.startsWith('/npub')
|| href.startsWith('/contacts/npub')
|| href.startsWith('/timeline/npub')
|| (href.startsWith('/') && href.length === 65)
) {
route(href);

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

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

Loading…
Cancel
Save