mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-20 01:56:33 +00:00
unsub global when not viewing it
This commit is contained in:
parent
17bb81e273
commit
b4b5914bf4
@ -93,6 +93,7 @@ class MessageFeed extends Component {
|
||||
if (this.props.scrollElement) {
|
||||
this.props.scrollElement.removeEventListener('scroll', this.handleScroll);
|
||||
}
|
||||
this.unsub && this.unsub();
|
||||
}
|
||||
|
||||
addScrollHandler() {
|
||||
@ -151,7 +152,7 @@ class MessageFeed extends Component {
|
||||
}
|
||||
|
||||
getMessagesByEveryone(includeReplies) {
|
||||
Events.getMessagesByEveryone((messages, cbIncludeReplies) => {
|
||||
this.unsub = Events.getMessagesByEveryone((messages, cbIncludeReplies) => {
|
||||
this.state.includeReplies === cbIncludeReplies && this.updateSortedMessages(messages);
|
||||
}, includeReplies);
|
||||
}
|
||||
|
@ -132,6 +132,10 @@ class PublicMessage extends Message {
|
||||
|
||||
componentDidMount() {
|
||||
this.unmounted = false;
|
||||
if (!this.props.hash) {
|
||||
console.error('PublicMessage: no hash');
|
||||
return;
|
||||
}
|
||||
const hexId = Key.toNostrHexAddress(this.props.hash);
|
||||
this.hexId = hexId;
|
||||
localState.get('mutedNotes').on(
|
||||
|
@ -782,7 +782,7 @@ const Events = {
|
||||
);
|
||||
};
|
||||
callback();
|
||||
return Subscriptions.subscribe([{ kinds: [1, 3, 5, 7] }], callback);
|
||||
return Subscriptions.subscribe([{ kinds: [1, 3, 5, 7, 9735], limit: 100 }], callback, 'global');
|
||||
},
|
||||
getMessagesByFollows(
|
||||
cb: (messageIds: string[], includeReplies: boolean) => void,
|
||||
@ -797,7 +797,7 @@ const Events = {
|
||||
);
|
||||
};
|
||||
callback();
|
||||
return Subscriptions.subscribe([{ kinds: [1, 3, 5, 7] }], callback);
|
||||
return Subscriptions.subscribe([{ kinds: [1, 3, 5, 7, 9735] }], callback);
|
||||
},
|
||||
getMessagesByKeyword(keyword: string, cb: (messageIds: string[]) => void): Unsubscribe {
|
||||
const callback = (event) => {
|
||||
|
@ -189,6 +189,17 @@ export default {
|
||||
5 * 1000,
|
||||
{ leading: true },
|
||||
),
|
||||
unsubscribe: function (id: string) {
|
||||
const subs = Subscriptions.subscriptionsByName.get(id);
|
||||
if (subs) {
|
||||
subs.forEach((sub) => {
|
||||
console.log('unsub', id);
|
||||
sub.unsub();
|
||||
});
|
||||
}
|
||||
Subscriptions.subscriptionsByName.delete(id);
|
||||
Subscriptions.subscribedFiltersByName.delete(id);
|
||||
},
|
||||
resubscribe(relay?: Relay) {
|
||||
console.log('subscribedFiltersByName.size', Subscriptions.subscribedFiltersByName.size);
|
||||
for (const [name, filters] of Array.from(Subscriptions.subscribedFiltersByName.entries())) {
|
||||
|
@ -113,7 +113,7 @@ const Session = {
|
||||
});
|
||||
setTimeout(() => {
|
||||
// TODO 'new' subscription should only be done when viewing Global
|
||||
Relays.subscribe([{ kinds: [0, 1, 3, 6, 7, 9735], limit: 10 }], 'new', false, 0, true); // everything new
|
||||
// Relays.subscribe([{ kinds: [0, 1, 3, 6, 7, 9735], limit: 10 }], 'new', false, 0, true); // everything new
|
||||
Relays.subscribe([{ authors: [myPub] }], 'ours', false, 0, true); // our stuff
|
||||
Relays.subscribe([{ '#p': [myPub] }], 'notifications', false, 0, true); // notifications and DMs
|
||||
}, 200);
|
||||
|
@ -132,18 +132,6 @@ const Subscriptions = {
|
||||
};
|
||||
go();
|
||||
}, 100),
|
||||
// TODO rename, this is for external subscription. clarify internal vs external subs distinction.
|
||||
unsubscribe: function (id: string) {
|
||||
const subs = this.subscriptionsByName.get(id);
|
||||
if (subs) {
|
||||
subs.forEach((sub) => {
|
||||
console.log('unsub', id);
|
||||
sub.unsub();
|
||||
});
|
||||
}
|
||||
this.subscriptionsByName.delete(id);
|
||||
this.subscribedFiltersByName.delete(id);
|
||||
},
|
||||
/**
|
||||
* internal subscribe
|
||||
* @param filters
|
||||
@ -231,12 +219,17 @@ const Subscriptions = {
|
||||
}
|
||||
hasNewIds && this.subscribeToPosts(this);
|
||||
hasNewKeywords && this.subscribeToKeywords(this);
|
||||
name === 'global' && Relays.subscribe(filters, 'global');
|
||||
return () => {
|
||||
if (currentSubscriptionId) {
|
||||
this.subscriptions.delete(currentSubscriptionId);
|
||||
}
|
||||
if (name) {
|
||||
this.internalSubscriptionsByName.delete(name);
|
||||
if (name === 'global') {
|
||||
Relays.unsubscribe('global');
|
||||
console.log('unsubscribed global');
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user