mirror of https://github.com/NekoX-Dev/NekoX.git
bot token login
This commit is contained in:
parent
5e72c10925
commit
035d7fbbf2
|
@ -67,7 +67,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
public class DataQuery {
|
||||
|
||||
private int currentAccount;
|
||||
private static volatile DataQuery[] Instance = new DataQuery[8];
|
||||
private static volatile DataQuery[] Instance = new DataQuery[UserConfig.MAX_ACCOUNT_COUNT];
|
||||
public static DataQuery getInstance(int num) {
|
||||
DataQuery localInstance = Instance[num];
|
||||
if (localInstance == null) {
|
||||
|
@ -1111,7 +1111,7 @@ public class DataQuery {
|
|||
archivedStickersCount[type] = count;
|
||||
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.archivedStickersCountDidLoad, type);
|
||||
}
|
||||
} else {
|
||||
} else if(!UserConfig.getInstance(currentAccount).isBot) {
|
||||
TLRPC.TL_messages_getArchivedStickers req = new TLRPC.TL_messages_getArchivedStickers();
|
||||
req.limit = 0;
|
||||
req.masks = type == TYPE_MASK;
|
||||
|
@ -1219,7 +1219,7 @@ public class DataQuery {
|
|||
}
|
||||
processLoadedStickers(type, newStickerArray, true, date, hash);
|
||||
});
|
||||
} else {
|
||||
} else if(!UserConfig.getInstance(currentAccount).isBot) {
|
||||
if (type == TYPE_FEATURED) {
|
||||
TLRPC.TL_messages_allStickers response = new TLRPC.TL_messages_allStickers();
|
||||
response.hash = loadFeaturedHash;
|
||||
|
|
|
@ -61,6 +61,7 @@ public class UserConfig {
|
|||
public long pendingAppUpdateInstallTime;
|
||||
public long lastUpdateCheckTime;
|
||||
public long autoDownloadConfigLoadTime;
|
||||
public boolean isBot;
|
||||
|
||||
public volatile byte[] savedPasswordHash;
|
||||
public volatile byte[] savedSaltedPassword;
|
||||
|
@ -135,6 +136,7 @@ public class UserConfig {
|
|||
editor.putBoolean("notificationsSignUpSettingsLoaded", notificationsSignUpSettingsLoaded);
|
||||
editor.putLong("autoDownloadConfigLoadTime", autoDownloadConfigLoadTime);
|
||||
editor.putBoolean("hasValidDialogLoadIds", hasValidDialogLoadIds);
|
||||
editor.putBoolean("isBot", isBot);
|
||||
|
||||
editor.putInt("6migrateOffsetId", migrateOffsetId);
|
||||
if (migrateOffsetId != -1) {
|
||||
|
@ -272,6 +274,7 @@ public class UserConfig {
|
|||
notificationsSignUpSettingsLoaded = preferences.getBoolean("notificationsSignUpSettingsLoaded", false);
|
||||
autoDownloadConfigLoadTime = preferences.getLong("autoDownloadConfigLoadTime", 0);
|
||||
hasValidDialogLoadIds = preferences.contains("2dialogsLoadOffsetId") || preferences.getBoolean("hasValidDialogLoadIds", false);
|
||||
isBot = preferences.getBoolean("isBot",false);
|
||||
|
||||
try {
|
||||
String terms = preferences.getString("terms", null);
|
||||
|
@ -423,6 +426,7 @@ public class UserConfig {
|
|||
loginTime = (int) (System.currentTimeMillis() / 1000);
|
||||
lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60;
|
||||
lastHintsSyncTime = (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60;
|
||||
isBot = false;
|
||||
resetSavedPassword();
|
||||
boolean hasActivated = false;
|
||||
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
|
||||
|
|
|
@ -30617,6 +30617,27 @@ public class TLRPC {
|
|||
}
|
||||
}
|
||||
|
||||
public static class TL_auth_importBotAuthorization extends TLObject {
|
||||
public static int constructor = 0x67a3ff2c;
|
||||
|
||||
public int flags;
|
||||
public int api_id;
|
||||
public String api_hash;
|
||||
public String bot_auth_token;
|
||||
|
||||
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
|
||||
return TL_auth_authorization.TLdeserialize(stream, constructor, exception);
|
||||
}
|
||||
|
||||
public void serializeToStream(AbstractSerializedData stream) {
|
||||
stream.writeInt32(constructor);
|
||||
stream.writeInt32(flags);
|
||||
stream.writeInt32(api_id);
|
||||
stream.writeString(api_hash);
|
||||
stream.writeString(bot_auth_token);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TL_account_registerDevice extends TLObject {
|
||||
public static int constructor = 0x5cbea590;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.app.Activity;
|
|||
import android.app.Dialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
|
@ -51,6 +52,7 @@ import android.view.Gravity;
|
|||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -207,11 +209,112 @@ public class LoginActivity extends BaseFragment {
|
|||
if (onBackPressed()) {
|
||||
finishFragment();
|
||||
}
|
||||
} else if (id == 2) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(LocaleController.getString("BotLogin", R.string.BotLogin));
|
||||
|
||||
final EditTextBoldCursor editText = new EditTextBoldCursor(context) {
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY));
|
||||
}
|
||||
};
|
||||
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
||||
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
||||
editText.setHintText("Token");
|
||||
editText.setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
|
||||
editText.setSingleLine(true);
|
||||
editText.setFocusable(true);
|
||||
editText.setTransformHintToHeader(true);
|
||||
editText.setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
|
||||
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
editText.setBackgroundDrawable(null);
|
||||
editText.requestFocus();
|
||||
editText.setPadding(0, 0, 0, 0);
|
||||
builder.setView(editText);
|
||||
|
||||
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (getParentActivity() == null) {
|
||||
return;
|
||||
}
|
||||
String token = editText.getText().toString();
|
||||
|
||||
if (token.length() == 0) {
|
||||
needShowAlert(LocaleController.getString("AppName", R.string.AppName), LocaleController.getString("InvalidAccessToken", R.string.InvalidAccessToken));
|
||||
return;
|
||||
}
|
||||
|
||||
ConnectionsManager.getInstance(currentAccount).cleanup(false);
|
||||
final TLRPC.TL_auth_importBotAuthorization req = new TLRPC.TL_auth_importBotAuthorization ();
|
||||
|
||||
req.api_hash = BuildVars.APP_HASH;
|
||||
req.api_id = BuildVars.APP_ID;
|
||||
req.bot_auth_token = token;
|
||||
req.flags = 0;
|
||||
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
if (error == null) {
|
||||
TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization) response;
|
||||
ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id);
|
||||
UserConfig.getInstance(currentAccount).clearConfig();
|
||||
MessagesController.getInstance(currentAccount).cleanup();
|
||||
UserConfig.getInstance(currentAccount).isBot = true;
|
||||
UserConfig.getInstance(currentAccount).syncContacts = syncContacts;
|
||||
UserConfig.getInstance(currentAccount).setCurrentUser(res.user);
|
||||
UserConfig.getInstance(currentAccount).saveConfig(true);
|
||||
MessagesStorage.getInstance(currentAccount).cleanup(true);
|
||||
ArrayList<TLRPC.User> users = new ArrayList<>();
|
||||
users.add(res.user);
|
||||
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
|
||||
MessagesController.getInstance(currentAccount).putUser(res.user, false);
|
||||
ContactsController.getInstance(currentAccount).checkAppAccount();
|
||||
MessagesController.getInstance(currentAccount).getBlockedUsers(true);
|
||||
MessagesController.getInstance(currentAccount).checkProxyInfo(true);
|
||||
ConnectionsManager.getInstance(currentAccount).updateDcSettings();
|
||||
needFinishActivity();
|
||||
} else {
|
||||
if (error.text != null) {
|
||||
if (error.text.contains("ACCESS_TOKEN_INVALID")) {
|
||||
needShowAlert(LocaleController.getString("AppName", R.string.AppName), LocaleController.getString("InvalidAccessToken", R.string.InvalidAccessToken));
|
||||
} else if (error.text.startsWith("FLOOD_WAIT")) {
|
||||
needShowAlert(LocaleController.getString("AppName", R.string.AppName), LocaleController.getString("FloodWait", R.string.FloodWait));
|
||||
} else if (error.code != -1000) {
|
||||
needShowAlert(LocaleController.getString("AppName", R.string.AppName), error.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
needHideProgress(false);
|
||||
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagTryDifferentDc | ConnectionsManager.RequestFlagEnableUnauthorized);
|
||||
needShowProgress(reqId);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
editText.requestFocus();
|
||||
AndroidUtilities.showKeyboard(editText);
|
||||
}
|
||||
});
|
||||
if (editText != null) {
|
||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams();
|
||||
if (layoutParams != null) {
|
||||
if (layoutParams instanceof FrameLayout.LayoutParams) {
|
||||
((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL;
|
||||
}
|
||||
layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(24);
|
||||
layoutParams.height = AndroidUtilities.dp(36);
|
||||
editText.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ActionBarMenu menu = actionBar.createMenu();
|
||||
menu.addItem(2, R.drawable.list_bot);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
||||
doneProgressView = new ContextProgressView(context, 1);
|
||||
|
|
Loading…
Reference in New Issue