Files
discord-decomp/modules/friend_suggestions/FriendSuggestionStore.tsx
T
2026-11-01 12:12:55 +02:00

103 lines
3.3 KiB
TypeScript

// Metro module 5948 (f5949).
import UserRecord from "../../records/UserRecord";
import UserStore from "../../stores/UserStore";
import Module12 from "../../_bundle/Module12";
import FriendSuggestionActionCreators from "./FriendSuggestionActionCreators";
import maybeDispatchDevOnlyDummyFriendSuggestions from "./maybeDispatchDevOnlyDummyFriendSuggestions";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
function $mk77511() {
return (a0) => a0.key;
}
let $mk77510 = function() {
return (a0) => {
const contactNames = a0.contact_names != null && a0.contact_names.length >= 2 ? a0.contact_names.slice(0, 2) : [];
return {
key: a0.suggested_user.id,
name: Module12.first(a0.reasons)?.name,
user: new UserRecord(a0.suggested_user),
mutualFriendsCount: a0.mutual_friends_count,
contactNames
};
};
};
let c3741_4 = {};
let friendSuggestionCount = 0;
let c3741_6 = false;
let c3741_7 = false;
class FriendSuggestionStore extends Module589.Store {
static displayName = "FriendSuggestionStore";
initialize() {
this.waitFor(UserStore);
}
getSuggestionCount() {
return friendSuggestionCount;
}
getSuggestions() {
return Object.entries(c3741_4).map((item) => {
const [, r13] = item;
return r13;
});
}
getSuggestion(a0) {
return c3741_4[a0];
}
}
const friendSuggestionStore = new FriendSuggestionStore(Dispatcher, {
CONNECTION_OPEN: function handleConnectionOpen(a0) {
c3741_4 = {};
const friendSuggestionCount2 = a0.friendSuggestionCount;
friendSuggestionCount = friendSuggestionCount2;
if (friendSuggestionCount2 > 0) {
c3741_7 = true;
const r3 = c3741_6;
if (r3 ? !r3 : true) {
c3741_6 = true;
c3741_7 = false;
FriendSuggestionActionCreators.fetch();
}
} else {
maybeDispatchDevOnlyDummyFriendSuggestions();
}
},
FRIEND_SUGGESTION_CREATE: function handleFriendSuggestionCreate({ suggestion }) {
const contactNames = suggestion.contact_names != null && suggestion.contact_names.length >= 2 ? suggestion.contact_names.slice(0, 2) : [];
const r21 = {
key: suggestion.suggested_user.id,
name: Module12.first(suggestion.reasons)?.name,
user: new UserRecord(suggestion.suggested_user),
mutualFriendsCount: suggestion.mutual_friends_count,
contactNames
};
if (c3741_4[r21.key] != null) {
return false;
}
friendSuggestionCount = friendSuggestionCount + 1;
const r38 = {
...c3741_4
};
r38[r21.key] = r21;
c3741_4 = r38;
},
FRIEND_SUGGESTION_DELETE: function handleFriendSuggestionDelete(a0) {
const r5 = Math;
const r7 = friendSuggestionCount - 1;
friendSuggestionCount = r7;
friendSuggestionCount = r5.max(0, r7);
delete c3741_4[a0.suggestedUserId];
},
LOAD_FRIEND_SUGGESTIONS_SUCCESS: function handleLoadFriendSuggestionsSuccess(a0) {
c3741_6 = false;
c3741_4 = Module12.chain(a0.suggestions).map($mk77510()).keyBy($mk77511()).value();
friendSuggestionCount = Module12.keys(c3741_4).length;
},
LOAD_FRIEND_SUGGESTIONS_FAILURE: function handleLoadFriendSuggestionsFailure() {
c3741_6 = false;
c3741_4 = {};
}
});
export default friendSuggestionStore;
export function transformFriendSuggestions(a0) {
return Module12.chain(a0).map($mk77510()).keyBy($mk77511()).value();
}