From ac507a6f21e942eed36842a87521202552d1e577 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Wed, 28 Dec 2022 14:37:09 +0200 Subject: [PATCH] lint --- .eslintignore | 2 +- src/js/Nostr.ts | 40 +++++++++++++++++++----------- src/js/components/PublicMessage.js | 33 ++++++++++++++++-------- src/js/components/SafeImg.tsx | 6 ++--- src/js/views/Feed.js | 6 +---- 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/.eslintignore b/.eslintignore index a7b8dc30..dde9b420 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -src/js/lib/*.js \ No newline at end of file +src/js/lib/** \ No newline at end of file diff --git a/src/js/Nostr.ts b/src/js/Nostr.ts index 12c174d8..d840c585 100644 --- a/src/js/Nostr.ts +++ b/src/js/Nostr.ts @@ -1,9 +1,11 @@ import iris from 'iris-lib'; import { debounce, throttle } from 'lodash'; + import { Event, Filter, getEventHash, Relay, relayInit, signEvent } from './lib/nostr-tools'; const bech32 = require('bech32-buffer'); +import localForage from 'localforage'; + import SortedLimitedEventSet from './SortedLimitedEventSet'; -import localForage from "localforage"; function arrayToHex(array: any) { return Array.from(array, (byte: any) => { @@ -33,7 +35,7 @@ const saveLocalStorageProfiles = throttle((profileMap: Map) => { return; } // should we save profile events instead? application state would be only changed by events - const profiles = Array.from(profileMap.keys()).map(pub => { + const profiles = Array.from(profileMap.keys()).map((pub) => { const p = profileMap.get(pub); p && (p.pub = pub); return p; @@ -115,11 +117,11 @@ export default { this.handleEvent(myFollowsEvent as Event); } if (Array.isArray(profiles)) { - profiles.forEach(p => p && this.profiles.set(p.pub, p)); + profiles.forEach((p) => p && this.profiles.set(p.pub, p)); } if (Array.isArray(latestMsgs)) { console.log('loaded latestmsgs'); - latestMsgs.forEach(msg => { + latestMsgs.forEach((msg) => { this.handleEvent(msg); // TODO this does nothing because follows are not known yet }); } @@ -226,16 +228,17 @@ export default { if (_this.subscribedPosts.size === 0) return; console.log('subscribe to posts', Array.from(_this.subscribedPosts)); for (const relay of _this.relays.values()) { - const sub = relay.sub([{ ids: Array.from(_this.subscribedPosts) }], {}); - // TODO update relay lastSeen - sub.on('event', (event) => _this.handleEvent(event)); + const sub = relay.sub([{ ids: Array.from(_this.subscribedPosts) }], {}); + // TODO update relay lastSeen + sub.on('event', (event) => _this.handleEvent(event)); } }, 1000), subscribe: function (filters: Filter[], cb: Function | undefined) { - cb && this.subscriptions.set(subscriptionId++, { - filters, - callback: cb, - }); + cb && + this.subscriptions.set(subscriptionId++, { + filters, + callback: cb, + }); let hasNewAuthors = false; let hasNewIds = false; @@ -320,7 +323,10 @@ export default { this.directRepliesByMessageId.get(replyingTo)?.add(event.id); // are boost messages screwing this up? - const repliedMsgs = event.tags.filter((tag) => tag[0] === 'e').map(tag => tag[1]).slice(0,2); + const repliedMsgs = event.tags + .filter((tag) => tag[0] === 'e') + .map((tag) => tag[1]) + .slice(0, 2); for (const id of repliedMsgs) { if (!this.threadRepliesByMessageId.has(id)) { this.threadRepliesByMessageId.set(id, new Set()); @@ -531,7 +537,12 @@ export default { getRepliesAndLikes(id: string, cb: Function | undefined) { const callback = () => { - cb && cb(this.directRepliesByMessageId.get(id), this.likesByMessageId.get(id), this.threadRepliesByMessageId.get(id)?.size ?? 0); + cb && + cb( + this.directRepliesByMessageId.get(id), + this.likesByMessageId.get(id), + this.threadRepliesByMessageId.get(id)?.size ?? 0, + ); }; if (this.directRepliesByMessageId.has(id) || this.likesByMessageId.has(id)) { callback(); @@ -563,7 +574,8 @@ export default { } return new Promise((resolve) => { - this.subscribe([{ ids: [id] }], () => { // TODO turn off subscription + this.subscribe([{ ids: [id] }], () => { + // TODO turn off subscription resolve(this.messagesById.get(id)); }); }); diff --git a/src/js/components/PublicMessage.js b/src/js/components/PublicMessage.js index 1616eefd..2144a42a 100644 --- a/src/js/components/PublicMessage.js +++ b/src/js/components/PublicMessage.js @@ -74,7 +74,8 @@ class PublicMessage extends Message { }; }; - if (Nostr.messagesById.has(nostrId)) { // for faster painting, return synchronously if we have the message + if (Nostr.messagesById.has(nostrId)) { + // for faster painting, return synchronously if we have the message return processNostrMessage(Nostr.messagesById.get(nostrId)); } @@ -126,7 +127,9 @@ class PublicMessage extends Message { const nostrId = Nostr.toNostrHexAddress(this.props.hash); const msg = r.signedData; - msg.info = { from: nostrId ? Nostr.toNostrBech32Address(r.signerKeyHash, 'npub') : r.signerKeyHash }; + msg.info = { + from: nostrId ? Nostr.toNostrBech32Address(r.signerKeyHash, 'npub') : r.signerKeyHash, + }; if (this.props.filter) { if (!this.props.filter(msg)) { return; @@ -156,7 +159,11 @@ class PublicMessage extends Message { if (nostrId) { Nostr.getRepliesAndLikes(nostrId, (replies, likes, threadReplyCount) => { this.likedBy = new Set(likes); - const sortedReplies = replies && Array.from(replies).sort((a, b) => Nostr.messagesById.get(a)?.time - Nostr.messagesById.get(b)?.time); + const sortedReplies = + replies && + Array.from(replies).sort( + (a, b) => Nostr.messagesById.get(a)?.time - Nostr.messagesById.get(b)?.time, + ); this.setState({ likes: this.likedBy.size, liked: this.likedBy.has(myPub), @@ -266,16 +273,17 @@ class PublicMessage extends Message { render() { const isThumbnail = this.props.thumbnail ? 'thumbnail-item' : ''; if (!this.state.msg) { - return html` -
-
- ${this.state.retrieving ? html`
Looking up message...
` : ''} -
-
`; + > +
+ ${this.state.retrieving ? html`
Looking up message...
` : ''} +
+ `; } //if (++this.i > 1) console.log(this.i); let name = this.props.name || this.state.name || this.shortPubKey(this.state.msg.info.from); @@ -405,7 +413,10 @@ class PublicMessage extends Message { ${s.likes || ''}
- + ${Helpers.getRelativeTimeText(time)} ${dateStr} ${timeStr} diff --git a/src/js/components/SafeImg.tsx b/src/js/components/SafeImg.tsx index 8bbb12a1..2e1e7364 100644 --- a/src/js/components/SafeImg.tsx +++ b/src/js/components/SafeImg.tsx @@ -8,10 +8,10 @@ const SafeImg = (props: Props) => { if (props.src && props.src.indexOf('data:image') !== 0) { // free proxy with a 250 images per 10 min limit: https://images.weserv.nl/docs/ if (props.width) { - const width = props.width * 2; - props.src = `https://proxy.irismessengers.wtf/insecure/rs:fill:${width}:${width}/plain/${props.src}`; + const width = props.width * 2; + props.src = `https://proxy.irismessengers.wtf/insecure/rs:fill:${width}:${width}/plain/${props.src}`; } else { - props.src = `https://proxy.irismessengers.wtf/insecure/plain/${props.src}`; + props.src = `https://proxy.irismessengers.wtf/insecure/plain/${props.src}`; } } return ; diff --git a/src/js/views/Feed.js b/src/js/views/Feed.js index 57be23a7..7b9644cc 100644 --- a/src/js/views/Feed.js +++ b/src/js/views/Feed.js @@ -74,11 +74,7 @@ class Feed extends View { ${s.searchTerm ? '' : html` - <${FeedMessageForm} - key="form${path}" - class="hidden-xs" - autofocus=${false} - /> + <${FeedMessageForm} key="form${path}" class="hidden-xs" autofocus=${false} /> `} ${s.searchTerm ? html`

Search results for "${s.searchTerm}"

`