use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method showFieldPanel.
public void showFieldPanel(boolean show, MessageObject messageObjectToReply, MessageObject messageObjectToEdit, ArrayList<MessageObject> messageObjectsToForward, TLRPC.WebPage webPage, boolean notify, int scheduleDate, boolean cancel, boolean animated) {
if (chatActivityEnterView == null) {
return;
}
boolean showHint = false;
if (show) {
if (messageObjectToReply == null && messageObjectsToForward == null && messageObjectToEdit == null && webPage == null) {
return;
}
hideHints(false);
if (searchItem != null && actionBar.isSearchFieldVisible()) {
actionBar.closeSearchField(false);
chatActivityEnterView.setFieldFocused();
AndroidUtilities.runOnUIThread(() -> {
if (chatActivityEnterView != null) {
chatActivityEnterView.openKeyboard();
}
}, 100);
}
boolean openKeyboard = false;
if (messageObjectToReply != null && messageObjectToReply.getDialogId() != dialog_id) {
messageObjectsToForward = new ArrayList<>();
messageObjectsToForward.add(messageObjectToReply);
messageObjectToReply = null;
openKeyboard = true;
}
chatActivityEnterTopView.setEditMode(false);
if (messageObjectToEdit != null) {
forwardingMessages = null;
if (threadMessageId == 0) {
replyingMessageObject = null;
chatActivityEnterView.setReplyingMessageObject(null);
}
editingMessageObject = messageObjectToEdit;
final boolean mediaEmpty = messageObjectToEdit.isMediaEmpty();
chatActivityEnterView.setEditingMessageObject(messageObjectToEdit, !mediaEmpty);
if (foundWebPage != null) {
return;
}
chatActivityEnterView.setForceShowSendButton(false, false);
final boolean canEditMedia = messageObjectToEdit.canEditMedia();
if (!mediaEmpty && canEditMedia) {
String editButtonText = null;
String replaceButtonText;
if (messageObjectToEdit.isPhoto()) {
editButtonText = LocaleController.getString("EditMessageEditPhoto", R.string.EditMessageEditPhoto);
replaceButtonText = LocaleController.getString("EditMessageReplacePhoto", R.string.EditMessageReplacePhoto);
} else if (messageObjectToEdit.isVideo()) {
editButtonText = LocaleController.getString("EditMessageEditVideo", R.string.EditMessageEditVideo);
replaceButtonText = LocaleController.getString("EditMessageReplaceVideo", R.string.EditMessageReplaceVideo);
} else if (messageObjectToEdit.isGif()) {
replaceButtonText = LocaleController.getString("EditMessageReplaceGif", R.string.EditMessageReplaceGif);
} else if (messageObjectToEdit.isMusic()) {
replaceButtonText = LocaleController.getString("EditMessageReplaceAudio", R.string.EditMessageReplaceAudio);
} else {
replaceButtonText = LocaleController.getString("EditMessageReplaceFile", R.string.EditMessageReplaceFile);
}
final ChatActivityEnterTopView.EditViewButton[] buttons = chatActivityEnterTopView.getEditView().getButtons();
buttons[0].setEditButton(editButtonText != null);
buttons[0].getTextView().setText(editButtonText != null ? editButtonText : replaceButtonText);
buttons[0].getImageView().setImageResource(editButtonText != null ? R.drawable.msg_photoeditor : R.drawable.msg_replace);
buttons[1].setVisibility(editButtonText != null ? View.VISIBLE : View.GONE);
if (editButtonText != null) {
buttons[1].getTextView().setText(replaceButtonText);
}
chatActivityEnterTopView.setEditMode(true);
} else {
replyIconImageView.setImageResource(R.drawable.group_edit);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrEditing", R.string.AccDescrEditing));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelEdit", R.string.AccDescrCancelEdit));
if (mediaEmpty) {
replyNameTextView.setText(LocaleController.getString("EditMessage", R.string.EditMessage));
} else {
replyNameTextView.setText(LocaleController.getString("EditCaption", R.string.EditCaption));
}
if (canEditMedia) {
replyObjectTextView.setText(LocaleController.getString("EditMessageMedia", R.string.EditMessageMedia));
} else if (messageObjectToEdit.messageText != null || messageObjectToEdit.caption != null) {
String mess = messageObjectToEdit.caption != null ? messageObjectToEdit.caption.toString() : messageObjectToEdit.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
Spannable cs = new SpannableStringBuilder(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
MediaDataController.addTextStyleRuns(messageObjectToEdit, cs);
replyObjectTextView.setText(cs);
}
}
} else if (messageObjectToReply != null) {
forwardingMessages = null;
editingMessageObject = null;
replyingMessageObject = messageObjectToReply;
chatActivityEnterView.setReplyingMessageObject(messageObjectToReply);
chatActivityEnterView.setEditingMessageObject(null, false);
if (foundWebPage != null) {
return;
}
String restrictionReason = MessagesController.getRestrictionReason(messageObjectToReply.messageOwner.restriction_reason);
chatActivityEnterView.setForceShowSendButton(false, false);
String name;
if (messageObjectToReply.isFromUser()) {
if (messageObjectToReply.messageOwner.from_id.channel_id != 0) {
TLRPC.Chat chat = getMessagesController().getChat(messageObjectToReply.messageOwner.from_id.channel_id);
if (chat == null) {
return;
}
name = chat.title;
} else {
TLRPC.User user = getMessagesController().getUser(messageObjectToReply.messageOwner.from_id.user_id);
if (user == null) {
return;
}
name = UserObject.getUserName(user);
}
} else {
TLRPC.Chat chat;
if (ChatObject.isChannel(currentChat) && currentChat.megagroup && messageObjectToReply.isForwardedChannelPost()) {
chat = getMessagesController().getChat(messageObjectToReply.messageOwner.fwd_from.from_id.channel_id);
} else {
chat = getMessagesController().getChat(-messageObjectToReply.getSenderId());
}
if (chat == null) {
return;
}
name = chat.title;
}
replyIconImageView.setImageResource(R.drawable.msg_panel_reply);
replyNameTextView.setText(name);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrReplying", R.string.AccDescrReplying));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelReply", R.string.AccDescrCancelReply));
CharSequence replyObjectText = null;
if (!TextUtils.isEmpty(restrictionReason)) {
replyObjectText = restrictionReason;
} else if (messageObjectToReply.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
replyObjectText = Emoji.replaceEmoji(messageObjectToReply.messageOwner.media.game.title, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
} else if (messageObjectToReply.messageText != null || messageObjectToReply.caption != null) {
String mess = messageObjectToReply.caption != null ? messageObjectToReply.caption.toString() : messageObjectToReply.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
replyObjectText = Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
}
if (replyObjectText != null) {
if (replyObjectText instanceof Spannable)
MediaDataController.addTextStyleRuns(messageObjectToReply.messageOwner.entities, messageObjectToReply.caption != null ? messageObjectToReply.caption : messageObjectToReply.messageText, (Spannable) replyObjectText);
replyObjectTextView.setText(replyObjectText);
}
} else if (messageObjectsToForward != null) {
if (messageObjectsToForward.isEmpty()) {
return;
}
if (threadMessageId == 0) {
replyingMessageObject = null;
chatActivityEnterView.setReplyingMessageObject(null);
}
editingMessageObject = null;
chatActivityEnterView.setEditingMessageObject(null, false);
if (forwardingMessages == null) {
forwardingMessages = new ForwardingMessagesParams(messageObjectsToForward, dialog_id);
}
if (foundWebPage != null) {
return;
}
chatActivityEnterView.setForceShowSendButton(true, false);
ArrayList<Long> uids = new ArrayList<>();
replyIconImageView.setImageResource(R.drawable.msg_panel_forward);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrForwarding", R.string.AccDescrForwarding));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelForward", R.string.AccDescrCancelForward));
MessageObject object = messageObjectsToForward.get(0);
if (object.isFromUser()) {
uids.add(object.messageOwner.from_id.user_id);
} else {
TLRPC.Chat chat = getMessagesController().getChat(object.messageOwner.peer_id.channel_id);
if (ChatObject.isChannel(chat) && chat.megagroup && object.isForwardedChannelPost()) {
uids.add(-object.messageOwner.fwd_from.from_id.channel_id);
} else {
uids.add(-object.messageOwner.peer_id.channel_id);
}
}
int type = object.isAnimatedEmoji() || object.isDice() ? 0 : object.type;
for (int a = 1; a < messageObjectsToForward.size(); a++) {
object = messageObjectsToForward.get(a);
long uid;
if (object.isFromUser()) {
uid = object.messageOwner.from_id.user_id;
} else {
TLRPC.Chat chat = getMessagesController().getChat(object.messageOwner.peer_id.channel_id);
if (ChatObject.isChannel(chat) && chat.megagroup && object.isForwardedChannelPost()) {
uid = -object.messageOwner.fwd_from.from_id.channel_id;
} else {
uid = -object.messageOwner.peer_id.channel_id;
}
}
if (!uids.contains(uid)) {
uids.add(uid);
}
if (messageObjectsToForward.get(a).type != type) {
type = -1;
}
}
StringBuilder userNames = new StringBuilder();
for (int a = 0; a < uids.size(); a++) {
Long uid = uids.get(a);
TLRPC.Chat chat = null;
TLRPC.User user = null;
if (uid > 0) {
user = getMessagesController().getUser(uid);
} else {
chat = getMessagesController().getChat(-uid);
}
if (user == null && chat == null) {
continue;
}
if (uids.size() == 1) {
if (user != null) {
userNames.append(UserObject.getUserName(user));
} else {
userNames.append(chat.title);
}
} else if (uids.size() == 2 || userNames.length() == 0) {
if (userNames.length() > 0) {
userNames.append(", ");
}
if (user != null) {
if (!TextUtils.isEmpty(user.first_name)) {
userNames.append(user.first_name);
} else if (!TextUtils.isEmpty(user.last_name)) {
userNames.append(user.last_name);
} else {
userNames.append(" ");
}
} else {
userNames.append(chat.title);
}
} else {
userNames.append(" ");
userNames.append(LocaleController.formatPluralString("AndOther", uids.size() - 1));
break;
}
}
formwardingNameText = userNames;
if (type == -1 || type == 0 || type == 10 || type == 11) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardMessagesCount", messageObjectsToForward.size()));
} else if (type == 1) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardPhoto", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 4) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardLocation", messageObjectsToForward.size()));
} else if (type == 3) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardVideo", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 12) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardContact", messageObjectsToForward.size()));
} else if (type == 2) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardAudio", messageObjectsToForward.size()));
} else if (type == MessageObject.TYPE_ROUND_VIDEO) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardRound", messageObjectsToForward.size()));
} else if (type == 14) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardMusic", messageObjectsToForward.size()));
} else if (type == MessageObject.TYPE_STICKER || type == MessageObject.TYPE_ANIMATED_STICKER) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardSticker", messageObjectsToForward.size()));
} else if (type == 17) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardPoll", messageObjectsToForward.size()));
} else if (type == 8 || type == 9) {
if (messageObjectsToForward.size() == 1 & type == 9) {
messageObjectToReply = messageObjectsToForward.get(0);
}
if (messageObjectsToForward.size() == 1 && type == 8) {
replyNameTextView.setText(LocaleController.getString("AttachGif", R.string.AttachGif));
} else {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardFile", messageObjectsToForward.size()));
}
}
if (forwardingMessages.hideForwardSendersName) {
replyObjectTextView.setText(LocaleController.getString("HiddenSendersNameDescription", R.string.HiddenSendersNameDescription));
} else {
if ((type == -1 || type == 0 || type == 10 || type == 11) && (messageObjectsToForward.size() == 1 && messageObjectsToForward.get(0).messageText != null)) {
MessageObject messageObject = messageObjectsToForward.get(0);
CharSequence mess = SpannableStringBuilder.valueOf(messageObject.messageText);
MediaDataController.addTextStyleRuns(messageObjectsToForward.get(0), (Spannable) mess);
if (mess.length() > 150) {
mess = mess.subSequence(0, 150);
}
mess = AndroidUtilities.replaceNewLines(mess);
Spannable formatted = AndroidUtilities.formatSpannableSimple(LocaleController.getString("ForwardingFromNameAndMessage", R.string.ForwardingFromNameAndMessage), userNames, mess);
replyObjectTextView.setText(Emoji.replaceEmoji(formatted, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else {
replyObjectTextView.setText(LocaleController.formatString("ForwardingFromNames", R.string.ForwardingFromNames, userNames));
}
}
if (!SharedConfig.forwardingOptionsHintShown) {
showHint = true;
}
} else {
replyIconImageView.setImageResource(R.drawable.msg_link);
if (webPage instanceof TLRPC.TL_webPagePending) {
replyNameTextView.setText(LocaleController.getString("GettingLinkInfo", R.string.GettingLinkInfo));
replyObjectTextView.setText(pendingLinkSearchString);
} else {
if (webPage.site_name != null) {
replyNameTextView.setText(webPage.site_name);
} else if (webPage.title != null) {
replyNameTextView.setText(webPage.title);
} else {
replyNameTextView.setText(LocaleController.getString("LinkPreview", R.string.LinkPreview));
}
if (webPage.title != null) {
replyObjectTextView.setText(webPage.title);
} else if (webPage.description != null) {
replyObjectTextView.setText(webPage.description);
} else if (webPage.author != null) {
replyObjectTextView.setText(webPage.author);
} else {
replyObjectTextView.setText(webPage.display_url);
}
chatActivityEnterView.setWebPage(webPage, true);
}
}
MessageObject thumbMediaMessageObject;
if (messageObjectToReply != null) {
thumbMediaMessageObject = messageObjectToReply;
} else if (messageObjectToEdit != null) {
if (!chatActivityEnterTopView.isEditMode()) {
thumbMediaMessageObject = messageObjectToEdit;
} else {
thumbMediaMessageObject = null;
}
} else {
thumbMediaMessageObject = null;
}
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) replyNameTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) replyObjectTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) replyObjectHintTextView.getLayoutParams();
int cacheType = 1;
int size = 0;
TLRPC.PhotoSize photoSize = null;
TLRPC.PhotoSize thumbPhotoSize = null;
TLObject photoSizeObject = null;
if (thumbMediaMessageObject != null && TextUtils.isEmpty(MessagesController.getRestrictionReason(thumbMediaMessageObject.messageOwner.restriction_reason))) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs2, 320);
thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs2, AndroidUtilities.dp(40));
photoSizeObject = thumbMediaMessageObject.photoThumbsObject2;
if (photoSize == null) {
if (thumbMediaMessageObject.mediaExists) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, AndroidUtilities.getPhotoSize());
if (photoSize != null) {
size = photoSize.size;
}
cacheType = 0;
} else {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, 320);
}
thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, AndroidUtilities.dp(40));
photoSizeObject = thumbMediaMessageObject.photoThumbsObject;
}
}
if (photoSize == thumbPhotoSize) {
thumbPhotoSize = null;
}
if (photoSize == null || photoSize instanceof TLRPC.TL_photoSizeEmpty || photoSize.location instanceof TLRPC.TL_fileLocationUnavailable || thumbMediaMessageObject.isAnyKindOfSticker() || thumbMediaMessageObject.isSecretMedia() || thumbMediaMessageObject.isWebpageDocument()) {
replyImageView.setImageBitmap(null);
replyImageLocation = null;
replyImageLocationObject = null;
replyImageView.setVisibility(View.INVISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = AndroidUtilities.dp(52);
} else {
if (thumbMediaMessageObject.isRoundVideo()) {
replyImageView.setRoundRadius(AndroidUtilities.dp(17));
} else {
replyImageView.setRoundRadius(AndroidUtilities.dp(2));
}
replyImageSize = size;
replyImageCacheType = cacheType;
replyImageLocation = photoSize;
replyImageThumbLocation = thumbPhotoSize;
replyImageLocationObject = photoSizeObject;
replyImageView.setImage(ImageLocation.getForObject(replyImageLocation, photoSizeObject), "50_50", ImageLocation.getForObject(thumbPhotoSize, photoSizeObject), "50_50_b", null, size, cacheType, thumbMediaMessageObject);
replyImageView.setVisibility(View.VISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = AndroidUtilities.dp(96);
}
replyNameTextView.setLayoutParams(layoutParams1);
replyObjectTextView.setLayoutParams(layoutParams2);
replyObjectTextView.setLayoutParams(layoutParams3);
chatActivityEnterView.showTopView(true, openKeyboard);
} else {
if (replyingMessageObject == null && forwardingMessages == null && foundWebPage == null && editingMessageObject == null && !chatActivityEnterView.isTopViewVisible()) {
return;
}
if (replyingMessageObject != null && replyingMessageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyKeyboardForceReply) {
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
preferences.edit().putInt("answered_" + dialog_id, replyingMessageObject.getId()).commit();
}
if (foundWebPage != null) {
foundWebPage = null;
chatActivityEnterView.setWebPage(null, !cancel);
if (webPage != null && (replyingMessageObject != null || forwardingMessages != null || editingMessageObject != null)) {
showFieldPanel(true, replyingMessageObject, editingMessageObject, forwardingMessages != null ? forwardingMessages.messages : null, null, notify, scheduleDate, false, true);
return;
}
}
if (forwardingMessages != null) {
ArrayList<MessageObject> messagesToForward = new ArrayList<>();
forwardingMessages.getSelectedMessages(messagesToForward);
forwardMessages(messagesToForward, forwardingMessages.hideForwardSendersName, forwardingMessages.hideCaption, notify, scheduleDate != 0 && scheduleDate != 0x7ffffffe ? scheduleDate + 1 : scheduleDate);
forwardingMessages = null;
}
chatActivityEnterView.setForceShowSendButton(false, animated);
if (!waitingForSendingMessageLoad) {
chatActivityEnterView.hideTopView(animated);
}
chatActivityEnterView.setReplyingMessageObject(threadMessageObject);
chatActivityEnterView.setEditingMessageObject(null, false);
topViewWasVisible = 0;
replyingMessageObject = threadMessageObject;
editingMessageObject = null;
replyImageLocation = null;
replyImageLocationObject = null;
}
if (showHint) {
if (tapForForwardingOptionsHitRunnable == null) {
AndroidUtilities.runOnUIThread(tapForForwardingOptionsHitRunnable = () -> {
showTapForForwardingOptionsHit = !showTapForForwardingOptionsHit;
replyObjectTextView.setPivotX(0);
replyObjectHintTextView.setPivotX(0);
if (showTapForForwardingOptionsHit) {
replyObjectTextView.animate().alpha(0f).scaleX(0.98f).scaleY(0.98f).setDuration(150).start();
replyObjectHintTextView.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(150).start();
} else {
replyObjectTextView.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(150).start();
replyObjectHintTextView.animate().alpha(0f).scaleX(0.98f).scaleY(0.98f).setDuration(150).start();
}
AndroidUtilities.runOnUIThread(tapForForwardingOptionsHitRunnable, 6000);
}, 6000);
}
} else {
if (tapForForwardingOptionsHitRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(tapForForwardingOptionsHitRunnable);
tapForForwardingOptionsHitRunnable = null;
}
replyObjectTextView.setAlpha(1f);
replyObjectHintTextView.setAlpha(0);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method getAnyParticipant.
private TLObject getAnyParticipant(long userId) {
for (int a = 0; a < 3; a++) {
LongSparseArray<TLObject> map;
if (a == 0) {
map = contactsMap;
} else if (a == 1) {
map = botsMap;
} else {
map = participantsMap;
}
TLObject p = map.get(userId);
if (p != null) {
return p;
}
}
return null;
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method updateParticipantWithRights.
private void updateParticipantWithRights(TLRPC.ChannelParticipant channelParticipant, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, long user_id, boolean withDelegate) {
boolean delegateCalled = false;
for (int a = 0; a < 3; a++) {
LongSparseArray<TLObject> map;
if (a == 0) {
map = contactsMap;
} else if (a == 1) {
map = botsMap;
} else {
map = participantsMap;
}
TLObject p = map.get(MessageObject.getPeerId(channelParticipant.peer));
if (p instanceof TLRPC.ChannelParticipant) {
channelParticipant = (TLRPC.ChannelParticipant) p;
channelParticipant.admin_rights = rightsAdmin;
channelParticipant.banned_rights = rightsBanned;
if (withDelegate) {
channelParticipant.promoted_by = getUserConfig().getClientUserId();
}
}
if (withDelegate && p != null && !delegateCalled && delegate != null) {
delegateCalled = true;
delegate.didAddParticipantToList(user_id, p);
}
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatUsersActivity method openRightsEdit2.
private void openRightsEdit2(long peerId, int date, TLObject participant, TLRPC.TL_chatAdminRights adminRights, TLRPC.TL_chatBannedRights bannedRights, String rank, boolean canEditAdmin, int type, boolean removeFragment) {
boolean[] needShowBulletin = new boolean[1];
final boolean isAdmin = participant instanceof TLRPC.TL_channelParticipantAdmin || participant instanceof TLRPC.TL_chatParticipantAdmin;
ChatRightsEditActivity fragment = new ChatRightsEditActivity(peerId, chatId, adminRights, defaultBannedRights, bannedRights, rank, type, true, false) {
@Override
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
if (!isOpen && backward && needShowBulletin[0] && BulletinFactory.canShowBulletin(ChatUsersActivity.this)) {
if (peerId > 0) {
TLRPC.User user = getMessagesController().getUser(peerId);
if (user != null) {
BulletinFactory.createPromoteToAdminBulletin(ChatUsersActivity.this, user.first_name).show();
}
} else {
TLRPC.Chat chat = getMessagesController().getChat(-peerId);
if (chat != null) {
BulletinFactory.createPromoteToAdminBulletin(ChatUsersActivity.this, chat.title).show();
}
}
}
}
};
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
if (type == 0) {
for (int a = 0; a < participants.size(); a++) {
TLObject p = participants.get(a);
if (p instanceof TLRPC.ChannelParticipant) {
TLRPC.ChannelParticipant p2 = (TLRPC.ChannelParticipant) p;
if (MessageObject.getPeerId(p2.peer) == peerId) {
TLRPC.ChannelParticipant newPart;
if (rights == 1) {
newPart = new TLRPC.TL_channelParticipantAdmin();
} else {
newPart = new TLRPC.TL_channelParticipant();
}
newPart.admin_rights = rightsAdmin;
newPart.banned_rights = rightsBanned;
newPart.inviter_id = getUserConfig().getClientUserId();
if (peerId > 0) {
newPart.peer = new TLRPC.TL_peerUser();
newPart.peer.user_id = peerId;
} else {
newPart.peer = new TLRPC.TL_peerChannel();
newPart.peer.channel_id = -peerId;
}
newPart.date = date;
newPart.flags |= 4;
newPart.rank = rank;
participants.set(a, newPart);
break;
}
} else if (p instanceof TLRPC.ChatParticipant) {
TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) p;
TLRPC.ChatParticipant newParticipant;
if (rights == 1) {
newParticipant = new TLRPC.TL_chatParticipantAdmin();
} else {
newParticipant = new TLRPC.TL_chatParticipant();
}
newParticipant.user_id = chatParticipant.user_id;
newParticipant.date = chatParticipant.date;
newParticipant.inviter_id = chatParticipant.inviter_id;
int index = info.participants.participants.indexOf(chatParticipant);
if (index >= 0) {
info.participants.participants.set(index, newParticipant);
}
loadChatParticipants(0, 200);
}
}
if (rights == 1 && !isAdmin) {
needShowBulletin[0] = true;
}
} else if (type == 1) {
if (rights == 0) {
removeParticipants(peerId);
}
}
}
@Override
public void didChangeOwner(TLRPC.User user) {
onOwnerChaged(user);
}
});
presentFragment(fragment);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class TwoStepVerificationSetupActivity method setNewPassword.
private void setNewPassword(final boolean clear) {
if (clear && waitingForEmail && currentPassword.has_password) {
needShowProgress();
TLRPC.TL_account_cancelPasswordEmail req = new TLRPC.TL_account_cancelPasswordEmail();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
needHideProgress();
if (error == null) {
TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
currentPassword.has_recovery = false;
currentPassword.email_unconfirmed_pattern = "";
fragment.setCurrentPasswordParams(currentPassword, currentPasswordHash, currentSecretId, currentSecret);
fragment.setBlockingAlert(otherwiseReloginDays);
presentFragment(fragment, true);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didRemoveTwoStepPassword);
}
}));
return;
}
final String password = firstPassword;
TLRPC.TL_account_passwordInputSettings new_settings = new TLRPC.TL_account_passwordInputSettings();
if (clear) {
UserConfig.getInstance(currentAccount).resetSavedPassword();
currentSecret = null;
if (waitingForEmail) {
new_settings.flags = 2;
new_settings.email = "";
} else {
new_settings.flags = 3;
new_settings.hint = "";
new_settings.new_password_hash = new byte[0];
new_settings.new_algo = new TLRPC.TL_passwordKdfAlgoUnknown();
new_settings.email = "";
}
} else {
if (hint == null && currentPassword != null) {
hint = currentPassword.hint;
}
if (hint == null) {
hint = "";
}
if (password != null) {
new_settings.flags |= 1;
new_settings.hint = hint;
new_settings.new_algo = currentPassword.new_algo;
}
if (email.length() > 0) {
new_settings.flags |= 2;
new_settings.email = email.trim();
}
}
TLObject request;
if (emailCode != null) {
TLRPC.TL_auth_recoverPassword req = new TLRPC.TL_auth_recoverPassword();
req.code = emailCode;
req.new_settings = new_settings;
req.flags |= 1;
request = req;
} else {
TLRPC.TL_account_updatePasswordSettings req = new TLRPC.TL_account_updatePasswordSettings();
if (currentPasswordHash == null || currentPasswordHash.length == 0 || clear && waitingForEmail) {
req.password = new TLRPC.TL_inputCheckPasswordEmpty();
}
req.new_settings = new_settings;
request = req;
}
needShowProgress();
Utilities.globalQueue.postRunnable(() -> {
if (request instanceof TLRPC.TL_account_updatePasswordSettings) {
TLRPC.TL_account_updatePasswordSettings req = (TLRPC.TL_account_updatePasswordSettings) request;
if (req.password == null) {
req.password = getNewSrpPassword();
}
}
byte[] newPasswordBytes;
byte[] newPasswordHash;
if (!clear && password != null) {
newPasswordBytes = AndroidUtilities.getStringBytes(password);
if (currentPassword.new_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) currentPassword.new_algo;
newPasswordHash = SRPHelper.getX(newPasswordBytes, algo);
} else {
newPasswordHash = null;
}
} else {
newPasswordBytes = null;
newPasswordHash = null;
}
RequestDelegate requestDelegate = (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error != null && "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) {
currentPassword = (TLRPC.TL_account_password) response2;
TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
setNewPassword(clear);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
}
}), ConnectionsManager.RequestFlagWithoutLogin);
return;
}
needHideProgress();
if (error == null && (response instanceof TLRPC.TL_boolTrue || response instanceof TLRPC.auth_Authorization)) {
getMessagesController().removeSuggestion(0, "VALIDATE_PASSWORD");
if (clear) {
for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
fragmentsToClose.get(a).removeSelfFromStack();
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didRemoveTwoStepPassword);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword);
finishFragment();
} else {
if (getParentActivity() == null) {
return;
}
if (currentPassword.has_password) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
fragmentsToClose.get(a).removeSelfFromStack();
}
TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
currentPassword.has_password = true;
if (!currentPassword.has_recovery) {
currentPassword.has_recovery = !TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern);
}
fragment.setCurrentPasswordParams(currentPassword, newPasswordHash != null ? newPasswordHash : currentPasswordHash, currentSecretId, currentSecret);
fragment.setBlockingAlert(otherwiseReloginDays);
presentFragment(fragment, true);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
});
if (password == null && currentPassword != null && currentPassword.has_password) {
builder.setMessage(LocaleController.getString("YourEmailSuccessText", R.string.YourEmailSuccessText));
} else {
builder.setMessage(LocaleController.getString("YourPasswordChangedSuccessText", R.string.YourPasswordChangedSuccessText));
}
builder.setTitle(LocaleController.getString("YourPasswordSuccess", R.string.YourPasswordSuccess));
Dialog dialog = showDialog(builder.create());
if (dialog != null) {
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
}
} else {
for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
fragmentsToClose.get(a).removeSelfFromStack();
}
currentPassword.has_password = true;
if (!currentPassword.has_recovery) {
currentPassword.has_recovery = !TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern);
}
if (closeAfterSet) {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged);
}
TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(TYPE_PASSWORD_SET, currentPassword);
fragment.setCurrentPasswordParams(newPasswordHash != null ? newPasswordHash : currentPasswordHash, currentSecretId, currentSecret, emailOnly);
fragment.closeAfterSet = closeAfterSet;
fragment.setBlockingAlert(otherwiseReloginDays);
presentFragment(fragment, true);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
}
}
} else if (error != null) {
if ("EMAIL_UNCONFIRMED".equals(error.text) || error.text.startsWith("EMAIL_UNCONFIRMED_")) {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged);
for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
fragmentsToClose.get(a).removeSelfFromStack();
}
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged, newPasswordHash, new_settings.new_algo, currentPassword.new_secure_algo, currentPassword.secure_random, email, hint, email, firstPassword);
currentPassword.email_unconfirmed_pattern = email;
TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(TwoStepVerificationSetupActivity.TYPE_EMAIL_CONFIRM, currentPassword);
fragment.setCurrentPasswordParams(newPasswordHash != null ? newPasswordHash : currentPasswordHash, currentSecretId, currentSecret, emailOnly);
fragment.closeAfterSet = closeAfterSet;
fragment.setBlockingAlert(otherwiseReloginDays);
presentFragment(fragment, true);
} else {
if ("EMAIL_INVALID".equals(error.text)) {
showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.getString("PasswordEmailInvalid", R.string.PasswordEmailInvalid));
} else if (error.text.startsWith("FLOOD_WAIT")) {
int time = Utilities.parseInt(error.text);
String timeString;
if (time < 60) {
timeString = LocaleController.formatPluralString("Seconds", time);
} else {
timeString = LocaleController.formatPluralString("Minutes", time / 60);
}
showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
} else {
showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
}
}
}
});
if (!clear) {
if (password != null && currentSecret != null && currentSecret.length == 32) {
if (currentPassword.new_secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) {
TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000 newAlgo = (TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) currentPassword.new_secure_algo;
byte[] passwordHash = Utilities.computePBKDF2(newPasswordBytes, newAlgo.salt);
byte[] key = new byte[32];
System.arraycopy(passwordHash, 0, key, 0, 32);
byte[] iv = new byte[16];
System.arraycopy(passwordHash, 32, iv, 0, 16);
byte[] encryptedSecret = new byte[32];
System.arraycopy(currentSecret, 0, encryptedSecret, 0, 32);
Utilities.aesCbcEncryptionByteArraySafe(encryptedSecret, key, iv, 0, encryptedSecret.length, 0, 1);
new_settings.new_secure_settings = new TLRPC.TL_secureSecretSettings();
new_settings.new_secure_settings.secure_algo = newAlgo;
new_settings.new_secure_settings.secure_secret = encryptedSecret;
new_settings.new_secure_settings.secure_secret_id = currentSecretId;
new_settings.flags |= 4;
}
}
if (currentPassword.new_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
if (password != null) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) currentPassword.new_algo;
new_settings.new_password_hash = SRPHelper.getVBytes(newPasswordBytes, algo);
if (new_settings.new_password_hash == null) {
TLRPC.TL_error error = new TLRPC.TL_error();
error.text = "ALGO_INVALID";
requestDelegate.run(null, error);
}
}
ConnectionsManager.getInstance(currentAccount).sendRequest(request, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
} else {
TLRPC.TL_error error = new TLRPC.TL_error();
error.text = "PASSWORD_HASH_INVALID";
requestDelegate.run(null, error);
}
} else {
ConnectionsManager.getInstance(currentAccount).sendRequest(request, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
}
});
}
Aggregations