use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method processNewMessages.
private void processNewMessages(ArrayList<MessageObject> arr) {
long currentUserId = getUserConfig().getClientUserId();
boolean updateChat = false;
boolean hasFromMe = false;
boolean isAd = false;
if (chatListItemAnimator != null) {
chatListItemAnimator.setShouldAnimateEnterFromBottom(true);
}
boolean notifiedSearch = false;
LongSparseArray<Long> scheduledGroupReplacement = null;
for (int a = 0, N = arr.size(); a < N; a++) {
MessageObject messageObject = arr.get(a);
if (!isAd) {
isAd = messageObject.isSponsored();
}
int messageId = messageObject.getId();
if (threadMessageId != 0) {
if (messageId > 0 && messageId <= (messageObject.isOut() ? threadMaxOutboxReadId : threadMaxInboxReadId)) {
messageObject.setIsRead();
}
}
if (currentEncryptedChat == null && !forwardEndReached[0] && messageId < 0) {
pendingSendMessagesDict.put(messageId, messageObject);
pendingSendMessages.add(0, messageObject);
}
if (messageObject.isDice() && !messageObject.isForwarded()) {
messageObject.wasUnread = true;
}
if (chatMode == MODE_SCHEDULED && messageObject.hasValidGroupId() && messagesDict[0].indexOfKey(messageObject.getId()) >= 0) {
long groupId = messageObject.getGroupId();
if (scheduledGroupReplacement == null) {
scheduledGroupReplacement = new LongSparseArray<>();
}
Long localId = scheduledGroupReplacement.get(groupId);
if (localId == null) {
localId = Utilities.random.nextLong();
scheduledGroupReplacement.put(groupId, localId);
}
messageObject.localGroupId = localId;
}
if (messageObject.isOut()) {
if (!notifiedSearch) {
notifiedSearch = true;
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.closeSearchByActiveAction);
}
if (currentChat != null) {
TLRPC.Chat newChat = getMessagesController().getChat(currentChat.id);
if (newChat != null) {
currentChat = newChat;
if (!newChat.gigagroup && newChat.slowmode_enabled && messageObject.isSent() && chatMode != MODE_SCHEDULED) {
if (chatInfo != null) {
int date = messageObject.messageOwner.date + chatInfo.slowmode_seconds;
int currentTime = getConnectionsManager().getCurrentTime();
if (date > getConnectionsManager().getCurrentTime()) {
chatInfo.slowmode_next_send_date = Math.max(chatInfo.slowmode_next_send_date, Math.min(currentTime + chatInfo.slowmode_seconds, date));
if (chatActivityEnterView != null) {
chatActivityEnterView.setSlowModeTimer(chatInfo.slowmode_next_send_date);
}
}
}
getMessagesController().loadFullChat(currentChat.id, 0, true);
}
}
}
}
if (currentChat != null) {
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser && messageObject.messageOwner.action.user_id == currentUserId || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser && messageObject.messageOwner.action.users.contains(currentUserId)) {
TLRPC.Chat newChat = getMessagesController().getChat(currentChat.id);
if (newChat != null) {
currentChat = newChat;
checkActionBarMenu(false);
updateBottomOverlay();
if (avatarContainer != null) {
avatarContainer.updateSubtitle(true);
}
}
}
} else if (inlineReturn != 0) {
if (messageObject.messageOwner.reply_markup != null) {
for (int b = 0; b < messageObject.messageOwner.reply_markup.rows.size(); b++) {
TLRPC.TL_keyboardButtonRow row = messageObject.messageOwner.reply_markup.rows.get(b);
for (int c = 0; c < row.buttons.size(); c++) {
TLRPC.KeyboardButton button = row.buttons.get(c);
if (button instanceof TLRPC.TL_keyboardButtonSwitchInline) {
processSwitchButton((TLRPC.TL_keyboardButtonSwitchInline) button);
break;
}
}
}
}
}
if (messageObject.getReplyMsgId() != 0 && messageObject.replyMessageObject == null) {
messageObject.replyMessageObject = messagesDict[0].get(messageObject.getReplyMsgId());
if (messageObject.replyMessageObject == null && messageObject.getDialogId() != mergeDialogId) {
messageObject.replyMessageObject = repliesMessagesDict.get(messageObject.getReplyMsgId());
}
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
messageObject.generatePinMessageText(null, null);
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
messageObject.generateGameMessageText(null);
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
messageObject.generatePaymentSentMessageText(null);
}
}
if (messageObject.replyMessageObject != null) {
repliesMessagesDict.put(messageObject.replyMessageObject.getId(), messageObject.replyMessageObject);
addReplyMessageOwner(messageObject, 0);
}
}
if (chatMode == MODE_SCHEDULED && !arr.isEmpty()) {
replaceMessageObjects(arr, 0, true);
}
boolean needMoveScrollToLastMessage = false;
boolean reloadMegagroup = false;
if (!forwardEndReached[0]) {
int currentMaxDate = Integer.MIN_VALUE;
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
if (obj.isOut()) {
rotateMotionBackgroundDrawable();
}
if (threadMessageId != 0 && threadMessageId != obj.getReplyTopMsgId() && threadMessageId != obj.getReplyMsgId()) {
continue;
}
int messageId = obj.getId();
if (obj.isOut() && waitingForSendingMessageLoad) {
waitingForSendingMessageLoad = false;
chatActivityEnterView.hideTopView(true);
if (changeBoundAnimator != null) {
changeBoundAnimator.start();
}
}
if (chatMode != MODE_SCHEDULED && currentUser != null && (currentUser.bot && obj.isOut() || currentUser.id == currentUserId)) {
obj.setIsRead();
}
TLRPC.MessageAction action = obj.messageOwner.action;
if (avatarContainer != null && currentEncryptedChat != null && action instanceof TLRPC.TL_messageEncryptedAction && action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
avatarContainer.setTime(action.encryptedAction.ttl_seconds);
}
if (action instanceof TLRPC.TL_messageActionChatMigrateTo) {
migrateToNewChat(obj);
return;
} else if (currentChat != null && currentChat.megagroup && (action instanceof TLRPC.TL_messageActionChatAddUser || action instanceof TLRPC.TL_messageActionChatDeleteUser)) {
reloadMegagroup = true;
}
if (a == 0 && obj.shouldAnimateSending() && chatMode != MODE_SCHEDULED) {
needAnimateToMessage = obj;
}
if (obj.isOut() && obj.wasJustSent) {
scrollToLastMessage(true);
return;
}
if (obj.type < 0 || messagesDict[0].indexOfKey(messageId) >= 0) {
continue;
}
if (currentChat != null && currentChat.creator && (!ChatObject.isChannel(currentChat) || currentChat.megagroup) && (action instanceof TLRPC.TL_messageActionChatCreate || action instanceof TLRPC.TL_messageActionChatEditPhoto && messages.size() < 2)) {
continue;
}
if (action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
continue;
}
if (threadMessageId != 0 && obj.messageOwner instanceof TLRPC.TL_messageEmpty) {
continue;
}
if (threadMessageObject != null && obj.isReply() && !(obj.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage)) {
int mid = obj.getReplyAnyMsgId();
if (threadMessageObject.getId() == mid) {
threadMessageObject.messageOwner.replies.replies++;
}
}
addToPolls(obj, null);
obj.checkLayout();
currentMaxDate = Math.max(currentMaxDate, obj.messageOwner.date);
if (messageId > 0) {
last_message_id = Math.max(last_message_id, messageId);
} else if (currentEncryptedChat != null) {
last_message_id = Math.min(last_message_id, messageId);
}
if (threadMessageId == 0) {
if (obj.messageOwner.mentioned && obj.isContentUnread()) {
newMentionsCount++;
}
}
if (!isAd) {
newUnreadMessageCount++;
}
if (obj.type == 10 || obj.type == 11) {
updateChat = true;
}
}
if (newUnreadMessageCount != 0 && pagedownButtonCounter != null) {
pagedownButtonCounter.setVisibility(View.VISIBLE);
if (prevSetUnreadCount != newUnreadMessageCount) {
prevSetUnreadCount = newUnreadMessageCount;
pagedownButtonCounter.setCount(newUnreadMessageCount, true);
}
}
if (newMentionsCount != 0 && mentiondownButtonCounter != null) {
mentiondownButtonCounter.setVisibility(View.VISIBLE);
mentiondownButtonCounter.setText(String.format("%d", newMentionsCount));
showMentionDownButton(true, true);
}
updateVisibleRows();
} else {
LongSparseArray<MessageObject.GroupedMessages> newGroups = null;
HashMap<String, ArrayList<MessageObject>> webpagesToReload = null;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("received new messages " + arr.size() + " in dialog " + dialog_id);
}
MessageObject lastActionSetChatThemeMessageObject = null;
for (int a = 0; a < arr.size(); a++) {
MessageObject obj = arr.get(a);
if (obj.scheduled != (chatMode == MODE_SCHEDULED) || threadMessageId != 0 && threadMessageId != obj.getReplyTopMsgId() && threadMessageId != obj.getReplyMsgId()) {
continue;
}
if (obj.isOut()) {
rotateMotionBackgroundDrawable();
}
int placeToPaste = -1;
int messageId = obj.getId();
if (chatMode == MODE_SCHEDULED && messagesDict[0].indexOfKey(messageId) >= 0) {
MessageObject removed = messagesDict[0].get(messageId);
messagesDict[0].remove(messageId);
if (removed != null) {
int index = messages.indexOf(removed);
messages.remove(index);
ArrayList<MessageObject> dayArr = messagesByDays.get(removed.dateKey);
dayArr.remove(removed);
if (dayArr.isEmpty()) {
messagesByDays.remove(removed.dateKey);
if (index >= 0 && index < messages.size()) {
messages.remove(index);
}
}
if (removed.hasValidGroupId()) {
MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(removed.getGroupId());
groupedMessages.messages.remove(removed);
if (newGroups == null) {
newGroups = new LongSparseArray<>();
}
newGroups.put(groupedMessages.groupId, groupedMessages);
}
if (chatAdapter != null) {
chatAdapter.notifyDataSetChanged(true);
}
}
}
if (isSecretChat()) {
checkSecretMessageForLocation(obj);
}
if (chatMode != MODE_SCHEDULED && currentUser != null && (currentUser.bot && obj.isOut() || currentUser.id == currentUserId)) {
obj.setIsRead();
}
TLRPC.MessageAction action = obj.messageOwner.action;
if (avatarContainer != null && currentEncryptedChat != null && action instanceof TLRPC.TL_messageEncryptedAction && action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
avatarContainer.setTime(action.encryptedAction.ttl_seconds);
}
if (obj.type < 0 || messagesDict[0].indexOfKey(messageId) >= 0) {
continue;
}
if (currentChat != null && currentChat.creator && (!ChatObject.isChannel(currentChat) || currentChat.megagroup) && (action instanceof TLRPC.TL_messageActionChatCreate || action instanceof TLRPC.TL_messageActionChatEditPhoto && messages.size() < 2)) {
continue;
}
if (action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
continue;
}
if (threadMessageId != 0 && obj.messageOwner instanceof TLRPC.TL_messageEmpty) {
continue;
}
if (threadMessageObject != null && threadMessageObject.messageOwner.replies != null && obj.isReply() && !(obj.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage)) {
int mid = obj.getReplyAnyMsgId();
if (threadMessageObject.getId() == mid) {
threadMessageObject.messageOwner.replies.replies++;
}
}
addToPolls(obj, null);
if (a == 0 && obj.shouldAnimateSending() && chatMode != MODE_SCHEDULED) {
animatingMessageObjects.add(obj);
}
MessageObject.GroupedMessages groupedMessages;
if (obj.hasValidGroupId()) {
groupedMessages = groupedMessagesMap.get(obj.getGroupId());
if (groupedMessages == null) {
groupedMessages = new MessageObject.GroupedMessages();
groupedMessages.groupId = obj.getGroupId();
groupedMessagesMap.put(groupedMessages.groupId, groupedMessages);
}
if (newGroups == null) {
newGroups = new LongSparseArray<>();
}
newGroups.put(groupedMessages.groupId, groupedMessages);
groupedMessages.messages.add(obj);
} else {
groupedMessages = null;
}
if (groupedMessages != null) {
int size = groupedMessages.messages.size();
MessageObject messageObject = size > 1 ? groupedMessages.messages.get(groupedMessages.messages.size() - 2) : null;
if (messageObject != null) {
placeToPaste = messages.indexOf(messageObject);
}
}
if (placeToPaste == -1) {
if (!obj.scheduled && obj.messageOwner.id < 0 || messages.isEmpty()) {
placeToPaste = 0;
} else {
int size = messages.size();
for (int b = 0; b < size; b++) {
MessageObject lastMessage = messages.get(b);
if (lastMessage.type >= 0 && lastMessage.messageOwner.date > 0) {
if (chatMode != MODE_SCHEDULED && lastMessage.messageOwner.id > 0 && obj.messageOwner.id > 0 && lastMessage.messageOwner.id < obj.messageOwner.id || lastMessage.messageOwner.date <= obj.messageOwner.date) {
MessageObject.GroupedMessages lastGroupedMessages;
if (lastMessage.getGroupId() != 0) {
lastGroupedMessages = groupedMessagesMap.get(lastMessage.getGroupId());
if (lastGroupedMessages != null && lastGroupedMessages.messages.size() == 0) {
lastGroupedMessages = null;
}
} else {
lastGroupedMessages = null;
}
if (lastGroupedMessages == null) {
placeToPaste = b;
} else {
placeToPaste = messages.indexOf(lastGroupedMessages.messages.get(lastGroupedMessages.messages.size() - 1));
}
break;
}
}
}
if (placeToPaste == -1 || placeToPaste > messages.size()) {
placeToPaste = messages.size();
}
}
}
if (currentEncryptedChat != null && obj.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && obj.messageOwner.media.webpage instanceof TLRPC.TL_webPageUrlPending) {
if (webpagesToReload == null) {
webpagesToReload = new HashMap<>();
}
ArrayList<MessageObject> arrayList = webpagesToReload.get(obj.messageOwner.media.webpage.url);
if (arrayList == null) {
arrayList = new ArrayList<>();
webpagesToReload.put(obj.messageOwner.media.webpage.url, arrayList);
}
arrayList.add(obj);
}
obj.checkLayout();
if (action instanceof TLRPC.TL_messageActionChatMigrateTo) {
migrateToNewChat(obj);
if (newGroups != null) {
for (int b = 0; b < newGroups.size(); b++) {
newGroups.valueAt(b).calculate();
}
}
return;
} else if (currentChat != null && currentChat.megagroup && (action instanceof TLRPC.TL_messageActionChatAddUser || action instanceof TLRPC.TL_messageActionChatDeleteUser)) {
reloadMegagroup = true;
}
if (minDate[0] == 0 || obj.messageOwner.date < minDate[0]) {
minDate[0] = obj.messageOwner.date;
}
if (obj.isOut() && !obj.messageOwner.from_scheduled) {
removeUnreadPlane(true);
hideInfoView();
hasFromMe = true;
}
if (messageId > 0) {
maxMessageId[0] = Math.min(messageId, maxMessageId[0]);
minMessageId[0] = Math.max(messageId, minMessageId[0]);
} else if (currentEncryptedChat != null) {
maxMessageId[0] = Math.max(messageId, maxMessageId[0]);
minMessageId[0] = Math.min(messageId, minMessageId[0]);
}
maxDate[0] = Math.max(maxDate[0], obj.messageOwner.date);
messagesDict[0].put(messageId, obj);
ArrayList<MessageObject> dayArray;
if (isAd && !messages.isEmpty()) {
dayArray = messagesByDays.get(messages.get(0).dateKey);
} else {
dayArray = messagesByDays.get(obj.dateKey);
}
if (placeToPaste > messages.size()) {
placeToPaste = messages.size();
}
int sponsoredMessagesCount = getSponsoredMessagesCount();
if (!isAd && placeToPaste < sponsoredMessagesCount) {
placeToPaste = sponsoredMessagesCount;
}
if (dayArray == null) {
dayArray = new ArrayList<>();
messagesByDays.put(obj.dateKey, dayArray);
TLRPC.Message dateMsg = new TLRPC.TL_message();
if (chatMode == MODE_SCHEDULED) {
if (obj.messageOwner.date == 0x7ffffffe) {
dateMsg.message = LocaleController.getString("MessageScheduledUntilOnline", R.string.MessageScheduledUntilOnline);
} else {
dateMsg.message = LocaleController.formatString("MessageScheduledOn", R.string.MessageScheduledOn, LocaleController.formatDateChat(obj.messageOwner.date, true));
}
} else {
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
}
dateMsg.id = 0;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(((long) obj.messageOwner.date) * 1000);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
dateMsg.date = (int) (calendar.getTimeInMillis() / 1000);
MessageObject dateObj = new MessageObject(currentAccount, dateMsg, false, false);
dateObj.type = 10;
dateObj.contentType = 1;
dateObj.isDateObject = true;
dateObj.stableId = lastStableId++;
messages.add(placeToPaste, dateObj);
if (chatAdapter != null) {
chatAdapter.notifyItemInserted(placeToPaste);
}
}
if (!(obj.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached) && (!obj.isOut() || obj.messageOwner.from_scheduled)) {
if (paused && placeToPaste == 0) {
if (!scrollToTopUnReadOnResume && unreadMessageObject != null) {
removeMessageObject(unreadMessageObject);
unreadMessageObject = null;
}
if (unreadMessageObject == null) {
TLRPC.Message dateMsg = new TLRPC.TL_message();
dateMsg.message = "";
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(currentAccount, dateMsg, false, false);
dateObj.type = 6;
dateObj.contentType = 2;
dateObj.stableId = lastStableId++;
messages.add(0, dateObj);
if (chatAdapter != null) {
chatAdapter.notifyItemInserted(0);
}
unreadMessageObject = dateObj;
scrollToMessage = unreadMessageObject;
scrollToMessagePosition = -10000;
scrollToTopUnReadOnResume = true;
}
}
}
dayArray.add(0, obj);
if (chatAdapter != null && placeToPaste < messages.size()) {
MessageObject prevMessage = messages.get(placeToPaste);
if (prevMessage.hasValidGroupId() && prevMessage.getGroupId() != obj.getGroupId()) {
MessageObject.GroupedMessages group = groupedMessagesMap.get(prevMessage.getGroupId());
if (group != null && group.messages.size() > 1) {
int size = group.messages.size();
chatAdapter.notifyItemRangeChanged(1, size - 1);
}
}
}
obj.stableId = lastStableId++;
messages.add(placeToPaste, obj);
if (placeToPaste == 0 && !obj.isSponsored()) {
needMoveScrollToLastMessage = true;
}
if (chatAdapter != null) {
chatAdapter.notifyItemChanged(placeToPaste);
chatAdapter.notifyItemInserted(placeToPaste);
}
if (obj.isOut() && waitingForSendingMessageLoad) {
waitingForSendingMessageLoad = false;
if (!animatingMessageObjects.contains(obj)) {
chatActivityEnterView.hideTopView(true);
}
if (changeBoundAnimator != null) {
changeBoundAnimator.start();
}
}
if (threadMessageId == 0) {
if (!obj.isOut() && obj.messageOwner.mentioned && obj.isContentUnread()) {
newMentionsCount++;
}
}
if (!isAd) {
newUnreadMessageCount++;
}
if (obj.type == 10 || obj.type == 11) {
updateChat = true;
}
if (obj.messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) {
lastActionSetChatThemeMessageObject = obj;
}
}
if (lastActionSetChatThemeMessageObject != null && lastActionSetChatThemeMessageObject.messageOwner != null && lastActionSetChatThemeMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) {
TLRPC.TL_messageActionSetChatTheme action = (TLRPC.TL_messageActionSetChatTheme) lastActionSetChatThemeMessageObject.messageOwner.action;
setChatThemeEmoticon(action.emoticon);
}
if (webpagesToReload != null) {
getMessagesController().reloadWebPages(dialog_id, webpagesToReload, chatMode == MODE_SCHEDULED);
}
if (newGroups != null) {
for (int a = 0; a < newGroups.size(); a++) {
MessageObject.GroupedMessages groupedMessages = newGroups.valueAt(a);
int oldCount = groupedMessages.posArray.size();
groupedMessages.calculate();
int newCount = groupedMessages.posArray.size();
if (newCount - oldCount > 0 && chatAdapter != null) {
int index = messages.indexOf(groupedMessages.messages.get(groupedMessages.messages.size() - 1));
if (index >= 0) {
chatAdapter.notifyItemRangeChanged(index, newCount);
}
}
}
}
showProgressView(false);
if (chatAdapter == null) {
scrollToTopOnResume = true;
}
if (chatListView != null && chatAdapter != null) {
int lastVisible = chatLayoutManager.findFirstVisibleItemPosition();
if (lastVisible == RecyclerView.NO_POSITION) {
lastVisible = 0;
}
View child = chatLayoutManager.findViewByPosition(lastVisible);
int diff;
if (child != null) {
diff = child.getBottom() - chatListView.getMeasuredHeight();
} else {
diff = 0;
}
if (!isAd) {
if (lastVisible == 0 && diff <= AndroidUtilities.dp(5) || hasFromMe) {
newUnreadMessageCount = 0;
if (!firstLoading && chatMode != MODE_SCHEDULED) {
if (paused) {
scrollToTopOnResume = true;
} else {
forceScrollToTop = true;
moveScrollToLastMessage(true);
}
}
} else {
if (newUnreadMessageCount != 0 && pagedownButtonCounter != null) {
if (prevSetUnreadCount != newUnreadMessageCount) {
prevSetUnreadCount = newUnreadMessageCount;
pagedownButtonCounter.setCount(newUnreadMessageCount, true);
}
}
canShowPagedownButton = true;
updatePagedownButtonVisibility(true);
}
} else {
if (child != null) {
chatLayoutManager.scrollToPositionWithOffset(lastVisible + 1, chatListView.getMeasuredHeight() - child.getBottom() - chatListView.getPaddingBottom());
}
}
if (newMentionsCount != 0 && mentiondownButtonCounter != null) {
mentiondownButtonCounter.setVisibility(View.VISIBLE);
mentiondownButtonCounter.setText(String.format("%d", newMentionsCount));
showMentionDownButton(true, true);
}
} else {
scrollToTopOnResume = true;
}
}
if (chatMode == MODE_SCHEDULED && !arr.isEmpty()) {
MessageObject messageObject = arr.get(0);
int mid = messageObject.getId();
if (mid < 0) {
if (chatListItemAnimator != null) {
chatListItemAnimator.setShouldAnimateEnterFromBottom(needMoveScrollToLastMessage);
}
if (needMoveScrollToLastMessage) {
moveScrollToLastMessage(false);
} else {
int index = messages.indexOf(messageObject);
if (chatLayoutManager != null && index > 0 && (chatLayoutManager.findViewByPosition(chatAdapter.messagesStartRow + index) != null || chatLayoutManager.findViewByPosition(chatAdapter.messagesStartRow + index - 1) != null)) {
chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + messages.indexOf(messageObject), getScrollOffsetForMessage(messageObject), false);
} else {
AndroidUtilities.runOnUIThread(() -> scrollToMessageId(mid, 0, false, 0, true, 0));
}
}
}
}
if (!messages.isEmpty() && botUser != null && botUser.length() == 0) {
botUser = null;
updateBottomOverlay();
}
if (updateChat) {
updateTitle();
checkAndUpdateAvatar();
}
if (reloadMegagroup) {
getMessagesController().loadFullChat(currentChat.id, 0, true);
}
checkWaitingForReplies();
updateReplyMessageHeader(true);
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method onPause.
@Override
public void onPause() {
super.onPause();
if (scrimPopupWindow != null) {
scrimPopupWindow.setPauseNotifications(false);
closeMenu();
}
int replyId = threadMessageId;
getMessagesController().markDialogAsReadNow(dialog_id, replyId);
MediaController.getInstance().stopRaiseToEarSensors(this, true);
paused = true;
wasPaused = true;
if (chatMode == 0) {
getNotificationsController().setOpenedDialogId(0);
}
Bulletin.removeDelegate(this);
getMessagesController().setLastVisibleDialogId(dialog_id, chatMode == MODE_SCHEDULED, false);
CharSequence draftMessage = null;
MessageObject replyMessage = null;
boolean searchWebpage = true;
if (!ignoreAttachOnPause && chatActivityEnterView != null && bottomOverlayChat != null && bottomOverlayChat.getVisibility() != View.VISIBLE) {
chatActivityEnterView.onPause();
replyMessage = replyingMessageObject;
draftMessage = AndroidUtilities.getTrimmedString(chatActivityEnterView.getDraftMessage());
searchWebpage = chatActivityEnterView.isMessageWebPageSearchEnabled();
chatActivityEnterView.setFieldFocused(false);
}
if (chatAttachAlert != null) {
if (!ignoreAttachOnPause) {
chatAttachAlert.onPause();
} else {
ignoreAttachOnPause = false;
}
}
if (contentView != null) {
contentView.onPause();
}
if (chatMode == 0) {
CharSequence[] message = new CharSequence[] { draftMessage };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 101);
getMediaDataController().saveDraft(dialog_id, threadMessageId, message[0], entities, replyMessage != null ? replyMessage.messageOwner : null, !searchWebpage);
getMessagesController().cancelTyping(0, dialog_id, threadMessageId);
if (!pausedOnLastMessage && !firstLoading) {
SharedPreferences.Editor editor = MessagesController.getNotificationsSettings(currentAccount).edit();
int messageId = 0;
int offset = 0;
if (chatLayoutManager != null) {
boolean sponsoredMessageFound = false;
for (int i = 0; i < chatListView.getChildCount(); i++) {
if (chatListView.getChildAt(i) instanceof ChatMessageCell && ((ChatMessageCell) chatListView.getChildAt(i)).getMessageObject().isSponsored()) {
sponsoredMessageFound = true;
break;
}
}
int position = chatLayoutManager.findFirstVisibleItemPosition();
if (position != 0 && !sponsoredMessageFound) {
RecyclerListView.Holder holder = (RecyclerListView.Holder) chatListView.findViewHolderForAdapterPosition(position);
if (holder != null) {
int mid = 0;
if (holder.itemView instanceof ChatMessageCell) {
mid = ((ChatMessageCell) holder.itemView).getMessageObject().getId();
} else if (holder.itemView instanceof ChatActionCell) {
mid = ((ChatActionCell) holder.itemView).getMessageObject().getId();
}
if (mid == 0) {
holder = (RecyclerListView.Holder) chatListView.findViewHolderForAdapterPosition(position + 1);
}
boolean ignore = false;
int count = 0;
for (int a = position - 1; a >= chatAdapter.messagesStartRow; a--) {
int num = a - chatAdapter.messagesStartRow;
if (num < 0 || num >= messages.size()) {
continue;
}
MessageObject messageObject = messages.get(num);
if (messageObject.getId() == 0) {
continue;
}
if ((!messageObject.isOut() || messageObject.messageOwner.from_scheduled) && messageObject.isUnread()) {
ignore = true;
messageId = 0;
}
if (count > 2) {
break;
}
count++;
}
if (holder != null && !ignore) {
if (holder.itemView instanceof ChatMessageCell) {
messageId = ((ChatMessageCell) holder.itemView).getMessageObject().getId();
} else if (holder.itemView instanceof ChatActionCell) {
messageId = ((ChatActionCell) holder.itemView).getMessageObject().getId();
}
if (messageId > 0 && currentEncryptedChat == null || messageId < 0 && currentEncryptedChat != null) {
offset = holder.itemView.getBottom() - chatListView.getMeasuredHeight();
if (BuildVars.LOGS_ENABLED) {
FileLog.d("save offset = " + offset + " for mid " + messageId);
}
} else {
messageId = 0;
}
}
}
}
}
if (messageId != 0) {
editor.putInt("diditem" + dialog_id, messageId);
editor.putInt("diditemo" + dialog_id, offset);
} else {
pausedOnLastMessage = true;
editor.remove("diditem" + dialog_id);
editor.remove("diditemo" + dialog_id);
}
editor.commit();
}
if (currentUser != null) {
chatLeaveTime = System.currentTimeMillis();
updateInformationForScreenshotDetector();
}
hideUndoViews();
}
if (chatListItemAnimator != null) {
chatListItemAnimator.endAnimations();
}
if (chatScrollHelper != null) {
chatScrollHelper.cancel();
}
if (AvatarPreviewer.hasVisibleInstance()) {
AvatarPreviewer.getInstance().close();
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method openVideoEditor.
public void openVideoEditor(String videoPath, String caption) {
if (getParentActivity() != null) {
final Bitmap thumb = SendMessagesHelper.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
final ArrayList<Object> cameraPhoto = new ArrayList<>();
MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, 0, 0, videoPath, 0, true, 0, 0, 0);
entry.caption = caption;
cameraPhoto.add(entry);
PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 0, false, new PhotoViewer.EmptyPhotoViewerProvider() {
@Override
public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
return new ImageReceiver.BitmapHolder(thumb, null, 0);
}
@Override
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
sendMedia((MediaController.PhotoEntry) cameraPhoto.get(0), videoEditedInfo, notify, scheduleDate, forceDocument);
}
@Override
public boolean canScrollAway() {
return false;
}
}, this);
} else {
fillEditingMediaWithCaption(caption, null);
SendMessagesHelper.prepareSendingVideo(getAccountInstance(), videoPath, null, dialog_id, replyingMessageObject, getThreadMessage(), null, null, 0, editingMessageObject, true, 0, false);
afterMessageSend();
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method setInPreviewMode.
@Override
protected void setInPreviewMode(boolean value) {
super.setInPreviewMode(value);
if (avatarContainer != null) {
avatarContainer.setOccupyStatusBar(!value);
avatarContainer.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, !value ? 56 : (chatMode == MODE_PINNED ? 10 : 0), 0, 40, 0));
}
if (chatActivityEnterView != null) {
chatActivityEnterView.setVisibility(!value ? View.VISIBLE : View.INVISIBLE);
}
if (actionBar != null) {
actionBar.setBackButtonDrawable(!value ? new BackDrawable(false) : null);
if (headerItem != null) {
headerItem.setAlpha(!value ? 1.0f : 0.0f);
}
if (attachItem != null) {
attachItem.setAlpha(!value ? 1.0f : 0.0f);
}
}
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
MessageObject message = null;
if (view instanceof ChatMessageCell) {
message = ((ChatMessageCell) view).getMessageObject();
} else if (view instanceof ChatActionCell) {
message = ((ChatActionCell) view).getMessageObject();
}
if (message != null && message.messageOwner != null && message.messageOwner.media_unread && message.messageOwner.mentioned) {
if (!message.isVoice() && !message.isRoundVideo()) {
newMentionsCount--;
if (newMentionsCount <= 0) {
newMentionsCount = 0;
hasAllMentionsLocal = true;
showMentionDownButton(false, true);
} else {
mentiondownButtonCounter.setText(String.format("%d", newMentionsCount));
}
getMessagesController().markMentionMessageAsRead(message.getId(), ChatObject.isChannel(currentChat) ? currentChat.id : 0, dialog_id);
message.setContentIsRead();
}
if (view instanceof ChatMessageCell) {
((ChatMessageCell) view).setHighlighted(false);
((ChatMessageCell) view).setHighlightedAnimated();
}
}
}
chatListView.setItemAnimator(null);
}
updateBottomOverlay();
updateSecretStatus();
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method checkSecretMessageForLocation.
private void checkSecretMessageForLocation(MessageObject messageObject) {
if (messageObject.type != 4 || locationAlertShown || SharedConfig.isSecretMapPreviewSet()) {
return;
}
locationAlertShown = true;
AlertsCreator.showSecretLocationAlert(getParentActivity(), currentAccount, () -> {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject message = cell.getMessageObject();
if (message.type == 4) {
cell.forceResetMessageObject();
}
}
}
}, true, themeDelegate);
}
Aggregations