fix(ImplicitRelationships): Use new Flux event (#2392)

This commit is contained in:
dolfies 2024-04-27 16:29:29 -04:00 committed by GitHub
parent d2941281a4
commit 840c775ed8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -151,20 +151,25 @@ export default definePlugin({
// OP 8 Request Guild Members allows 100 user IDs at a time // OP 8 Request Guild Members allows 100 user IDs at a time
const ignore = new Set(toRequest); const ignore = new Set(toRequest);
const relationships = RelationshipStore.getRelationships(); const relationships = RelationshipStore.getRelationships();
const callback = ({ nonce, members }) => { const callback = ({ chunks }) => {
if (nonce !== sentNonce) return; for (const chunk of chunks) {
members.forEach(member => { const { nonce, members } = chunk;
ignore.delete(member.user.id); if (nonce !== sentNonce) return;
}); members.forEach(member => {
ignore.delete(member.user.id);
});
nonFriendAffinities.map(id => UserStore.getUser(id)).filter(user => user && !ignore.has(user.id)).forEach(user => relationships[user.id] = 5); nonFriendAffinities.map(id => UserStore.getUser(id)).filter(user => user && !ignore.has(user.id)).forEach(user => relationships[user.id] = 5);
RelationshipStore.emitChange(); RelationshipStore.emitChange();
if (--count === 0) { if (--count === 0) {
FluxDispatcher.unsubscribe("GUILD_MEMBERS_CHUNK", callback); // @ts-ignore
FluxDispatcher.unsubscribe("GUILD_MEMBERS_CHUNK_BATCH", callback);
}
} }
}; };
FluxDispatcher.subscribe("GUILD_MEMBERS_CHUNK", callback); // @ts-ignore
FluxDispatcher.subscribe("GUILD_MEMBERS_CHUNK_BATCH", callback);
for (let i = 0; i < toRequest.length; i += 100) { for (let i = 0; i < toRequest.length; i += 100) {
FluxDispatcher.dispatch({ FluxDispatcher.dispatch({
type: "GUILD_MEMBERS_REQUEST", type: "GUILD_MEMBERS_REQUEST",