fix fetching our own dms

This commit is contained in:
Martti Malmi 2023-03-28 11:06:43 +03:00
parent 2755deb256
commit 9d82f5d58b
6 changed files with 22 additions and 34 deletions

View File

@ -8,7 +8,7 @@ import { route } from 'preact-router';
import EventComponent from './components/events/EventComponent';
import Name from './components/Name';
import { isSafeOrigin } from './components/SafeImg';
import { SafeImg, isSafeOrigin } from './components/SafeImg';
import Torrent from './components/Torrent';
import Key from './nostr/Key';
import { language, translate as t } from './translations/Translation';
@ -340,6 +340,21 @@ export default {
});
}
// find .jpg .jpeg .gif .png .webp urls in msg.text and create img tag
if (settings.enableImages !== false) {
const imgRegex = /https?:\/\/.*\.(?:jpg|jpeg|gif|png|webp)/gi;
replacedText = reactStringReplace(replacedText, imgRegex, (match, i) => {
let parsedUrl;
try {
parsedUrl = new URL(match);
} catch (e) {
console.log('invalid url', match);
return;
}
return <SafeImg src={parsedUrl} key={parsedUrl + i} />;
});
}
replacedText = this.highlightText(replacedText, event, opts);
const lnRegex =

View File

@ -1,3 +1,4 @@
//import "preact/debug";
import { Helmet } from 'react-helmet';
import { Router, RouterOnChangeArgs } from 'preact-router';

View File

@ -43,14 +43,6 @@ const DEFAULT_SETTINGS = {
timespan: 'all',
};
const TIMESPANS = {
all: 0,
day: 24 * 60 * 60,
week: 7 * 24 * 60 * 60,
month: 30 * 24 * 60 * 60,
year: 365 * 24 * 60 * 60,
};
class Feed extends Component {
constructor() {
super();
@ -264,6 +256,9 @@ class Feed extends Component {
}
getEvents(callback) {
if (this.props.index === 'notifications') {
}
if (this.props.nostrUser) {
if (this.props.index === 'likes') {
return PubSub.subscribe(

View File

@ -301,12 +301,6 @@ class Note extends Component {
}
if (parsedUrl.pathname.toLowerCase().match(/\.(jpg|jpeg|gif|png|webp)$/)) {
meta.attachments.push({ type: 'image', data: `${parsedUrl.href}` });
// Remove URL from beginning or end of line or before newline
const esc = escapeRegExp(url);
text = text.replace(new RegExp(`^${esc}`), '');
text = text.replace(new RegExp(`${esc}$`), '');
text = text.replace(new RegExp(`${esc}\n`), ' ');
}
});
}
@ -629,23 +623,6 @@ class Note extends Component {
`;
}
renderAttachments() {
return this.props.meta.attachments.map((a, i) => {
if (i > 0 && !this.props.standalone && !this.state.showMore) {
return;
}
return html`<div class="img-container">
<${SafeImg}
width=${569}
src=${a.data}
onClick=${(e) => {
this.imageClicked(e);
}}
/>
</div>`;
});
}
isTooLong() {
return (
this.props.meta.attachments?.length > 1 ||
@ -721,7 +698,6 @@ class Note extends Component {
/>
`
: ''}
${this.props.meta.attachments && this.renderAttachments()}
${s.text?.length > 0
? html`<div class="text ${s.emojiOnly && 'emoji-only'}">
${(!this.state.showMore && this.state.shortContent) || this.state.content}

View File

@ -756,7 +756,7 @@ const Events = {
};
this.directMessagesByUser.has(address) && callback();
const myPub = Key.getPubKey();
return PubSub.subscribe([{ kinds: [4], '#p': [address, myPub] }], callback);
return PubSub.subscribe([{ kinds: [4], '#p': [myPub], authors: [address] }, { kinds: [4], '#p': [address], authors: [myPub] }], callback);
},
getDirectMessages(cb) {
const callback = () => {

View File

@ -32,6 +32,7 @@ let dev: any = {
};
const relayPool = new RelayPool(Relays.DEFAULT_RELAYS, {
useEventCache: false,
externalGetEventById: (id) => Events.db.by('id', id),
});
localState.get('dev').on((d) => {