use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaDataController method saveDraftReplyMessage.
private void saveDraftReplyMessage(long dialogId, int threadId, TLRPC.Message message) {
if (message == null) {
return;
}
AndroidUtilities.runOnUIThread(() -> {
SparseArray<TLRPC.DraftMessage> threads = drafts.get(dialogId);
TLRPC.DraftMessage draftMessage = threads != null ? threads.get(threadId) : null;
if (draftMessage != null && draftMessage.reply_to_msg_id == message.id) {
SparseArray<TLRPC.Message> threads2 = draftMessages.get(dialogId);
if (threads2 == null) {
threads2 = new SparseArray<>();
draftMessages.put(dialogId, threads2);
}
threads2.put(threadId, message);
SerializedData serializedData = new SerializedData(message.getObjectSize());
message.serializeToStream(serializedData);
draftPreferences.edit().putString(threadId == 0 ? ("r_" + dialogId) : ("rt_" + dialogId + "_" + threadId), Utilities.bytesToHex(serializedData.toByteArray())).commit();
getNotificationCenter().postNotificationName(NotificationCenter.newDraftReceived, dialogId);
serializedData.cleanup();
}
});
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class PollCreateActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (quizOnly == 1) {
actionBar.setTitle(LocaleController.getString("NewQuiz", R.string.NewQuiz));
} else {
actionBar.setTitle(LocaleController.getString("NewPoll", R.string.NewPoll));
}
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
if (quizPoll && doneItem.getAlpha() != 1.0f) {
int checksCount = 0;
for (int a = 0; a < answersChecks.length; a++) {
if (!TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a])) && answersChecks[a]) {
checksCount++;
}
}
if (checksCount <= 0) {
showQuizHint();
}
return;
}
TLRPC.TL_messageMediaPoll poll = new TLRPC.TL_messageMediaPoll();
poll.poll = new TLRPC.TL_poll();
poll.poll.multiple_choice = multipleChoise;
poll.poll.quiz = quizPoll;
poll.poll.public_voters = !anonymousPoll;
poll.poll.question = ChatAttachAlertPollLayout.getFixedString(questionString).toString();
SerializedData serializedData = new SerializedData(10);
for (int a = 0; a < answers.length; a++) {
if (TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a]))) {
continue;
}
TLRPC.TL_pollAnswer answer = new TLRPC.TL_pollAnswer();
answer.text = ChatAttachAlertPollLayout.getFixedString(answers[a]).toString();
answer.option = new byte[1];
answer.option[0] = (byte) (48 + poll.poll.answers.size());
poll.poll.answers.add(answer);
if ((multipleChoise || quizPoll) && answersChecks[a]) {
serializedData.writeByte(answer.option[0]);
}
}
HashMap<String, String> params = new HashMap<>();
params.put("answers", Utilities.bytesToHex(serializedData.toByteArray()));
poll.results = new TLRPC.TL_pollResults();
CharSequence solution = ChatAttachAlertPollLayout.getFixedString(solutionString);
if (solution != null) {
poll.results.solution = solution.toString();
CharSequence[] message = new CharSequence[] { solution };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, true);
if (entities != null && !entities.isEmpty()) {
poll.results.solution_entities = entities;
}
if (!TextUtils.isEmpty(poll.results.solution)) {
poll.results.flags |= 16;
}
}
if (parentFragment.isInScheduleMode()) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), parentFragment.getDialogId(), (notify, scheduleDate) -> {
delegate.sendPoll(poll, params, notify, scheduleDate);
finishFragment();
});
} else {
delegate.sendPoll(poll, params, true, 0);
finishFragment();
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneItem = menu.addItem(done_button, LocaleController.getString("Create", R.string.Create).toUpperCase());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context) {
@Override
protected void requestChildOnScreen(View child, View focused) {
if (!(child instanceof PollEditTextCell)) {
return;
}
super.requestChildOnScreen(child, focused);
}
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
rectangle.bottom += AndroidUtilities.dp(60);
return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}
};
listView.setVerticalScrollBarEnabled(false);
((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
itemTouchHelper.attachToRecyclerView(listView);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (position == addAnswerRow) {
addNewField();
} else if (view instanceof TextCheckCell) {
TextCheckCell cell = (TextCheckCell) view;
boolean checked;
boolean wasChecksBefore = quizPoll;
if (position == anonymousRow) {
checked = anonymousPoll = !anonymousPoll;
} else if (position == multipleRow) {
checked = multipleChoise = !multipleChoise;
if (multipleChoise && quizPoll) {
int prevSolutionRow = solutionRow;
quizPoll = false;
updateRows();
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(quizRow);
if (holder != null) {
((TextCheckCell) holder.itemView).setChecked(false);
} else {
listAdapter.notifyItemChanged(quizRow);
}
listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
}
} else {
if (quizOnly != 0) {
return;
}
checked = quizPoll = !quizPoll;
int prevSolutionRow = solutionRow;
updateRows();
if (quizPoll) {
listAdapter.notifyItemRangeInserted(solutionRow, 2);
} else {
listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
}
if (quizPoll && multipleChoise) {
multipleChoise = false;
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(multipleRow);
if (holder != null) {
((TextCheckCell) holder.itemView).setChecked(false);
} else {
listAdapter.notifyItemChanged(multipleRow);
}
}
if (quizPoll) {
boolean was = false;
for (int a = 0; a < answersChecks.length; a++) {
if (was) {
answersChecks[a] = false;
} else if (answersChecks[a]) {
was = true;
}
}
}
}
if (hintShowed && !quizPoll) {
hintView.hide();
}
int count = listView.getChildCount();
for (int a = answerStartRow; a < answerStartRow + answersCount; a++) {
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(a);
if (holder != null && holder.itemView instanceof PollEditTextCell) {
PollEditTextCell pollEditTextCell = (PollEditTextCell) holder.itemView;
pollEditTextCell.setShowCheckBox(quizPoll, true);
pollEditTextCell.setChecked(answersChecks[a - answerStartRow], wasChecksBefore);
if (pollEditTextCell.getTop() > AndroidUtilities.dp(40) && position == quizRow && !hintShowed) {
hintView.showForView(pollEditTextCell.getCheckBox(), true);
hintShowed = true;
}
}
}
cell.setChecked(checked);
checkDoneButton();
}
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy != 0 && hintView != null) {
hintView.hide();
}
}
});
hintView = new HintView(context, 4);
hintView.setText(LocaleController.getString("PollTapToSelect", R.string.PollTapToSelect));
hintView.setAlpha(0.0f);
hintView.setVisibility(View.INVISIBLE);
frameLayout.addView(hintView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
checkDoneButton();
return fragmentView;
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method editMessage.
public void editMessage(MessageObject messageObject, TLRPC.TL_photo photo, VideoEditedInfo videoEditedInfo, TLRPC.TL_document document, String path, HashMap<String, String> params, boolean retry, Object parentObject) {
if (messageObject == null) {
return;
}
if (params == null) {
params = new HashMap<>();
}
TLRPC.Message newMsg = messageObject.messageOwner;
messageObject.cancelEditing = false;
try {
int type = -1;
DelayedMessage delayedMessage = null;
long peer = messageObject.getDialogId();
boolean supportsSendingNewEntities = true;
if (DialogObject.isEncryptedDialog(peer)) {
int encryptedId = DialogObject.getEncryptedChatId(peer);
TLRPC.EncryptedChat encryptedChat = getMessagesController().getEncryptedChat(encryptedId);
if (encryptedChat == null || AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) < 101) {
supportsSendingNewEntities = false;
}
}
if (retry) {
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage || messageObject.messageOwner.media == null || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
type = 1;
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
photo = (TLRPC.TL_photo) messageObject.messageOwner.media.photo;
type = 2;
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
document = (TLRPC.TL_document) messageObject.messageOwner.media.document;
if (MessageObject.isVideoDocument(document) || videoEditedInfo != null) {
type = 3;
} else {
type = 7;
}
videoEditedInfo = messageObject.videoEditedInfo;
}
params = newMsg.params;
if (parentObject == null && params != null && params.containsKey("parentObject")) {
parentObject = params.get("parentObject");
}
messageObject.editingMessage = newMsg.message;
messageObject.editingMessageEntities = newMsg.entities;
path = newMsg.attachPath;
} else {
messageObject.previousMedia = newMsg.media;
messageObject.previousMessage = newMsg.message;
messageObject.previousMessageEntities = newMsg.entities;
messageObject.previousAttachPath = newMsg.attachPath;
TLRPC.MessageMedia media = newMsg.media;
if (media == null) {
media = new TLRPC.TL_messageMediaEmpty();
}
SerializedData serializedDataCalc = new SerializedData(true);
writePreviousMessageData(newMsg, serializedDataCalc);
SerializedData prevMessageData = new SerializedData(serializedDataCalc.length());
writePreviousMessageData(newMsg, prevMessageData);
if (params == null) {
params = new HashMap<>();
}
params.put("prevMedia", Base64.encodeToString(prevMessageData.toByteArray(), Base64.DEFAULT));
prevMessageData.cleanup();
if (photo != null) {
newMsg.media = new TLRPC.TL_messageMediaPhoto();
newMsg.media.flags |= 3;
newMsg.media.photo = photo;
type = 2;
if (path != null && path.length() > 0 && path.startsWith("http")) {
newMsg.attachPath = path;
} else {
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
newMsg.attachPath = FileLoader.getPathToAttach(location1, true).toString();
}
} else if (document != null) {
newMsg.media = new TLRPC.TL_messageMediaDocument();
newMsg.media.flags |= 3;
newMsg.media.document = document;
if (MessageObject.isVideoDocument(document) || videoEditedInfo != null) {
type = 3;
} else {
type = 7;
}
if (videoEditedInfo != null) {
String ve = videoEditedInfo.getString();
params.put("ve", ve);
}
newMsg.attachPath = path;
} else {
type = 1;
}
newMsg.params = params;
newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_EDITING;
}
if (newMsg.attachPath == null) {
newMsg.attachPath = "";
}
newMsg.local_id = 0;
if ((messageObject.type == 3 || videoEditedInfo != null || messageObject.type == 2) && !TextUtils.isEmpty(newMsg.attachPath)) {
messageObject.attachPathExists = true;
}
if (messageObject.videoEditedInfo != null && videoEditedInfo == null) {
videoEditedInfo = messageObject.videoEditedInfo;
}
if (!retry) {
if (messageObject.editingMessage != null) {
String oldMessge = newMsg.message;
newMsg.message = messageObject.editingMessage.toString();
messageObject.caption = null;
if (type == 1) {
if (messageObject.editingMessageEntities != null) {
newMsg.entities = messageObject.editingMessageEntities;
newMsg.flags |= 128;
} else if (!TextUtils.equals(oldMessge, newMsg.message)) {
newMsg.flags &= ~128;
}
} else {
if (messageObject.editingMessageEntities != null) {
newMsg.entities = messageObject.editingMessageEntities;
newMsg.flags |= 128;
} else {
CharSequence[] message = new CharSequence[] { messageObject.editingMessage };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, supportsSendingNewEntities);
if (entities != null && !entities.isEmpty()) {
newMsg.entities = entities;
newMsg.flags |= 128;
} else if (!TextUtils.equals(oldMessge, newMsg.message)) {
newMsg.flags &= ~128;
}
}
messageObject.generateCaption();
}
}
ArrayList<TLRPC.Message> arr = new ArrayList<>();
arr.add(newMsg);
getMessagesStorage().putMessages(arr, false, true, false, 0, messageObject.scheduled);
messageObject.type = -1;
messageObject.setType();
if (type == 1) {
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
messageObject.generateCaption();
} else {
messageObject.resetLayout();
messageObject.checkLayout();
}
}
messageObject.createMessageSendInfo();
ArrayList<MessageObject> arrayList = new ArrayList<>();
arrayList.add(messageObject);
getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, peer, arrayList);
}
String originalPath = null;
if (params != null && params.containsKey("originalPath")) {
originalPath = params.get("originalPath");
}
boolean performMediaUpload = false;
if (type >= 1 && type <= 3 || type >= 5 && type <= 8) {
TLRPC.InputMedia inputMedia = null;
if (type == 1) {
} else if (type == 2) {
TLRPC.TL_inputMediaUploadedPhoto uploadedPhoto = new TLRPC.TL_inputMediaUploadedPhoto();
if (params != null) {
String masks = params.get("masks");
if (masks != null) {
SerializedData serializedData = new SerializedData(Utilities.hexToBytes(masks));
int count = serializedData.readInt32(false);
for (int a = 0; a < count; a++) {
uploadedPhoto.stickers.add(TLRPC.InputDocument.TLdeserialize(serializedData, serializedData.readInt32(false), false));
}
uploadedPhoto.flags |= 1;
serializedData.cleanup();
}
}
if (photo.access_hash == 0) {
inputMedia = uploadedPhoto;
performMediaUpload = true;
} else {
TLRPC.TL_inputMediaPhoto media = new TLRPC.TL_inputMediaPhoto();
media.id = new TLRPC.TL_inputPhoto();
media.id.id = photo.id;
media.id.access_hash = photo.access_hash;
media.id.file_reference = photo.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
inputMedia = media;
}
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 0;
delayedMessage.obj = messageObject;
delayedMessage.originalPath = originalPath;
delayedMessage.parentObject = parentObject;
delayedMessage.inputUploadMedia = uploadedPhoto;
delayedMessage.performMediaUpload = performMediaUpload;
if (path != null && path.length() > 0 && path.startsWith("http")) {
delayedMessage.httpLocation = path;
} else {
delayedMessage.photoSize = photo.sizes.get(photo.sizes.size() - 1);
delayedMessage.locationParent = photo;
}
} else if (type == 3) {
TLRPC.TL_inputMediaUploadedDocument uploadedDocument = new TLRPC.TL_inputMediaUploadedDocument();
if (params != null) {
String masks = params.get("masks");
if (masks != null) {
SerializedData serializedData = new SerializedData(Utilities.hexToBytes(masks));
int count = serializedData.readInt32(false);
for (int a = 0; a < count; a++) {
uploadedDocument.stickers.add(TLRPC.InputDocument.TLdeserialize(serializedData, serializedData.readInt32(false), false));
}
uploadedDocument.flags |= 1;
serializedData.cleanup();
}
}
uploadedDocument.mime_type = document.mime_type;
uploadedDocument.attributes = document.attributes;
if (!messageObject.isGif() && (videoEditedInfo == null || !videoEditedInfo.muted)) {
uploadedDocument.nosound_video = true;
if (BuildVars.DEBUG_VERSION) {
FileLog.d("nosound_video = true");
}
}
if (document.access_hash == 0) {
inputMedia = uploadedDocument;
performMediaUpload = true;
} else {
TLRPC.TL_inputMediaDocument media = new TLRPC.TL_inputMediaDocument();
media.id = new TLRPC.TL_inputDocument();
media.id.id = document.id;
media.id.access_hash = document.access_hash;
media.id.file_reference = document.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
inputMedia = media;
}
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 1;
delayedMessage.obj = messageObject;
delayedMessage.originalPath = originalPath;
delayedMessage.parentObject = parentObject;
delayedMessage.inputUploadMedia = uploadedDocument;
delayedMessage.performMediaUpload = performMediaUpload;
if (!document.thumbs.isEmpty()) {
TLRPC.PhotoSize photoSize = document.thumbs.get(0);
if (!(photoSize instanceof TLRPC.TL_photoStrippedSize)) {
delayedMessage.photoSize = photoSize;
delayedMessage.locationParent = document;
}
}
delayedMessage.videoEditedInfo = videoEditedInfo;
} else if (type == 7) {
boolean http = false;
TLRPC.InputMedia uploadedDocument = new TLRPC.TL_inputMediaUploadedDocument();
uploadedDocument.mime_type = document.mime_type;
uploadedDocument.attributes = document.attributes;
if (document.access_hash == 0) {
inputMedia = uploadedDocument;
performMediaUpload = uploadedDocument instanceof TLRPC.TL_inputMediaUploadedDocument;
} else {
TLRPC.TL_inputMediaDocument media = new TLRPC.TL_inputMediaDocument();
media.id = new TLRPC.TL_inputDocument();
media.id.id = document.id;
media.id.access_hash = document.access_hash;
media.id.file_reference = document.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
inputMedia = media;
}
if (!http) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.originalPath = originalPath;
delayedMessage.type = 2;
delayedMessage.obj = messageObject;
if (!document.thumbs.isEmpty()) {
TLRPC.PhotoSize photoSize = document.thumbs.get(0);
if (!(photoSize instanceof TLRPC.TL_photoStrippedSize)) {
delayedMessage.photoSize = photoSize;
delayedMessage.locationParent = document;
}
}
delayedMessage.parentObject = parentObject;
delayedMessage.inputUploadMedia = uploadedDocument;
delayedMessage.performMediaUpload = performMediaUpload;
}
}
TLObject reqSend;
TLRPC.TL_messages_editMessage request = new TLRPC.TL_messages_editMessage();
request.id = messageObject.getId();
request.peer = getMessagesController().getInputPeer(peer);
if (inputMedia != null) {
request.flags |= 16384;
request.media = inputMedia;
}
if (messageObject.scheduled) {
request.schedule_date = messageObject.messageOwner.date;
request.flags |= 32768;
}
if (messageObject.editingMessage != null) {
request.message = messageObject.editingMessage.toString();
request.flags |= 2048;
request.no_webpage = !messageObject.editingMessageSearchWebPage;
if (messageObject.editingMessageEntities != null) {
request.entities = messageObject.editingMessageEntities;
request.flags |= 8;
} else {
CharSequence[] message = new CharSequence[] { messageObject.editingMessage };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, supportsSendingNewEntities);
if (entities != null && !entities.isEmpty()) {
request.entities = entities;
request.flags |= 8;
}
}
messageObject.editingMessage = null;
messageObject.editingMessageEntities = null;
}
if (delayedMessage != null) {
delayedMessage.sendRequest = request;
}
reqSend = request;
if (type == 1) {
performSendMessageRequest(reqSend, messageObject, null, delayedMessage, parentObject, params, messageObject.scheduled);
} else if (type == 2) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, messageObject, originalPath, null, true, delayedMessage, parentObject, params, messageObject.scheduled);
}
} else if (type == 3) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, messageObject, originalPath, delayedMessage, parentObject, params, messageObject.scheduled);
}
} else if (type == 6) {
performSendMessageRequest(reqSend, messageObject, originalPath, delayedMessage, parentObject, params, messageObject.scheduled);
} else if (type == 7) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, messageObject, originalPath, delayedMessage, parentObject, params, messageObject.scheduled);
}
} else if (type == 8) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, messageObject, originalPath, delayedMessage, parentObject, params, messageObject.scheduled);
}
}
}
} catch (Exception e) {
FileLog.e(e);
revertEditingMessageObject(messageObject);
}
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method sendMessage.
private void sendMessage(String message, String caption, TLRPC.MessageMedia location, TLRPC.TL_photo photo, VideoEditedInfo videoEditedInfo, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_game game, TLRPC.TL_messageMediaPoll poll, TLRPC.TL_messageMediaInvoice invoice, long peer, String path, MessageObject replyToMsg, MessageObject replyToTopMsg, TLRPC.WebPage webPage, boolean searchLinks, MessageObject retryMessageObject, ArrayList<TLRPC.MessageEntity> entities, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate, int ttl, Object parentObject, MessageObject.SendAnimationData sendAnimationData) {
if (user != null && user.phone == null) {
return;
}
if (peer == 0) {
return;
}
if (message == null && caption == null) {
caption = "";
}
String originalPath = null;
if (params != null && params.containsKey("originalPath")) {
originalPath = params.get("originalPath");
}
TLRPC.Message newMsg = null;
MessageObject newMsgObj = null;
DelayedMessage delayedMessage = null;
int type = -1;
boolean isChannel = false;
boolean forceNoSoundVideo = false;
TLRPC.Peer fromPeer = null;
String rank = null;
long linkedToGroup = 0;
TLRPC.EncryptedChat encryptedChat = null;
TLRPC.InputPeer sendToPeer = !DialogObject.isEncryptedDialog(peer) ? getMessagesController().getInputPeer(peer) : null;
long myId = getUserConfig().getClientUserId();
if (DialogObject.isEncryptedDialog(peer)) {
encryptedChat = getMessagesController().getEncryptedChat(DialogObject.getEncryptedChatId(peer));
if (encryptedChat == null) {
if (retryMessageObject != null) {
getMessagesStorage().markMessageAsSendError(retryMessageObject.messageOwner, retryMessageObject.scheduled);
retryMessageObject.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, retryMessageObject.getId());
processSentMessage(retryMessageObject.getId());
}
return;
}
} else if (sendToPeer instanceof TLRPC.TL_inputPeerChannel) {
TLRPC.Chat chat = getMessagesController().getChat(sendToPeer.channel_id);
TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id);
isChannel = chat != null && !chat.megagroup;
if (isChannel && chat.has_link && chatFull != null) {
linkedToGroup = chatFull.linked_chat_id;
}
fromPeer = getMessagesController().getPeer(ChatObject.getSendAsPeerId(chat, chatFull, true));
}
try {
if (retryMessageObject != null) {
newMsg = retryMessageObject.messageOwner;
if (parentObject == null && params != null && params.containsKey("parentObject")) {
parentObject = params.get("parentObject");
}
if (retryMessageObject.isForwarded() || params != null && params.containsKey("fwd_id")) {
type = 4;
} else {
if (retryMessageObject.isDice()) {
type = 11;
message = retryMessageObject.getDiceEmoji();
caption = "";
} else if (retryMessageObject.type == 0 || retryMessageObject.isAnimatedEmoji()) {
if (retryMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
// game = retryMessageObject.messageOwner.media.game;
} else {
message = newMsg.message;
}
type = 0;
} else if (retryMessageObject.type == 4) {
location = newMsg.media;
type = 1;
} else if (retryMessageObject.type == 1) {
photo = (TLRPC.TL_photo) newMsg.media.photo;
if (retryMessageObject.messageOwner.message != null) {
caption = retryMessageObject.messageOwner.message;
}
type = 2;
} else if (retryMessageObject.type == 3 || retryMessageObject.type == 5 || retryMessageObject.videoEditedInfo != null) {
type = 3;
document = (TLRPC.TL_document) newMsg.media.document;
if (retryMessageObject.messageOwner.message != null) {
caption = retryMessageObject.messageOwner.message;
}
} else if (retryMessageObject.type == 12) {
user = new TLRPC.TL_userRequest_old2();
user.phone = newMsg.media.phone_number;
user.first_name = newMsg.media.first_name;
user.last_name = newMsg.media.last_name;
TLRPC.TL_restrictionReason reason = new TLRPC.TL_restrictionReason();
reason.platform = "";
reason.reason = "";
reason.text = newMsg.media.vcard;
user.restriction_reason.add(reason);
user.id = newMsg.media.user_id;
type = 6;
} else if (retryMessageObject.type == 8 || retryMessageObject.type == 9 || retryMessageObject.type == MessageObject.TYPE_STICKER || retryMessageObject.type == 14 || retryMessageObject.type == MessageObject.TYPE_ANIMATED_STICKER) {
document = (TLRPC.TL_document) newMsg.media.document;
type = 7;
if (retryMessageObject.messageOwner.message != null) {
caption = retryMessageObject.messageOwner.message;
}
} else if (retryMessageObject.type == 2) {
document = (TLRPC.TL_document) newMsg.media.document;
type = 8;
if (retryMessageObject.messageOwner.message != null) {
caption = retryMessageObject.messageOwner.message;
}
} else if (retryMessageObject.type == MessageObject.TYPE_POLL) {
poll = (TLRPC.TL_messageMediaPoll) newMsg.media;
type = 10;
}
if (params != null && params.containsKey("query_id")) {
type = 9;
}
if (newMsg.media.ttl_seconds > 0) {
ttl = newMsg.media.ttl_seconds;
}
}
} else {
boolean canSendStickers = true;
if (DialogObject.isChatDialog(peer)) {
TLRPC.Chat chat = getMessagesController().getChat(-peer);
canSendStickers = ChatObject.canSendStickers(chat);
}
if (message != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
if (encryptedChat != null && webPage instanceof TLRPC.TL_webPagePending) {
if (webPage.url != null) {
TLRPC.WebPage newWebPage = new TLRPC.TL_webPageUrlPending();
newWebPage.url = webPage.url;
webPage = newWebPage;
} else {
webPage = null;
}
}
if (canSendStickers && message.length() < 30 && webPage == null && (entities == null || entities.isEmpty()) && getMessagesController().diceEmojies.contains(message.replace("\ufe0f", "")) && encryptedChat == null && scheduleDate == 0) {
TLRPC.TL_messageMediaDice mediaDice = new TLRPC.TL_messageMediaDice();
mediaDice.emoticon = message;
mediaDice.value = -1;
newMsg.media = mediaDice;
type = 11;
caption = "";
} else {
if (webPage == null) {
newMsg.media = new TLRPC.TL_messageMediaEmpty();
} else {
newMsg.media = new TLRPC.TL_messageMediaWebPage();
newMsg.media.webpage = webPage;
}
if (params != null && params.containsKey("query_id")) {
type = 9;
} else {
type = 0;
}
newMsg.message = message;
}
} else if (poll != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
newMsg.media = poll;
type = 10;
} else if (location != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
newMsg.media = location;
if (params != null && params.containsKey("query_id")) {
type = 9;
} else {
type = 1;
}
} else if (photo != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
newMsg.media = new TLRPC.TL_messageMediaPhoto();
newMsg.media.flags |= 3;
if (entities != null) {
newMsg.entities = entities;
}
if (ttl != 0) {
newMsg.ttl = newMsg.media.ttl_seconds = ttl;
newMsg.media.flags |= 4;
}
newMsg.media.photo = photo;
if (params != null && params.containsKey("query_id")) {
type = 9;
} else {
type = 2;
}
if (path != null && path.length() > 0 && path.startsWith("http")) {
newMsg.attachPath = path;
} else {
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
newMsg.attachPath = FileLoader.getPathToAttach(location1, true).toString();
}
} else if (game != null) {
newMsg = new TLRPC.TL_message();
newMsg.media = new TLRPC.TL_messageMediaGame();
newMsg.media.game = game;
if (params != null && params.containsKey("query_id")) {
type = 9;
}
} else if (invoice != null) {
newMsg = new TLRPC.TL_message();
newMsg.media = invoice;
if (params != null && params.containsKey("query_id")) {
type = 9;
}
} else if (user != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
newMsg.media = new TLRPC.TL_messageMediaContact();
newMsg.media.phone_number = user.phone;
newMsg.media.first_name = user.first_name;
newMsg.media.last_name = user.last_name;
newMsg.media.user_id = user.id;
if (!user.restriction_reason.isEmpty() && user.restriction_reason.get(0).text.startsWith("BEGIN:VCARD")) {
newMsg.media.vcard = user.restriction_reason.get(0).text;
} else {
newMsg.media.vcard = "";
}
if (newMsg.media.first_name == null) {
user.first_name = newMsg.media.first_name = "";
}
if (newMsg.media.last_name == null) {
user.last_name = newMsg.media.last_name = "";
}
if (params != null && params.containsKey("query_id")) {
type = 9;
} else {
type = 6;
}
} else if (document != null) {
if (encryptedChat != null) {
newMsg = new TLRPC.TL_message_secret();
} else {
newMsg = new TLRPC.TL_message();
}
if (DialogObject.isChatDialog(peer)) {
if (!canSendStickers) {
for (int a = 0, N = document.attributes.size(); a < N; a++) {
if (document.attributes.get(a) instanceof TLRPC.TL_documentAttributeAnimated) {
document.attributes.remove(a);
forceNoSoundVideo = true;
break;
}
}
}
}
newMsg.media = new TLRPC.TL_messageMediaDocument();
newMsg.media.flags |= 3;
if (ttl != 0) {
newMsg.ttl = newMsg.media.ttl_seconds = ttl;
newMsg.media.flags |= 4;
}
newMsg.media.document = document;
if (params != null && params.containsKey("query_id")) {
type = 9;
} else if (!MessageObject.isVideoSticker(document) && (MessageObject.isVideoDocument(document) || MessageObject.isRoundVideoDocument(document) || videoEditedInfo != null)) {
type = 3;
} else if (MessageObject.isVoiceDocument(document)) {
type = 8;
} else {
type = 7;
}
if (videoEditedInfo != null) {
String ve = videoEditedInfo.getString();
if (params == null) {
params = new HashMap<>();
}
params.put("ve", ve);
}
if (encryptedChat != null && document.dc_id > 0 && !MessageObject.isStickerDocument(document) && !MessageObject.isAnimatedStickerDocument(document, true)) {
newMsg.attachPath = FileLoader.getPathToAttach(document).toString();
} else {
newMsg.attachPath = path;
}
if (encryptedChat != null && (MessageObject.isStickerDocument(document) || MessageObject.isAnimatedStickerDocument(document, true))) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
document.attributes.remove(a);
TLRPC.TL_documentAttributeSticker_layer55 attributeSticker = new TLRPC.TL_documentAttributeSticker_layer55();
document.attributes.add(attributeSticker);
attributeSticker.alt = attribute.alt;
if (attribute.stickerset != null) {
String name;
if (attribute.stickerset instanceof TLRPC.TL_inputStickerSetShortName) {
name = attribute.stickerset.short_name;
} else {
name = getMediaDataController().getStickerSetName(attribute.stickerset.id);
}
if (!TextUtils.isEmpty(name)) {
attributeSticker.stickerset = new TLRPC.TL_inputStickerSetShortName();
attributeSticker.stickerset.short_name = name;
} else {
if (attribute.stickerset instanceof TLRPC.TL_inputStickerSetID) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.locationParent = attributeSticker;
delayedMessage.type = 5;
delayedMessage.parentObject = attribute.stickerset;
}
attributeSticker.stickerset = new TLRPC.TL_inputStickerSetEmpty();
}
} else {
attributeSticker.stickerset = new TLRPC.TL_inputStickerSetEmpty();
}
break;
}
}
}
}
if (entities != null && !entities.isEmpty()) {
newMsg.entities = entities;
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_ENTITIES;
}
if (caption != null) {
newMsg.message = caption;
} else if (newMsg.message == null) {
newMsg.message = "";
}
if (newMsg.attachPath == null) {
newMsg.attachPath = "";
}
newMsg.local_id = newMsg.id = getUserConfig().getNewMessageId();
newMsg.out = true;
if (isChannel && sendToPeer != null) {
newMsg.from_id = new TLRPC.TL_peerChannel();
newMsg.from_id.channel_id = sendToPeer.channel_id;
} else if (fromPeer != null) {
newMsg.from_id = fromPeer;
if (rank != null) {
newMsg.post_author = rank;
newMsg.flags |= 65536;
}
} else {
newMsg.from_id = new TLRPC.TL_peerUser();
newMsg.from_id.user_id = myId;
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
}
getUserConfig().saveConfig(false);
}
newMsg.silent = !notify || MessagesController.getNotificationsSettings(currentAccount).getBoolean("silent_" + peer, false);
if (newMsg.random_id == 0) {
newMsg.random_id = getNextRandomId();
}
if (params != null && params.containsKey("bot")) {
if (encryptedChat != null) {
newMsg.via_bot_name = params.get("bot_name");
if (newMsg.via_bot_name == null) {
newMsg.via_bot_name = "";
}
} else {
newMsg.via_bot_id = Utilities.parseInt(params.get("bot"));
}
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_BOT_ID;
}
newMsg.params = params;
if (retryMessageObject == null || !retryMessageObject.resendAsIs) {
newMsg.date = scheduleDate != 0 ? scheduleDate : getConnectionsManager().getCurrentTime();
if (sendToPeer instanceof TLRPC.TL_inputPeerChannel) {
if (scheduleDate == 0 && isChannel) {
newMsg.views = 1;
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_VIEWS;
}
TLRPC.Chat chat = getMessagesController().getChat(sendToPeer.channel_id);
if (chat != null) {
if (chat.megagroup) {
newMsg.unread = true;
} else {
newMsg.post = true;
if (chat.signatures) {
newMsg.from_id = new TLRPC.TL_peerUser();
newMsg.from_id.user_id = myId;
}
}
}
} else {
newMsg.unread = true;
}
}
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA;
newMsg.dialog_id = peer;
if (replyToMsg != null) {
newMsg.reply_to = new TLRPC.TL_messageReplyHeader();
if (encryptedChat != null && replyToMsg.messageOwner.random_id != 0) {
newMsg.reply_to.reply_to_random_id = replyToMsg.messageOwner.random_id;
newMsg.flags |= TLRPC.MESSAGE_FLAG_REPLY;
} else {
newMsg.flags |= TLRPC.MESSAGE_FLAG_REPLY;
}
newMsg.reply_to.reply_to_msg_id = replyToMsg.getId();
if (replyToTopMsg != null && replyToTopMsg != replyToMsg) {
newMsg.reply_to.reply_to_top_id = replyToTopMsg.getId();
newMsg.reply_to.flags |= 2;
}
}
if (linkedToGroup != 0) {
newMsg.replies = new TLRPC.TL_messageReplies();
newMsg.replies.comments = true;
newMsg.replies.channel_id = linkedToGroup;
newMsg.replies.flags |= 1;
newMsg.flags |= 8388608;
}
if (replyMarkup != null && encryptedChat == null) {
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_MARKUP;
newMsg.reply_markup = replyMarkup;
}
if (!DialogObject.isEncryptedDialog(peer)) {
newMsg.peer_id = getMessagesController().getPeer(peer);
if (DialogObject.isUserDialog(peer)) {
TLRPC.User sendToUser = getMessagesController().getUser(peer);
if (sendToUser == null) {
processSentMessage(newMsg.id);
return;
}
if (sendToUser.bot) {
newMsg.unread = false;
}
}
} else {
newMsg.peer_id = new TLRPC.TL_peerUser();
if (encryptedChat.participant_id == myId) {
newMsg.peer_id.user_id = encryptedChat.admin_id;
} else {
newMsg.peer_id.user_id = encryptedChat.participant_id;
}
if (ttl != 0) {
newMsg.ttl = ttl;
} else {
newMsg.ttl = encryptedChat.ttl;
if (newMsg.ttl != 0 && newMsg.media != null) {
newMsg.media.ttl_seconds = newMsg.ttl;
newMsg.media.flags |= 4;
}
}
if (newMsg.ttl != 0 && newMsg.media.document != null) {
if (MessageObject.isVoiceMessage(newMsg)) {
int duration = 0;
for (int a = 0; a < newMsg.media.document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = newMsg.media.document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
duration = attribute.duration;
break;
}
}
newMsg.ttl = Math.max(newMsg.ttl, duration + 1);
} else if (MessageObject.isVideoMessage(newMsg) || MessageObject.isRoundVideoMessage(newMsg)) {
int duration = 0;
for (int a = 0; a < newMsg.media.document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = newMsg.media.document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
duration = attribute.duration;
break;
}
}
newMsg.ttl = Math.max(newMsg.ttl, duration + 1);
}
}
}
if (MessageObject.isVoiceMessage(newMsg) || MessageObject.isRoundVideoMessage(newMsg)) {
newMsg.media_unread = true;
}
if (newMsg.from_id == null) {
newMsg.from_id = newMsg.peer_id;
}
newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
long groupId = 0;
boolean isFinalGroupMedia = false;
if (params != null) {
String groupIdStr = params.get("groupId");
if (groupIdStr != null) {
groupId = Utilities.parseLong(groupIdStr);
newMsg.grouped_id = groupId;
newMsg.flags |= 131072;
}
isFinalGroupMedia = params.get("final") != null;
}
newMsgObj = new MessageObject(currentAccount, newMsg, replyToMsg, true, true);
newMsgObj.sendAnimationData = sendAnimationData;
newMsgObj.wasJustSent = true;
newMsgObj.scheduled = scheduleDate != 0;
if (!newMsgObj.isForwarded() && (newMsgObj.type == 3 || videoEditedInfo != null || newMsgObj.type == 2) && !TextUtils.isEmpty(newMsg.attachPath)) {
newMsgObj.attachPathExists = true;
}
if (newMsgObj.videoEditedInfo != null && videoEditedInfo == null) {
videoEditedInfo = newMsgObj.videoEditedInfo;
}
if (groupId == 0) {
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(newMsgObj);
ArrayList<TLRPC.Message> arr = new ArrayList<>();
arr.add(newMsg);
MessagesStorage.getInstance(currentAccount).putMessages(arr, false, true, false, 0, scheduleDate != 0);
MessagesController.getInstance(currentAccount).updateInterfaceWithMessages(peer, objArr, scheduleDate != 0);
if (scheduleDate == 0) {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsNeedReload);
}
} else {
String key = "group_" + groupId;
ArrayList<DelayedMessage> arrayList = delayedMessages.get(key);
if (arrayList != null) {
delayedMessage = arrayList.get(0);
}
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.initForGroup(groupId);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.scheduled = scheduleDate != 0;
}
delayedMessage.performMediaUpload = false;
delayedMessage.photoSize = null;
delayedMessage.videoEditedInfo = null;
delayedMessage.httpLocation = null;
if (isFinalGroupMedia) {
delayedMessage.finalGroupMessage = newMsg.id;
}
}
if (BuildVars.LOGS_ENABLED) {
if (sendToPeer != null) {
FileLog.d("send message user_id = " + sendToPeer.user_id + " chat_id = " + sendToPeer.chat_id + " channel_id = " + sendToPeer.channel_id + " access_hash = " + sendToPeer.access_hash + " notify = " + notify + " silent = " + MessagesController.getNotificationsSettings(currentAccount).getBoolean("silent_" + peer, false));
}
}
boolean performMediaUpload = false;
if (type == 0 || type == 9 && message != null && encryptedChat != null) {
if (encryptedChat == null) {
TLRPC.TL_messages_sendMessage reqSend = new TLRPC.TL_messages_sendMessage();
reqSend.message = message;
reqSend.clear_draft = retryMessageObject == null;
reqSend.silent = newMsg.silent;
reqSend.peer = sendToPeer;
reqSend.random_id = newMsg.random_id;
if (newMsg.from_id != null) {
reqSend.send_as = getMessagesController().getInputPeer(newMsg.from_id);
}
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
reqSend.flags |= 1;
reqSend.reply_to_msg_id = newMsg.reply_to.reply_to_msg_id;
}
if (!searchLinks) {
reqSend.no_webpage = true;
}
if (entities != null && !entities.isEmpty()) {
reqSend.entities = entities;
reqSend.flags |= 8;
}
if (scheduleDate != 0) {
reqSend.schedule_date = scheduleDate;
reqSend.flags |= 1024;
}
performSendMessageRequest(reqSend, newMsgObj, null, null, parentObject, params, scheduleDate != 0);
if (retryMessageObject == null) {
getMediaDataController().cleanDraft(peer, replyToTopMsg != null ? replyToTopMsg.getId() : 0, false);
}
} else {
TLRPC.TL_decryptedMessage reqSend;
reqSend = new TLRPC.TL_decryptedMessage();
reqSend.ttl = newMsg.ttl;
if (entities != null && !entities.isEmpty()) {
reqSend.entities = entities;
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_ENTITIES;
}
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_random_id != 0) {
reqSend.reply_to_random_id = newMsg.reply_to.reply_to_random_id;
reqSend.flags |= TLRPC.MESSAGE_FLAG_REPLY;
}
if (params != null && params.get("bot_name") != null) {
reqSend.via_bot_name = params.get("bot_name");
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_BOT_ID;
}
reqSend.silent = newMsg.silent;
reqSend.random_id = newMsg.random_id;
reqSend.message = message;
if (webPage != null && webPage.url != null) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaWebPage();
reqSend.media.url = webPage.url;
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA;
} else {
reqSend.media = new TLRPC.TL_decryptedMessageMediaEmpty();
}
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null, newMsgObj);
if (retryMessageObject == null) {
getMediaDataController().cleanDraft(peer, replyToTopMsg != null ? replyToTopMsg.getId() : 0, false);
}
}
} else if (type >= 1 && type <= 3 || type >= 5 && type <= 8 || type == 9 && encryptedChat != null || type == 10 || type == 11) {
if (encryptedChat == null) {
TLRPC.InputMedia inputMedia = null;
if (type == 1) {
if (location instanceof TLRPC.TL_messageMediaVenue) {
inputMedia = new TLRPC.TL_inputMediaVenue();
inputMedia.address = location.address;
inputMedia.title = location.title;
inputMedia.provider = location.provider;
inputMedia.venue_id = location.venue_id;
inputMedia.venue_type = "";
} else if (location instanceof TLRPC.TL_messageMediaGeoLive) {
inputMedia = new TLRPC.TL_inputMediaGeoLive();
inputMedia.period = location.period;
inputMedia.flags |= 2;
if (location.heading != 0) {
inputMedia.heading = location.heading;
inputMedia.flags |= 4;
}
if (location.proximity_notification_radius != 0) {
inputMedia.proximity_notification_radius = location.proximity_notification_radius;
inputMedia.flags |= 8;
}
} else {
inputMedia = new TLRPC.TL_inputMediaGeoPoint();
}
inputMedia.geo_point = new TLRPC.TL_inputGeoPoint();
inputMedia.geo_point.lat = location.geo.lat;
inputMedia.geo_point._long = location.geo._long;
} else if (type == 2 || type == 9 && photo != null) {
TLRPC.TL_inputMediaUploadedPhoto uploadedPhoto = new TLRPC.TL_inputMediaUploadedPhoto();
if (ttl != 0) {
newMsg.ttl = uploadedPhoto.ttl_seconds = ttl;
uploadedPhoto.flags |= 2;
}
if (params != null) {
String masks = params.get("masks");
if (masks != null) {
SerializedData serializedData = new SerializedData(Utilities.hexToBytes(masks));
int count = serializedData.readInt32(false);
for (int a = 0; a < count; a++) {
uploadedPhoto.stickers.add(TLRPC.InputDocument.TLdeserialize(serializedData, serializedData.readInt32(false), false));
}
uploadedPhoto.flags |= 1;
serializedData.cleanup();
}
}
if (photo.access_hash == 0) {
inputMedia = uploadedPhoto;
performMediaUpload = true;
} else {
TLRPC.TL_inputMediaPhoto media = new TLRPC.TL_inputMediaPhoto();
media.id = new TLRPC.TL_inputPhoto();
media.id.id = photo.id;
media.id.access_hash = photo.access_hash;
media.id.file_reference = photo.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
inputMedia = media;
}
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 0;
delayedMessage.obj = newMsgObj;
delayedMessage.originalPath = originalPath;
delayedMessage.scheduled = scheduleDate != 0;
}
delayedMessage.inputUploadMedia = uploadedPhoto;
delayedMessage.performMediaUpload = performMediaUpload;
if (path != null && path.length() > 0 && path.startsWith("http")) {
delayedMessage.httpLocation = path;
} else {
delayedMessage.photoSize = photo.sizes.get(photo.sizes.size() - 1);
delayedMessage.locationParent = photo;
}
} else if (type == 3) {
TLRPC.TL_inputMediaUploadedDocument uploadedDocument = new TLRPC.TL_inputMediaUploadedDocument();
uploadedDocument.mime_type = document.mime_type;
uploadedDocument.attributes = document.attributes;
if (forceNoSoundVideo || !MessageObject.isRoundVideoDocument(document) && (videoEditedInfo == null || !videoEditedInfo.muted && !videoEditedInfo.roundVideo)) {
uploadedDocument.nosound_video = true;
if (BuildVars.DEBUG_VERSION) {
FileLog.d("nosound_video = true");
}
}
if (ttl != 0) {
newMsg.ttl = uploadedDocument.ttl_seconds = ttl;
uploadedDocument.flags |= 2;
}
if (params != null) {
String masks = params.get("masks");
if (masks != null) {
SerializedData serializedData = new SerializedData(Utilities.hexToBytes(masks));
int count = serializedData.readInt32(false);
for (int a = 0; a < count; a++) {
uploadedDocument.stickers.add(TLRPC.InputDocument.TLdeserialize(serializedData, serializedData.readInt32(false), false));
}
uploadedDocument.flags |= 1;
serializedData.cleanup();
}
}
if (document.access_hash == 0) {
inputMedia = uploadedDocument;
performMediaUpload = true;
} else {
TLRPC.TL_inputMediaDocument media = new TLRPC.TL_inputMediaDocument();
media.id = new TLRPC.TL_inputDocument();
media.id.id = document.id;
media.id.access_hash = document.access_hash;
media.id.file_reference = document.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
if (params != null && params.containsKey("query")) {
media.query = params.get("query");
media.flags |= 2;
}
inputMedia = media;
}
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 1;
delayedMessage.obj = newMsgObj;
delayedMessage.originalPath = originalPath;
delayedMessage.parentObject = parentObject;
delayedMessage.scheduled = scheduleDate != 0;
}
delayedMessage.inputUploadMedia = uploadedDocument;
delayedMessage.performMediaUpload = performMediaUpload;
if (!document.thumbs.isEmpty()) {
TLRPC.PhotoSize photoSize = document.thumbs.get(0);
if (!(photoSize instanceof TLRPC.TL_photoStrippedSize)) {
delayedMessage.photoSize = photoSize;
delayedMessage.locationParent = document;
}
}
delayedMessage.videoEditedInfo = videoEditedInfo;
} else if (type == 6) {
inputMedia = new TLRPC.TL_inputMediaContact();
inputMedia.phone_number = user.phone;
inputMedia.first_name = user.first_name;
inputMedia.last_name = user.last_name;
if (!user.restriction_reason.isEmpty() && user.restriction_reason.get(0).text.startsWith("BEGIN:VCARD")) {
inputMedia.vcard = user.restriction_reason.get(0).text;
} else {
inputMedia.vcard = "";
}
} else if (type == 7 || type == 9) {
boolean http = false;
TLRPC.InputMedia uploadedMedia;
if (originalPath != null || path != null || document.access_hash == 0) {
uploadedMedia = new TLRPC.TL_inputMediaUploadedDocument();
if (ttl != 0) {
newMsg.ttl = uploadedMedia.ttl_seconds = ttl;
uploadedMedia.flags |= 2;
}
if (forceNoSoundVideo || !TextUtils.isEmpty(path) && path.toLowerCase().endsWith("mp4") && (params == null || params.containsKey("forceDocument"))) {
uploadedMedia.nosound_video = true;
}
uploadedMedia.force_file = params != null && params.containsKey("forceDocument");
uploadedMedia.mime_type = document.mime_type;
uploadedMedia.attributes = document.attributes;
} else {
uploadedMedia = null;
}
if (document.access_hash == 0) {
inputMedia = uploadedMedia;
performMediaUpload = uploadedMedia instanceof TLRPC.TL_inputMediaUploadedDocument;
} else {
TLRPC.TL_inputMediaDocument media = new TLRPC.TL_inputMediaDocument();
media.id = new TLRPC.TL_inputDocument();
media.id.id = document.id;
media.id.access_hash = document.access_hash;
media.id.file_reference = document.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
if (params != null && params.containsKey("query")) {
media.query = params.get("query");
media.flags |= 2;
}
inputMedia = media;
}
if (!http && uploadedMedia != null) {
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 2;
delayedMessage.obj = newMsgObj;
delayedMessage.originalPath = originalPath;
delayedMessage.parentObject = parentObject;
delayedMessage.scheduled = scheduleDate != 0;
}
delayedMessage.inputUploadMedia = uploadedMedia;
delayedMessage.performMediaUpload = performMediaUpload;
if (!document.thumbs.isEmpty()) {
TLRPC.PhotoSize photoSize = document.thumbs.get(0);
if (!(photoSize instanceof TLRPC.TL_photoStrippedSize)) {
delayedMessage.photoSize = photoSize;
delayedMessage.locationParent = document;
}
}
}
} else if (type == 8) {
TLRPC.TL_inputMediaUploadedDocument uploadedDocument = new TLRPC.TL_inputMediaUploadedDocument();
uploadedDocument.mime_type = document.mime_type;
uploadedDocument.attributes = document.attributes;
if (ttl != 0) {
newMsg.ttl = uploadedDocument.ttl_seconds = ttl;
uploadedDocument.flags |= 2;
}
if (document.access_hash == 0) {
inputMedia = uploadedDocument;
performMediaUpload = true;
} else {
TLRPC.TL_inputMediaDocument media = new TLRPC.TL_inputMediaDocument();
media.id = new TLRPC.TL_inputDocument();
media.id.id = document.id;
media.id.access_hash = document.access_hash;
media.id.file_reference = document.file_reference;
if (media.id.file_reference == null) {
media.id.file_reference = new byte[0];
}
if (params != null && params.containsKey("query")) {
media.query = params.get("query");
media.flags |= 2;
}
inputMedia = media;
}
delayedMessage = new DelayedMessage(peer);
delayedMessage.type = 3;
delayedMessage.obj = newMsgObj;
delayedMessage.parentObject = parentObject;
delayedMessage.inputUploadMedia = uploadedDocument;
delayedMessage.performMediaUpload = performMediaUpload;
delayedMessage.scheduled = scheduleDate != 0;
} else if (type == 10) {
TLRPC.TL_inputMediaPoll inputMediaPoll = new TLRPC.TL_inputMediaPoll();
inputMediaPoll.poll = poll.poll;
if (params != null && params.containsKey("answers")) {
byte[] answers = Utilities.hexToBytes(params.get("answers"));
if (answers.length > 0) {
for (int a = 0; a < answers.length; a++) {
inputMediaPoll.correct_answers.add(new byte[] { answers[a] });
}
inputMediaPoll.flags |= 1;
}
}
if (poll.results != null && !TextUtils.isEmpty(poll.results.solution)) {
inputMediaPoll.solution = poll.results.solution;
inputMediaPoll.solution_entities = poll.results.solution_entities;
inputMediaPoll.flags |= 2;
}
inputMedia = inputMediaPoll;
} else if (type == 11) {
TLRPC.TL_inputMediaDice inputMediaDice = new TLRPC.TL_inputMediaDice();
inputMediaDice.emoticon = message;
inputMedia = inputMediaDice;
}
TLObject reqSend;
if (groupId != 0) {
TLRPC.TL_messages_sendMultiMedia request;
if (delayedMessage.sendRequest != null) {
request = (TLRPC.TL_messages_sendMultiMedia) delayedMessage.sendRequest;
} else {
request = new TLRPC.TL_messages_sendMultiMedia();
request.peer = sendToPeer;
request.silent = newMsg.silent;
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
request.flags |= 1;
request.reply_to_msg_id = newMsg.reply_to.reply_to_msg_id;
}
if (scheduleDate != 0) {
request.schedule_date = scheduleDate;
request.flags |= 1024;
}
delayedMessage.sendRequest = request;
}
delayedMessage.messageObjects.add(newMsgObj);
delayedMessage.parentObjects.add(parentObject);
delayedMessage.locations.add(delayedMessage.photoSize);
delayedMessage.videoEditedInfos.add(delayedMessage.videoEditedInfo);
delayedMessage.httpLocations.add(delayedMessage.httpLocation);
delayedMessage.inputMedias.add(delayedMessage.inputUploadMedia);
delayedMessage.messages.add(newMsg);
delayedMessage.originalPaths.add(originalPath);
TLRPC.TL_inputSingleMedia inputSingleMedia = new TLRPC.TL_inputSingleMedia();
inputSingleMedia.random_id = newMsg.random_id;
inputSingleMedia.media = inputMedia;
inputSingleMedia.message = caption;
if (entities != null && !entities.isEmpty()) {
inputSingleMedia.entities = entities;
inputSingleMedia.flags |= 1;
}
request.multi_media.add(inputSingleMedia);
reqSend = request;
} else {
TLRPC.TL_messages_sendMedia request = new TLRPC.TL_messages_sendMedia();
request.peer = sendToPeer;
request.silent = newMsg.silent;
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
request.flags |= 1;
request.reply_to_msg_id = newMsg.reply_to.reply_to_msg_id;
}
request.random_id = newMsg.random_id;
if (newMsg.from_id != null) {
request.send_as = getMessagesController().getInputPeer(newMsg.from_id);
}
request.media = inputMedia;
request.message = caption;
if (entities != null && !entities.isEmpty()) {
request.entities = entities;
request.flags |= 8;
}
if (scheduleDate != 0) {
request.schedule_date = scheduleDate;
request.flags |= 1024;
}
if (delayedMessage != null) {
delayedMessage.sendRequest = request;
}
reqSend = request;
}
if (groupId != 0) {
performSendDelayedMessage(delayedMessage);
} else if (type == 1) {
performSendMessageRequest(reqSend, newMsgObj, null, delayedMessage, parentObject, params, scheduleDate != 0);
} else if (type == 2) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj, originalPath, null, true, delayedMessage, parentObject, params, scheduleDate != 0);
}
} else if (type == 3) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj, originalPath, delayedMessage, parentObject, params, scheduleDate != 0);
}
} else if (type == 6) {
performSendMessageRequest(reqSend, newMsgObj, originalPath, delayedMessage, parentObject, params, scheduleDate != 0);
} else if (type == 7) {
if (performMediaUpload && delayedMessage != null) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj, originalPath, delayedMessage, parentObject, params, scheduleDate != 0);
}
} else if (type == 8) {
if (performMediaUpload) {
performSendDelayedMessage(delayedMessage);
} else {
performSendMessageRequest(reqSend, newMsgObj, originalPath, delayedMessage, parentObject, params, scheduleDate != 0);
}
} else if (type == 10 || type == 11) {
performSendMessageRequest(reqSend, newMsgObj, originalPath, delayedMessage, parentObject, params, scheduleDate != 0);
}
} else {
TLRPC.TL_decryptedMessage reqSend;
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 73) {
reqSend = new TLRPC.TL_decryptedMessage();
if (groupId != 0) {
reqSend.grouped_id = groupId;
reqSend.flags |= 131072;
}
} else {
reqSend = new TLRPC.TL_decryptedMessage_layer45();
}
reqSend.ttl = newMsg.ttl;
if (entities != null && !entities.isEmpty()) {
reqSend.entities = entities;
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_ENTITIES;
}
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_random_id != 0) {
reqSend.reply_to_random_id = newMsg.reply_to.reply_to_random_id;
reqSend.flags |= TLRPC.MESSAGE_FLAG_REPLY;
}
reqSend.silent = newMsg.silent;
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA;
if (params != null && params.get("bot_name") != null) {
reqSend.via_bot_name = params.get("bot_name");
reqSend.flags |= TLRPC.MESSAGE_FLAG_HAS_BOT_ID;
}
reqSend.random_id = newMsg.random_id;
reqSend.message = "";
if (type == 1) {
if (location instanceof TLRPC.TL_messageMediaVenue) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaVenue();
reqSend.media.address = location.address;
reqSend.media.title = location.title;
reqSend.media.provider = location.provider;
reqSend.media.venue_id = location.venue_id;
} else {
reqSend.media = new TLRPC.TL_decryptedMessageMediaGeoPoint();
}
reqSend.media.lat = location.geo.lat;
reqSend.media._long = location.geo._long;
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null, newMsgObj);
} else if (type == 2 || type == 9 && photo != null) {
TLRPC.PhotoSize small = photo.sizes.get(0);
TLRPC.PhotoSize big = photo.sizes.get(photo.sizes.size() - 1);
ImageLoader.fillPhotoSizeWithBytes(small);
reqSend.media = new TLRPC.TL_decryptedMessageMediaPhoto();
reqSend.media.caption = caption;
if (small.bytes != null) {
((TLRPC.TL_decryptedMessageMediaPhoto) reqSend.media).thumb = small.bytes;
} else {
((TLRPC.TL_decryptedMessageMediaPhoto) reqSend.media).thumb = new byte[0];
}
reqSend.media.thumb_h = small.h;
reqSend.media.thumb_w = small.w;
reqSend.media.w = big.w;
reqSend.media.h = big.h;
reqSend.media.size = big.size;
if (big.location.key == null || groupId != 0) {
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.type = 0;
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.obj = newMsgObj;
if (params != null && params.containsKey("parentObject")) {
delayedMessage.parentObject = params.get("parentObject");
} else {
delayedMessage.parentObject = parentObject;
}
delayedMessage.performMediaUpload = true;
delayedMessage.scheduled = scheduleDate != 0;
}
if (!TextUtils.isEmpty(path) && path.startsWith("http")) {
delayedMessage.httpLocation = path;
} else {
delayedMessage.photoSize = photo.sizes.get(photo.sizes.size() - 1);
delayedMessage.locationParent = photo;
}
if (groupId == 0) {
performSendDelayedMessage(delayedMessage);
}
} else {
TLRPC.TL_inputEncryptedFile encryptedFile = new TLRPC.TL_inputEncryptedFile();
encryptedFile.id = big.location.volume_id;
encryptedFile.access_hash = big.location.secret;
reqSend.media.key = big.location.key;
reqSend.media.iv = big.location.iv;
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null, newMsgObj);
}
} else if (type == 3) {
TLRPC.PhotoSize thumb = getThumbForSecretChat(document.thumbs);
ImageLoader.fillPhotoSizeWithBytes(thumb);
if (MessageObject.isNewGifDocument(document) || MessageObject.isRoundVideoDocument(document)) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
reqSend.media.attributes = document.attributes;
if (thumb != null && thumb.bytes != null) {
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = thumb.bytes;
} else {
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = new byte[0];
}
} else {
reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo();
if (thumb != null && thumb.bytes != null) {
((TLRPC.TL_decryptedMessageMediaVideo) reqSend.media).thumb = thumb.bytes;
} else {
((TLRPC.TL_decryptedMessageMediaVideo) reqSend.media).thumb = new byte[0];
}
}
reqSend.media.caption = caption;
reqSend.media.mime_type = "video/mp4";
reqSend.media.size = document.size;
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
reqSend.media.w = attribute.w;
reqSend.media.h = attribute.h;
reqSend.media.duration = attribute.duration;
break;
}
}
reqSend.media.thumb_h = thumb.h;
reqSend.media.thumb_w = thumb.w;
if (document.key == null || groupId != 0) {
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.type = 1;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.originalPath = originalPath;
delayedMessage.obj = newMsgObj;
if (params != null && params.containsKey("parentObject")) {
delayedMessage.parentObject = params.get("parentObject");
} else {
delayedMessage.parentObject = parentObject;
}
delayedMessage.performMediaUpload = true;
delayedMessage.scheduled = scheduleDate != 0;
}
delayedMessage.videoEditedInfo = videoEditedInfo;
if (groupId == 0) {
performSendDelayedMessage(delayedMessage);
}
} else {
TLRPC.TL_inputEncryptedFile encryptedFile = new TLRPC.TL_inputEncryptedFile();
encryptedFile.id = document.id;
encryptedFile.access_hash = document.access_hash;
reqSend.media.key = document.key;
reqSend.media.iv = document.iv;
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null, newMsgObj);
}
} else if (type == 6) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaContact();
reqSend.media.phone_number = user.phone;
reqSend.media.first_name = user.first_name;
reqSend.media.last_name = user.last_name;
reqSend.media.user_id = user.id;
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null, newMsgObj);
} else if (type == 7 || type == 9 && document != null) {
if (document.access_hash != 0 && (MessageObject.isStickerDocument(document) || MessageObject.isAnimatedStickerDocument(document, true))) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaExternalDocument();
reqSend.media.id = document.id;
reqSend.media.date = document.date;
reqSend.media.access_hash = document.access_hash;
reqSend.media.mime_type = document.mime_type;
reqSend.media.size = document.size;
reqSend.media.dc_id = document.dc_id;
reqSend.media.attributes = document.attributes;
TLRPC.PhotoSize thumb = getThumbForSecretChat(document.thumbs);
if (thumb != null) {
((TLRPC.TL_decryptedMessageMediaExternalDocument) reqSend.media).thumb = thumb;
} else {
((TLRPC.TL_decryptedMessageMediaExternalDocument) reqSend.media).thumb = new TLRPC.TL_photoSizeEmpty();
((TLRPC.TL_decryptedMessageMediaExternalDocument) reqSend.media).thumb.type = "s";
}
if (delayedMessage != null && delayedMessage.type == 5) {
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.obj = newMsgObj;
performSendDelayedMessage(delayedMessage);
} else {
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, null, null, newMsgObj);
}
} else {
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
reqSend.media.attributes = document.attributes;
reqSend.media.caption = caption;
TLRPC.PhotoSize thumb = getThumbForSecretChat(document.thumbs);
if (thumb != null) {
ImageLoader.fillPhotoSizeWithBytes(thumb);
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = thumb.bytes;
reqSend.media.thumb_h = thumb.h;
reqSend.media.thumb_w = thumb.w;
} else {
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = new byte[0];
reqSend.media.thumb_h = 0;
reqSend.media.thumb_w = 0;
}
reqSend.media.size = document.size;
reqSend.media.mime_type = document.mime_type;
if (document.key == null || groupId != 0) {
if (delayedMessage == null) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.type = 2;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.originalPath = originalPath;
delayedMessage.obj = newMsgObj;
if (params != null && params.containsKey("parentObject")) {
delayedMessage.parentObject = params.get("parentObject");
} else {
delayedMessage.parentObject = parentObject;
}
delayedMessage.performMediaUpload = true;
delayedMessage.scheduled = scheduleDate != 0;
}
if (path != null && path.length() > 0 && path.startsWith("http")) {
delayedMessage.httpLocation = path;
}
if (groupId == 0) {
performSendDelayedMessage(delayedMessage);
}
} else {
TLRPC.TL_inputEncryptedFile encryptedFile = new TLRPC.TL_inputEncryptedFile();
encryptedFile.id = document.id;
encryptedFile.access_hash = document.access_hash;
reqSend.media.key = document.key;
reqSend.media.iv = document.iv;
getSecretChatHelper().performSendEncryptedRequest(reqSend, newMsgObj.messageOwner, encryptedChat, encryptedFile, null, newMsgObj);
}
}
} else if (type == 8) {
delayedMessage = new DelayedMessage(peer);
delayedMessage.encryptedChat = encryptedChat;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.obj = newMsgObj;
delayedMessage.type = 3;
delayedMessage.parentObject = parentObject;
delayedMessage.performMediaUpload = true;
delayedMessage.scheduled = scheduleDate != 0;
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
reqSend.media.attributes = document.attributes;
reqSend.media.caption = caption;
TLRPC.PhotoSize thumb = getThumbForSecretChat(document.thumbs);
if (thumb != null) {
ImageLoader.fillPhotoSizeWithBytes(thumb);
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = thumb.bytes;
reqSend.media.thumb_h = thumb.h;
reqSend.media.thumb_w = thumb.w;
} else {
((TLRPC.TL_decryptedMessageMediaDocument) reqSend.media).thumb = new byte[0];
reqSend.media.thumb_h = 0;
reqSend.media.thumb_w = 0;
}
reqSend.media.mime_type = document.mime_type;
reqSend.media.size = document.size;
delayedMessage.originalPath = originalPath;
performSendDelayedMessage(delayedMessage);
}
if (groupId != 0) {
TLRPC.TL_messages_sendEncryptedMultiMedia request;
if (delayedMessage.sendEncryptedRequest != null) {
request = (TLRPC.TL_messages_sendEncryptedMultiMedia) delayedMessage.sendEncryptedRequest;
} else {
request = new TLRPC.TL_messages_sendEncryptedMultiMedia();
delayedMessage.sendEncryptedRequest = request;
}
delayedMessage.messageObjects.add(newMsgObj);
delayedMessage.messages.add(newMsg);
delayedMessage.originalPaths.add(originalPath);
delayedMessage.performMediaUpload = true;
request.messages.add(reqSend);
TLRPC.TL_inputEncryptedFile encryptedFile = new TLRPC.TL_inputEncryptedFile();
encryptedFile.id = type == 3 || type == 7 ? 1 : 0;
request.files.add(encryptedFile);
performSendDelayedMessage(delayedMessage);
}
if (retryMessageObject == null) {
getMediaDataController().cleanDraft(peer, replyToTopMsg != null ? replyToTopMsg.getId() : 0, false);
}
}
} else if (type == 4) {
TLRPC.TL_messages_forwardMessages reqSend = new TLRPC.TL_messages_forwardMessages();
reqSend.to_peer = sendToPeer;
reqSend.with_my_score = retryMessageObject.messageOwner.with_my_score;
if (params != null && params.containsKey("fwd_id")) {
int fwdId = Utilities.parseInt(params.get("fwd_id"));
reqSend.drop_author = true;
long peerId = Utilities.parseLong(params.get("fwd_peer"));
if (peerId < 0) {
TLRPC.Chat chat = getMessagesController().getChat(-peerId);
if (ChatObject.isChannel(chat)) {
reqSend.from_peer = new TLRPC.TL_inputPeerChannel();
reqSend.from_peer.channel_id = chat.id;
reqSend.from_peer.access_hash = chat.access_hash;
} else {
reqSend.from_peer = new TLRPC.TL_inputPeerEmpty();
}
} else {
reqSend.from_peer = new TLRPC.TL_inputPeerEmpty();
}
reqSend.id.add(fwdId);
} else {
reqSend.from_peer = new TLRPC.TL_inputPeerEmpty();
}
reqSend.silent = newMsg.silent;
if (scheduleDate != 0) {
reqSend.schedule_date = scheduleDate;
reqSend.flags |= 1024;
}
reqSend.random_id.add(newMsg.random_id);
if (retryMessageObject.getId() >= 0) {
reqSend.id.add(retryMessageObject.getId());
} else {
if (retryMessageObject.messageOwner.fwd_msg_id != 0) {
reqSend.id.add(retryMessageObject.messageOwner.fwd_msg_id);
} else if (retryMessageObject.messageOwner.fwd_from != null) {
reqSend.id.add(retryMessageObject.messageOwner.fwd_from.channel_post);
}
}
performSendMessageRequest(reqSend, newMsgObj, null, null, parentObject, params, scheduleDate != 0);
} else if (type == 9) {
TLRPC.TL_messages_sendInlineBotResult reqSend = new TLRPC.TL_messages_sendInlineBotResult();
reqSend.peer = sendToPeer;
reqSend.random_id = newMsg.random_id;
if (newMsg.from_id != null) {
reqSend.send_as = getMessagesController().getInputPeer(newMsg.from_id);
}
reqSend.hide_via = !params.containsKey("bot");
if (newMsg.reply_to != null && newMsg.reply_to.reply_to_msg_id != 0) {
reqSend.flags |= 1;
reqSend.reply_to_msg_id = newMsg.reply_to.reply_to_msg_id;
}
reqSend.silent = newMsg.silent;
if (scheduleDate != 0) {
reqSend.schedule_date = scheduleDate;
reqSend.flags |= 1024;
}
reqSend.query_id = Utilities.parseLong(params.get("query_id"));
reqSend.id = params.get("id");
if (retryMessageObject == null) {
reqSend.clear_draft = true;
getMediaDataController().cleanDraft(peer, replyToTopMsg != null ? replyToTopMsg.getId() : 0, false);
}
performSendMessageRequest(reqSend, newMsgObj, null, null, parentObject, params, scheduleDate != 0);
}
} catch (Exception e) {
FileLog.e(e);
getMessagesStorage().markMessageAsSendError(newMsg, scheduleDate != 0);
if (newMsgObj != null) {
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
}
getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, newMsg.id);
processSentMessage(newMsg.id);
}
}
use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.
the class SharedConfig method saveProxyList.
public static void saveProxyList() {
SerializedData serializedData = new SerializedData();
int count = proxyList.size();
serializedData.writeInt32(count);
for (int a = 0; a < count; a++) {
ProxyInfo info = proxyList.get(a);
serializedData.writeString(info.address != null ? info.address : "");
serializedData.writeInt32(info.port);
serializedData.writeString(info.username != null ? info.username : "");
serializedData.writeString(info.password != null ? info.password : "");
serializedData.writeString(info.secret != null ? info.secret : "");
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putString("proxy_list", Base64.encodeToString(serializedData.toByteArray(), Base64.NO_WRAP)).commit();
serializedData.cleanup();
}
Aggregations