146 lines
3.9 KiB
TypeScript
146 lines
3.9 KiB
TypeScript
// Metro module 13793 (f13794).
|
|
import LRUCache from "../../_bundle/LRUCache";
|
|
import Durations from "../../utils/Durations";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c9601_2 = {
|
|
taken: null,
|
|
error: void 0,
|
|
rateLimited: true
|
|
};
|
|
let c9601_3 = {
|
|
validations: new LRUCache({
|
|
max: 100,
|
|
maxAge: 60000
|
|
}),
|
|
currentUsernameInvalid: false,
|
|
retryAfterTime: null,
|
|
suggestions: {
|
|
migration: {
|
|
suggestion: {
|
|
username: void 0
|
|
},
|
|
fetched: false,
|
|
usernameSuggestionLoading: false
|
|
},
|
|
registration: {
|
|
suggestion: {
|
|
username: void 0
|
|
},
|
|
source: void 0,
|
|
fetched: false
|
|
}
|
|
}
|
|
};
|
|
class UniqueUsernamesStore extends Module589.Store {
|
|
static displayName = "UniqueUsernamesStore";
|
|
isRateLimited() {
|
|
return c9601_3.retryAfterTime != null && Date.now() < c9601_3.retryAfterTime;
|
|
}
|
|
validate(a0) {
|
|
let r7, r15;
|
|
L9: {
|
|
L3: {
|
|
r7 = c9601_3.validations.get(a0);
|
|
if (this.isRateLimited()) {
|
|
if (r7 != null && !r7.rateLimited) {
|
|
break L3;
|
|
}
|
|
r15 = c9601_2;
|
|
break L9;
|
|
}
|
|
}
|
|
r15 = !this.isRateLimited() && r7 != null ? r7.rateLimited ? void 0 : r7 : r7;
|
|
}
|
|
return r15;
|
|
}
|
|
registrationUsernameSuggestion() {
|
|
return c9601_3.suggestions.registration.suggestion.username;
|
|
}
|
|
usernameSuggestion() {
|
|
return c9601_3.suggestions.migration.suggestion.username;
|
|
}
|
|
usernameSuggestionLoading() {
|
|
return c9601_3.suggestions.migration.usernameSuggestionLoading;
|
|
}
|
|
isCurrentUsernameInvalid() {
|
|
return c9601_3.currentUsernameInvalid;
|
|
}
|
|
wasRegistrationSuggestionFetched(a0) {
|
|
return c9601_3.suggestions.registration.source === a0 && c9601_3.suggestions.registration.fetched;
|
|
}
|
|
wasSuggestionsFetched() {
|
|
return c9601_3.suggestions.migration.fetched;
|
|
}
|
|
}
|
|
const uniqueUsernamesStore = new UniqueUsernamesStore(Dispatcher, {
|
|
UNIQUE_USERNAME_ATTEMPT_SUCCESS: function handleUniqueUsernameAttemptSuccess(a0) {
|
|
c9601_3.validations.set(a0.username, {
|
|
taken: a0.taken
|
|
});
|
|
},
|
|
UNIQUE_USERNAME_ATTEMPT_FAILURE: function handleUniqueUsernameAttemptFailure({ username, error, statusCode, retryAfter }) {
|
|
if (statusCode === 429) {
|
|
const validations = c9601_3.validations;
|
|
const r18 = {
|
|
taken: null,
|
|
error,
|
|
rateLimited: true
|
|
};
|
|
let r11 = retryAfter;
|
|
if (r11 == null) {
|
|
r11 = 7;
|
|
}
|
|
validations.set(username, r18, r11 * Durations.Millis.SECOND);
|
|
} else {
|
|
c9601_3.validations.set(username, {
|
|
taken: null,
|
|
error
|
|
});
|
|
}
|
|
if (retryAfter != null) {
|
|
c9601_3.retryAfterTime = Date.now() + retryAfter * Durations.Millis.SECOND;
|
|
}
|
|
},
|
|
UNIQUE_USERNAME_SUGGESTIONS_RESET: function handleUniqueUsernameSuggestionsReset() {
|
|
c9601_3.suggestions.migration = {
|
|
suggestion: {
|
|
username: void 0
|
|
},
|
|
fetched: false,
|
|
usernameSuggestionLoading: false
|
|
};
|
|
c9601_3.suggestions.registration = {
|
|
suggestion: {
|
|
username: void 0
|
|
},
|
|
source: void 0,
|
|
fetched: false
|
|
};
|
|
},
|
|
UNIQUE_USERNAME_SUGGESTIONS_SUCCESS: function handleUniqueUsernameSuggestionsSuccess({ suggestion }) {
|
|
c9601_3.suggestions.migration = {
|
|
suggestion,
|
|
fetched: true,
|
|
usernameSuggestionLoading: false
|
|
};
|
|
if (suggestion?.invalid_current_username === true) {
|
|
c9601_3.currentUsernameInvalid = true;
|
|
}
|
|
},
|
|
UNIQUE_USERNAME_REGISTRATION_SUGGESTIONS_SUCCESS: function handleUniqueUsernameRegistrationSuggestionsSuccess(a0) {
|
|
const suggestion = a0.suggestion;
|
|
c9601_3.suggestions.registration = {
|
|
suggestion,
|
|
source: a0.source,
|
|
fetched: true
|
|
};
|
|
if (suggestion?.username != null) {
|
|
c9601_3.validations.set(suggestion.username, {
|
|
taken: false
|
|
});
|
|
}
|
|
}
|
|
});
|
|
export default uniqueUsernamesStore;
|