use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method sendCallback.
public void sendCallback(final boolean cache, final MessageObject messageObject, final TLRPC.KeyboardButton button, TLRPC.InputCheckPasswordSRP srp, TwoStepVerificationActivity passwordFragment, final ChatActivity parentFragment) {
if (messageObject == null || button == null || parentFragment == null) {
return;
}
final boolean cacheFinal;
int type;
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
cacheFinal = false;
type = 3;
} else if (button instanceof TLRPC.TL_keyboardButtonGame) {
cacheFinal = false;
type = 1;
} else {
cacheFinal = cache;
if (button instanceof TLRPC.TL_keyboardButtonBuy) {
type = 2;
} else {
type = 0;
}
}
final String key = messageObject.getDialogId() + "_" + messageObject.getId() + "_" + Utilities.bytesToHex(button.data) + "_" + type;
waitingForCallback.put(key, true);
TLObject[] request = new TLObject[1];
RequestDelegate requestDelegate = (response, error) -> AndroidUtilities.runOnUIThread(() -> {
waitingForCallback.remove(key);
if (cacheFinal && response == null) {
sendCallback(false, messageObject, button, parentFragment);
} else if (response != null) {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
passwordFragment.finishFragment();
}
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
if (response instanceof TLRPC.TL_urlAuthResultRequest) {
TLRPC.TL_urlAuthResultRequest res = (TLRPC.TL_urlAuthResultRequest) response;
parentFragment.showRequestUrlAlert(res, (TLRPC.TL_messages_requestUrlAuth) request[0], button.url, false);
} else if (response instanceof TLRPC.TL_urlAuthResultAccepted) {
TLRPC.TL_urlAuthResultAccepted res = (TLRPC.TL_urlAuthResultAccepted) response;
AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
} else if (response instanceof TLRPC.TL_urlAuthResultDefault) {
TLRPC.TL_urlAuthResultDefault res = (TLRPC.TL_urlAuthResultDefault) response;
AlertsCreator.showOpenUrlAlert(parentFragment, button.url, false, true);
}
} else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
if (response instanceof TLRPC.TL_payments_paymentForm) {
final TLRPC.TL_payments_paymentForm form = (TLRPC.TL_payments_paymentForm) response;
getMessagesController().putUsers(form.users, false);
parentFragment.presentFragment(new PaymentFormActivity(form, messageObject, parentFragment));
} else if (response instanceof TLRPC.TL_payments_paymentReceipt) {
parentFragment.presentFragment(new PaymentFormActivity((TLRPC.TL_payments_paymentReceipt) response));
}
} else {
TLRPC.TL_messages_botCallbackAnswer res = (TLRPC.TL_messages_botCallbackAnswer) response;
if (!cacheFinal && res.cache_time != 0 && !button.requires_password) {
getMessagesStorage().saveBotCache(key, res);
}
if (res.message != null) {
long uid = messageObject.getFromChatId();
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
String name = null;
if (uid > 0) {
TLRPC.User user = getMessagesController().getUser(uid);
if (user != null) {
name = ContactsController.formatName(user.first_name, user.last_name);
}
} else {
TLRPC.Chat chat = getMessagesController().getChat(-uid);
if (chat != null) {
name = chat.title;
}
}
if (name == null) {
name = "bot";
}
if (res.alert) {
if (parentFragment.getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(name);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(res.message);
parentFragment.showDialog(builder.create());
} else {
parentFragment.showAlert(name, res.message);
}
} else if (res.url != null) {
if (parentFragment.getParentActivity() == null) {
return;
}
long uid = messageObject.getFromChatId();
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
TLRPC.User user = getMessagesController().getUser(uid);
boolean verified = user != null && user.verified;
if (button instanceof TLRPC.TL_keyboardButtonGame) {
TLRPC.TL_game game = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame ? messageObject.messageOwner.media.game : null;
if (game == null) {
return;
}
parentFragment.showOpenGameAlert(game, messageObject, res.url, !verified && MessagesController.getNotificationsSettings(currentAccount).getBoolean("askgame_" + uid, true), uid);
} else {
AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
}
}
}
} else if (error != null) {
if (parentFragment.getParentActivity() == null) {
return;
}
if ("PASSWORD_HASH_INVALID".equals(error.text)) {
if (srp == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(LocaleController.getString("BotOwnershipTransfer", R.string.BotOwnershipTransfer));
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferReadyAlertText", R.string.BotOwnershipTransferReadyAlertText)));
builder.setPositiveButton(LocaleController.getString("BotOwnershipTransferChangeOwner", R.string.BotOwnershipTransferChangeOwner), (dialogInterface, i) -> {
TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
fragment.setDelegate(password -> sendCallback(cache, messageObject, button, password, fragment, parentFragment));
parentFragment.presentFragment(fragment);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
}
} else if ("PASSWORD_MISSING".equals(error.text) || error.text.startsWith("PASSWORD_TOO_FRESH_") || error.text.startsWith("SESSION_TOO_FRESH_")) {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(LocaleController.getString("EditAdminTransferAlertTitle", R.string.EditAdminTransferAlertTitle));
LinearLayout linearLayout = new LinearLayout(parentFragment.getParentActivity());
linearLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(2), AndroidUtilities.dp(24), 0);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
TextView messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferAlertText", R.string.BotOwnershipTransferAlertText)));
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
LinearLayout linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
ImageView dotImageView = new ImageView(parentFragment.getParentActivity());
dotImageView.setImageResource(R.drawable.list_circle);
dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText1", R.string.EditAdminTransferAlertText1)));
if (LocaleController.isRTL) {
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
} else {
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
dotImageView = new ImageView(parentFragment.getParentActivity());
dotImageView.setImageResource(R.drawable.list_circle);
dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText2", R.string.EditAdminTransferAlertText2)));
if (LocaleController.isRTL) {
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
} else {
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if ("PASSWORD_MISSING".equals(error.text)) {
builder.setPositiveButton(LocaleController.getString("EditAdminTransferSetPassword", R.string.EditAdminTransferSetPassword), (dialogInterface, i) -> parentFragment.presentFragment(new TwoStepVerificationSetupActivity(TwoStepVerificationSetupActivity.TYPE_INTRO, null)));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
} else {
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(LocaleController.getString("EditAdminTransferAlertText3", R.string.EditAdminTransferAlertText3));
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
}
parentFragment.showDialog(builder.create());
} else if ("SRP_ID_INVALID".equals(error.text)) {
TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance(currentAccount).sendRequest(getPasswordReq, (response2, error2) -> AndroidUtilities.runOnUIThread(() -> {
if (error2 == null) {
TLRPC.TL_account_password currentPassword = (TLRPC.TL_account_password) response2;
passwordFragment.setCurrentPasswordInfo(null, currentPassword);
TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
sendCallback(cache, messageObject, button, passwordFragment.getNewSrpPassword(), passwordFragment, parentFragment);
}
}), ConnectionsManager.RequestFlagWithoutLogin);
} else {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
passwordFragment.finishFragment();
}
}
}
});
if (cacheFinal) {
getMessagesStorage().getBotCache(key, requestDelegate);
} else {
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
TLRPC.TL_messages_requestUrlAuth req = new TLRPC.TL_messages_requestUrlAuth();
req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
req.msg_id = messageObject.getId();
req.button_id = button.button_id;
req.flags |= 2;
request[0] = req;
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
} else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
if ((messageObject.messageOwner.media.flags & 4) == 0) {
TLRPC.TL_payments_getPaymentForm req = new TLRPC.TL_payments_getPaymentForm();
req.msg_id = messageObject.getId();
req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("bg_color", Theme.getColor(Theme.key_windowBackgroundWhite));
jsonObject.put("text_color", Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
jsonObject.put("hint_color", Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
jsonObject.put("link_color", Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
jsonObject.put("button_color", Theme.getColor(Theme.key_featuredStickers_addButton));
jsonObject.put("button_text_color", Theme.getColor(Theme.key_featuredStickers_buttonText));
req.theme_params = new TLRPC.TL_dataJSON();
req.theme_params.data = jsonObject.toString();
req.flags |= 1;
} catch (Exception e) {
FileLog.e(e);
}
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
} else {
TLRPC.TL_payments_getPaymentReceipt req = new TLRPC.TL_payments_getPaymentReceipt();
req.msg_id = messageObject.messageOwner.media.receipt_msg_id;
req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
}
} else {
TLRPC.TL_messages_getBotCallbackAnswer req = new TLRPC.TL_messages_getBotCallbackAnswer();
req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
req.msg_id = messageObject.getId();
req.game = button instanceof TLRPC.TL_keyboardButtonGame;
if (button.requires_password) {
req.password = req.password = srp != null ? srp : new TLRPC.TL_inputCheckPasswordEmpty();
;
req.flags |= 4;
}
if (button.data != null) {
req.flags |= 1;
req.data = button.data;
}
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
}
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createReportAlert.
public static void createReportAlert(final Context context, final long dialog_id, final int messageId, final BaseFragment parentFragment, Theme.ResourcesProvider resourcesProvider, Runnable hideDim) {
if (context == null || parentFragment == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(context, true, resourcesProvider);
builder.setDimBehind(hideDim == null);
builder.setOnPreDismissListener(di -> {
if (hideDim != null) {
hideDim.run();
}
});
builder.setTitle(LocaleController.getString("ReportChat", R.string.ReportChat), true);
CharSequence[] items;
int[] icons;
if (messageId != 0) {
items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
} else {
items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatFakeAccount", R.string.ReportChatFakeAccount), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_fake, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
}
builder.setItems(items, icons, (dialogInterface, i) -> {
if (messageId == 0 && (i == 0 || i == 2 || i == 3 || i == 4) && parentFragment instanceof ChatActivity) {
((ChatActivity) parentFragment).openReportChat(i);
return;
} else if (messageId == 0 && (i == 5 || i == 1) || messageId != 0 && i == 4) {
if (parentFragment instanceof ChatActivity) {
AndroidUtilities.requestAdjustNothing(parentFragment.getParentActivity(), parentFragment.getClassGuid());
}
parentFragment.showDialog(new ReportAlert(context, i == 4 ? 5 : i) {
@Override
public void dismissInternal() {
super.dismissInternal();
if (parentFragment instanceof ChatActivity) {
((ChatActivity) parentFragment).checkAdjustResize();
}
}
@Override
protected void onSend(int type, String message) {
ArrayList<Integer> ids = new ArrayList<>();
if (messageId != 0) {
ids.add(messageId);
}
TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
sendReport(peer, type, message, ids);
if (parentFragment instanceof ChatActivity) {
((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
}
}
});
return;
}
TLObject req;
TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
if (messageId != 0) {
TLRPC.TL_messages_report request = new TLRPC.TL_messages_report();
request.peer = peer;
request.id.add(messageId);
request.message = "";
if (i == 0) {
request.reason = new TLRPC.TL_inputReportReasonSpam();
} else if (i == 1) {
request.reason = new TLRPC.TL_inputReportReasonViolence();
} else if (i == 2) {
request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
} else if (i == 3) {
request.reason = new TLRPC.TL_inputReportReasonPornography();
}
req = request;
} else {
TLRPC.TL_account_reportPeer request = new TLRPC.TL_account_reportPeer();
request.peer = peer;
request.message = "";
if (i == 0) {
request.reason = new TLRPC.TL_inputReportReasonSpam();
} else if (i == 1) {
request.reason = new TLRPC.TL_inputReportReasonFake();
} else if (i == 2) {
request.reason = new TLRPC.TL_inputReportReasonViolence();
} else if (i == 3) {
request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
} else if (i == 4) {
request.reason = new TLRPC.TL_inputReportReasonPornography();
}
req = request;
}
ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {
});
if (parentFragment instanceof ChatActivity) {
((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
} else {
BulletinFactory.of(parentFragment).createReportSent(resourcesProvider).show();
}
});
BottomSheet sheet = builder.create();
parentFragment.showDialog(sheet);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method onOwnerChaged.
private void onOwnerChaged(TLRPC.User user) {
undoView.showWithAction(-chatId, isChannel ? UndoView.ACTION_OWNER_TRANSFERED_CHANNEL : UndoView.ACTION_OWNER_TRANSFERED_GROUP, user);
boolean foundAny = false;
currentChat.creator = false;
for (int a = 0; a < 3; a++) {
LongSparseArray<TLObject> map;
ArrayList<TLObject> arrayList;
boolean found = false;
if (a == 0) {
map = contactsMap;
arrayList = contacts;
} else if (a == 1) {
map = botsMap;
arrayList = bots;
} else {
map = participantsMap;
arrayList = participants;
}
TLObject object = map.get(user.id);
if (object instanceof TLRPC.ChannelParticipant) {
TLRPC.TL_channelParticipantCreator creator = new TLRPC.TL_channelParticipantCreator();
creator.peer = new TLRPC.TL_peerUser();
creator.peer.user_id = user.id;
map.put(user.id, creator);
int index = arrayList.indexOf(object);
if (index >= 0) {
arrayList.set(index, creator);
}
found = true;
foundAny = true;
}
long selfUserId = getUserConfig().getClientUserId();
object = map.get(selfUserId);
if (object instanceof TLRPC.ChannelParticipant) {
TLRPC.TL_channelParticipantAdmin admin = new TLRPC.TL_channelParticipantAdmin();
admin.peer = new TLRPC.TL_peerUser();
admin.peer.user_id = selfUserId;
admin.self = true;
admin.inviter_id = selfUserId;
admin.promoted_by = selfUserId;
admin.date = (int) (System.currentTimeMillis() / 1000);
admin.admin_rights = new TLRPC.TL_chatAdminRights();
admin.admin_rights.change_info = admin.admin_rights.post_messages = admin.admin_rights.edit_messages = admin.admin_rights.delete_messages = admin.admin_rights.ban_users = admin.admin_rights.invite_users = admin.admin_rights.pin_messages = admin.admin_rights.add_admins = true;
if (!isChannel) {
admin.admin_rights.manage_call = true;
}
map.put(selfUserId, admin);
int index = arrayList.indexOf(object);
if (index >= 0) {
arrayList.set(index, admin);
}
found = true;
}
if (found) {
Collections.sort(arrayList, (lhs, rhs) -> {
int type1 = getChannelAdminParticipantType(lhs);
int type2 = getChannelAdminParticipantType(rhs);
if (type1 > type2) {
return 1;
} else if (type1 < type2) {
return -1;
}
return 0;
});
}
}
if (!foundAny) {
TLRPC.TL_channelParticipantCreator creator = new TLRPC.TL_channelParticipantCreator();
creator.peer = new TLRPC.TL_peerUser();
creator.peer.user_id = user.id;
participantsMap.put(user.id, creator);
participants.add(creator);
sortAdmins(participants);
updateRows();
}
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didChangeOwner(user);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method loadChatParticipants.
private void loadChatParticipants(int offset, int count, boolean reset) {
Log.i("chat users", "loadChatParticipants(" + offset + ", " + count + ", " + reset + ")");
if (!ChatObject.isChannel(currentChat)) {
loadingUsers = false;
participants.clear();
bots.clear();
contacts.clear();
participantsMap.clear();
contactsMap.clear();
botsMap.clear();
if (type == TYPE_ADMIN) {
if (info != null) {
for (int a = 0, size = info.participants.participants.size(); a < size; a++) {
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
if (participant instanceof TLRPC.TL_chatParticipantCreator || participant instanceof TLRPC.TL_chatParticipantAdmin) {
participants.add(participant);
}
participantsMap.put(participant.user_id, participant);
}
}
} else if (type == TYPE_USERS) {
if (info != null) {
long selfUserId = getUserConfig().clientUserId;
for (int a = 0, size = info.participants.participants.size(); a < size; a++) {
TLRPC.ChatParticipant participant = info.participants.participants.get(a);
if (selectType != SELECT_TYPE_MEMBERS && participant.user_id == selfUserId) {
continue;
}
if (ignoredUsers != null && ignoredUsers.indexOfKey(participant.user_id) >= 0) {
continue;
}
if (selectType == SELECT_TYPE_ADMIN) {
if (getContactsController().isContact(participant.user_id)) {
contacts.add(participant);
contactsMap.put(participant.user_id, participant);
} else if (!UserObject.isDeleted(getMessagesController().getUser(participant.user_id))) {
participants.add(participant);
participantsMap.put(participant.user_id, participant);
}
} else {
if (getContactsController().isContact(participant.user_id)) {
contacts.add(participant);
contactsMap.put(participant.user_id, participant);
} else {
TLRPC.User user = getMessagesController().getUser(participant.user_id);
if (user != null && user.bot) {
bots.add(participant);
botsMap.put(participant.user_id, participant);
} else {
participants.add(participant);
participantsMap.put(participant.user_id, participant);
}
}
}
}
}
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
updateRows();
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
} else {
loadingUsers = true;
if (emptyView != null) {
emptyView.showProgress(true, false);
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
final ArrayList<TLRPC.TL_channels_getParticipants> requests = loadChatParticipantsRequests(offset, count, reset);
final ArrayList<TLRPC.TL_channels_channelParticipants> responses = new ArrayList<>();
Log.i("chat users", "requests.size() = " + requests.size());
final Runnable onRequestsEnd = () -> {
for (int i = 0; i < requests.size(); ++i) {
TLRPC.TL_channels_getParticipants req = requests.get(i);
TLRPC.TL_channels_channelParticipants res = responses.get(i);
if (req == null || res == null)
continue;
if (type == TYPE_ADMIN) {
getMessagesController().processLoadedAdminsResponse(chatId, res);
}
getMessagesController().putUsers(res.users, false);
getMessagesController().putChats(res.chats, false);
long selfId = getUserConfig().getClientUserId();
if (selectType != SELECT_TYPE_MEMBERS) {
for (int a = 0; a < res.participants.size(); a++) {
if (MessageObject.getPeerId(res.participants.get(a).peer) == selfId) {
res.participants.remove(a);
break;
}
}
}
ArrayList<TLObject> objects;
LongSparseArray<TLObject> map;
if (type == TYPE_USERS) {
delayResults--;
if (req.filter instanceof TLRPC.TL_channelParticipantsContacts) {
objects = contacts;
map = contactsMap;
} else if (req.filter instanceof TLRPC.TL_channelParticipantsBots) {
objects = bots;
map = botsMap;
} else {
objects = participants;
map = participantsMap;
}
} else {
objects = participants;
map = participantsMap;
participantsMap.clear();
}
objects.clear();
objects.addAll(res.participants);
for (int a = 0, size = res.participants.size(); a < size; a++) {
TLRPC.ChannelParticipant participant = res.participants.get(a);
if (participant.user_id == selfId) {
objects.remove(participant);
} else {
map.put(MessageObject.getPeerId(participant.peer), participant);
}
}
if (type == TYPE_USERS) {
for (int a = 0, N = participants.size(); a < N; a++) {
TLObject object = participants.get(a);
if (!(object instanceof TLRPC.ChannelParticipant)) {
participants.remove(a);
a--;
N--;
continue;
}
TLRPC.ChannelParticipant participant = (TLRPC.ChannelParticipant) object;
long peerId = MessageObject.getPeerId(participant.peer);
boolean remove = false;
if (contactsMap.get(peerId) != null || botsMap.get(peerId) != null) {
remove = true;
} else if (selectType == SELECT_TYPE_ADMIN && peerId > 0 && UserObject.isDeleted(getMessagesController().getUser(peerId))) {
remove = true;
} else if (ignoredUsers != null && ignoredUsers.indexOfKey(peerId) >= 0) {
remove = true;
}
if (remove) {
participants.remove(a);
participantsMap.remove(peerId);
a--;
N--;
}
}
}
try {
if ((type == TYPE_BANNED || type == TYPE_KICKED || type == TYPE_USERS) && currentChat != null && currentChat.megagroup && info instanceof TLRPC.TL_channelFull && info.participants_count <= 200) {
sortUsers(objects);
} else if (type == TYPE_ADMIN) {
sortAdmins(participants);
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (type != TYPE_USERS || delayResults <= 0) {
showItemsAnimated(listViewAdapter != null ? listViewAdapter.getItemCount() : 0);
loadingUsers = false;
firstLoaded = true;
}
updateRows();
if (listViewAdapter != null) {
listView.setAnimateEmptyView(openTransitionStarted, 0);
listViewAdapter.notifyDataSetChanged();
if (emptyView != null && listViewAdapter.getItemCount() == 0 && firstLoaded) {
emptyView.showProgress(false, true);
}
}
resumeDelayedFragmentAnimation();
};
AtomicInteger responsesReceived = new AtomicInteger(0);
for (int i = 0; i < requests.size(); ++i) {
responses.add(null);
final int index = i;
int reqId = getConnectionsManager().sendRequest(requests.get(index), (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error == null && response instanceof TLRPC.TL_channels_channelParticipants)
responses.set(index, (TLRPC.TL_channels_channelParticipants) response);
responsesReceived.getAndIncrement();
if (responsesReceived.get() == requests.size()) {
onRequestsEnd.run();
}
}));
getConnectionsManager().bindRequestToGuid(reqId, classGuid);
}
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method removeParticipants.
private void removeParticipants(long peerId) {
boolean updated = false;
DiffCallback savedState = saveState();
for (int a = 0; a < 3; a++) {
LongSparseArray<TLObject> map;
ArrayList<TLObject> arrayList;
if (a == 0) {
map = contactsMap;
arrayList = contacts;
} else if (a == 1) {
map = botsMap;
arrayList = bots;
} else {
map = participantsMap;
arrayList = participants;
}
TLObject p = map.get(peerId);
if (p != null) {
map.remove(peerId);
arrayList.remove(p);
updated = true;
if (type == TYPE_BANNED) {
info.kicked_count--;
}
}
}
if (updated) {
updateListAnimated(savedState);
}
if (listView.getAdapter() == searchListViewAdapter) {
searchListViewAdapter.removeUserId(peerId);
}
}
Aggregations