Java Code Examples for org.telegram.messenger.MessageObject#getId()

The following examples show how to use org.telegram.messenger.MessageObject#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setDialog(long dialog_id, MessageObject messageObject, int date, boolean useMe) {
    currentDialogId = dialog_id;
    message = messageObject;
    useMeForMyMessages = useMe;
    isDialogCell = false;
    lastMessageDate = date;
    currentEditDate = messageObject != null ? messageObject.messageOwner.edit_date : 0;
    unreadCount = 0;
    markUnread = false;
    messageId = messageObject != null ? messageObject.getId() : 0;
    mentionCount = 0;
    lastUnreadState = messageObject != null && messageObject.isUnread();
    if (message != null) {
        lastSendState = message.messageOwner.send_state;
    }
    update(0);
}
 
Example 2
Source File: DialogCell.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setDialog(long dialog_id, MessageObject messageObject, int date, boolean useMe) {
    currentDialogId = dialog_id;
    message = messageObject;
    useMeForMyMessages = useMe;
    isDialogCell = false;
    lastMessageDate = date;
    currentEditDate = messageObject != null ? messageObject.messageOwner.edit_date : 0;
    unreadCount = 0;
    markUnread = false;
    messageId = messageObject != null ? messageObject.getId() : 0;
    mentionCount = 0;
    lastUnreadState = messageObject != null && messageObject.isUnread();
    if (message != null) {
        lastSendState = message.messageOwner.send_state;
    }
    update(0);
}
 
Example 3
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void checkVisibility() {
    boolean show = false;
    if (isLocation) {
        if (fragment instanceof DialogsActivity) {
            show = LocationController.getLocationsCount() != 0;
        } else {
            show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
        }
    } else {
        if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING) {
            show = true;
        } else {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0) {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
 
Example 4
Source File: DialogCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setDialog(long dialog_id, MessageObject messageObject, int date)
{
    currentDialogId = dialog_id;
    message = messageObject;
    isDialogCell = false;
    lastMessageDate = date;
    currentEditDate = messageObject != null ? messageObject.messageOwner.edit_date : 0;
    unreadCount = 0;
    markUnread = false;
    messageId = messageObject != null ? messageObject.getId() : 0;
    mentionCount = 0;
    lastUnreadState = messageObject != null && messageObject.isUnread();
    if (message != null)
    {
        lastSendState = message.messageOwner.send_state;
    }
    update(0);
}
 
Example 5
Source File: DialogCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setDialog(long dialog_id, MessageObject messageObject, int date)
{
    currentDialogId = dialog_id;
    message = messageObject;
    isDialogCell = false;
    lastMessageDate = date;
    currentEditDate = messageObject != null ? messageObject.messageOwner.edit_date : 0;
    unreadCount = 0;
    markUnread = false;
    messageId = messageObject != null ? messageObject.getId() : 0;
    mentionCount = 0;
    lastUnreadState = messageObject != null && messageObject.isUnread();
    if (message != null)
    {
        lastSendState = message.messageOwner.send_state;
    }
    update(0);
}
 
Example 6
Source File: PopupNotificationActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void getNewMessage() {
    if (popupMessages.isEmpty()) {
        onFinish();
        finish();
        return;
    }

    boolean found = false;
    if ((currentMessageNum != 0 || chatActivityEnterView.hasText() || startedMoving) && currentMessageObject != null) {
        for (int a = 0, size = popupMessages.size(); a < size; a++) {
            MessageObject messageObject = popupMessages.get(a);
            if (messageObject.currentAccount == currentMessageObject.currentAccount && messageObject.getDialogId() == currentMessageObject.getDialogId() && messageObject.getId() == currentMessageObject.getId()) {
                currentMessageNum = a;
                found = true;
                break;
            }
        }
    }
    if (!found) {
        currentMessageNum = 0;
        currentMessageObject = popupMessages.get(0);
        updateInterfaceForCurrentMessage(0);
    } else if (startedMoving) {
        if (currentMessageNum == popupMessages.size() - 1) {
            prepareLayouts(3);
        } else if (currentMessageNum == 1) {
            prepareLayouts(4);
        }
    }
    countText.setText(String.format("%d/%d", currentMessageNum + 1, popupMessages.size()));
}
 
Example 7
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void checkVisibility()
{
    boolean show = false;
    if (isLocation)
    {
        if (fragment instanceof DialogsActivity)
        {
            show = LocationController.getLocationsCount() != 0;
        }
        else
        {
            show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
        }
    }
    else
    {
        if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING)
        {
            show = true;
        }
        else
        {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0)
            {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
 
Example 8
Source File: MediaActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean addMessage(MessageObject messageObject, boolean isNew, boolean enc) {
    int loadIndex = messageObject.getDialogId() == dialog_id ? 0 : 1;
    if (messagesDict[loadIndex].indexOfKey(messageObject.getId()) >= 0) {
        return false;
    }
    ArrayList<MessageObject> messageObjects = sectionArrays.get(messageObject.monthKey);
    if (messageObjects == null) {
        messageObjects = new ArrayList<>();
        sectionArrays.put(messageObject.monthKey, messageObjects);
        if (isNew) {
            sections.add(0, messageObject.monthKey);
        } else {
            sections.add(messageObject.monthKey);
        }
    }
    if (isNew) {
        messageObjects.add(0, messageObject);
        messages.add(0, messageObject);
    } else {
        messageObjects.add(messageObject);
        messages.add(messageObject);
    }
    messagesDict[loadIndex].put(messageObject.getId(), messageObject);
    if (!enc) {
        if (messageObject.getId() > 0) {
            max_id[loadIndex] = Math.min(messageObject.getId(), max_id[loadIndex]);
        }
    } else {
        max_id[loadIndex] = Math.max(messageObject.getId(), max_id[loadIndex]);
    }
    return true;
}
 
Example 9
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void checkVisibility()
{
    boolean show = false;
    if (isLocation)
    {
        if (fragment instanceof DialogsActivity)
        {
            show = LocationController.getLocationsCount() != 0;
        }
        else
        {
            show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
        }
    }
    else
    {
        if (VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING)
        {
            show = true;
        }
        else
        {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0)
            {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
 
Example 10
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void draw(MessageObject messageObject, MessageObject.TextLayoutBlock block, Canvas canvas) {
    if (selectedView == null || selectedView.getMessageObject() == null || isDescription) {
        return;
    }

    MessageObject selectedMessageObject = selectedView.getMessageObject();
    if (selectedMessageObject == null || selectedMessageObject.textLayoutBlocks == null) {
        return;
    }

    if (messageObject.getId() == selectedCellId) {
        int selectionStart = this.selectionStart;
        int selectionEnd = this.selectionEnd;
        if (selectedMessageObject.textLayoutBlocks.size() > 1) {
            if (selectionStart < block.charactersOffset) {
                selectionStart = block.charactersOffset;
            }
            if (selectionStart > block.charactersEnd) {
                selectionStart = block.charactersEnd;
            }
            if (selectionEnd < block.charactersOffset) {
                selectionEnd = block.charactersOffset;
            }
            if (selectionEnd > block.charactersEnd) {
                selectionEnd = block.charactersEnd;
            }
        }

        if (selectionStart != selectionEnd) {
            if (selectedMessageObject.isOutOwner()) {
                selectionPaint.setColor(Theme.getColor(Theme.key_chat_outTextSelectionHighlight));
            } else {
                selectionPaint.setColor(Theme.getColor(key_chat_inTextSelectionHighlight));
            }
            drawSelection(canvas, block.textLayout, selectionStart, selectionEnd);
        }
    }
}
 
Example 11
Source File: MediaActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean addMessage(MessageObject messageObject, boolean isNew, boolean enc) {
    int loadIndex = messageObject.getDialogId() == dialog_id ? 0 : 1;
    if (messagesDict[loadIndex].indexOfKey(messageObject.getId()) >= 0) {
        return false;
    }
    ArrayList<MessageObject> messageObjects = sectionArrays.get(messageObject.monthKey);
    if (messageObjects == null) {
        messageObjects = new ArrayList<>();
        sectionArrays.put(messageObject.monthKey, messageObjects);
        if (isNew) {
            sections.add(0, messageObject.monthKey);
        } else {
            sections.add(messageObject.monthKey);
        }
    }
    if (isNew) {
        messageObjects.add(0, messageObject);
        messages.add(0, messageObject);
    } else {
        messageObjects.add(messageObject);
        messages.add(messageObject);
    }
    messagesDict[loadIndex].put(messageObject.getId(), messageObject);
    if (!enc) {
        if (messageObject.getId() > 0) {
            max_id[loadIndex] = Math.min(messageObject.getId(), max_id[loadIndex]);
        }
    } else {
        max_id[loadIndex] = Math.max(messageObject.getId(), max_id[loadIndex]);
    }
    return true;
}
 
Example 12
Source File: SecretMediaViewer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean isShowingImage(MessageObject object) {
    return isVisible && !disableShowCheck && object != null && currentMessageObject != null && currentMessageObject.getId() == object.getId();
}
 
Example 13
Source File: AudioPlayerAlert.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void updateTitle(boolean shutdown) {
    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null && shutdown || messageObject != null && !messageObject.isMusic()) {
        dismiss();
    } else {
        if (messageObject == null) {
            return;
        }
        if (messageObject.eventId != 0 || messageObject.getId() <= -2000000000) {
            hasOptions = false;
            menuItem.setVisibility(View.INVISIBLE);
            optionsButton.setVisibility(View.INVISIBLE);
        } else {
            hasOptions = true;
            if (!actionBar.isSearchFieldVisible()) {
                menuItem.setVisibility(View.VISIBLE);
            }
            optionsButton.setVisibility(View.VISIBLE);
        }
        checkIfMusicDownloaded(messageObject);
        updateProgress(messageObject);

        if (MediaController.getInstance().isMessagePaused()) {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
        } else {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_pause, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
        }
        String title = messageObject.getMusicTitle();
        String author = messageObject.getMusicAuthor();
        titleTextView.setText(title);
        authorTextView.setText(author);
        actionBar.setTitle(title);
        actionBar.setSubtitle(author);

        AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
        if (audioInfo != null && audioInfo.getCover() != null) {
            hasNoCover = false;
            placeholderImageView.setImageBitmap(audioInfo.getCover());
        } else {
            hasNoCover = true;
            placeholderImageView.invalidate();
            placeholderImageView.setImageDrawable(null);
        }

        if (durationTextView != null) {
            int duration = messageObject.getDuration();
            durationTextView.setText(duration != 0 ? String.format("%d:%02d", duration / 60, duration % 60) : "-:--");
        }
    }
}
 
Example 14
Source File: StatisticActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.messagesDidLoad) {
        int guid = (Integer) args[10];
        if (guid == classGuid) {
            ArrayList<MessageObject> messArr = (ArrayList<MessageObject>) args[2];
            ArrayList<RecentPostInfo> deletedMessages = new ArrayList<>();
            int n = messArr.size();
            for (int i = 0; i < n; i++) {
                MessageObject messageObjectFormCache = messArr.get(i);
                int index = recentPostIdtoIndexMap.get(messageObjectFormCache.getId(), -1);
                if (index >= 0 && recentPostsAll.get(index).counters.msg_id == messageObjectFormCache.getId()) {
                    if (messageObjectFormCache.deleted) {
                        deletedMessages.add(recentPostsAll.get(index));
                    } else {
                        recentPostsAll.get(index).message = messageObjectFormCache;
                    }
                }
            }

            recentPostsAll.removeAll(deletedMessages);

            recentPostsLoaded.clear();
            n = recentPostsAll.size();
            for (int i = 0; i < n; i++) {
                RecentPostInfo postInfo = recentPostsAll.get(i);
                if (postInfo.message == null) {
                    loadFromId = postInfo.counters.msg_id;
                    break;
                } else {
                    recentPostsLoaded.add(postInfo);
                }
            }

            if (recentPostsLoaded.size() < 20) {
                loadMessages();
            }
            if (adapter != null) {
                diffUtilsCallback.update();
            }
        }
    }
}
 
Example 15
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void checkDataChanged(MessageObject messageObject) {
    if (selectedCellId == messageObject.getId()) {
        clear(true);
    }
}
 
Example 16
Source File: AudioPlayerAlert.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void updateTitle(boolean shutdown) {
    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null && shutdown || messageObject != null && !messageObject.isMusic()) {
        dismiss();
    } else {
        if (messageObject == null) {
            return;
        }
        if (messageObject.eventId != 0 || messageObject.getId() <= -2000000000) {
            hasOptions = false;
            menuItem.setVisibility(View.INVISIBLE);
            optionsButton.setVisibility(View.INVISIBLE);
        } else {
            hasOptions = true;
            if (!actionBar.isSearchFieldVisible()) {
                menuItem.setVisibility(View.VISIBLE);
            }
            optionsButton.setVisibility(View.VISIBLE);
        }
        checkIfMusicDownloaded(messageObject);
        updateProgress(messageObject);

        if (MediaController.getInstance().isMessagePaused()) {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
            playButton.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
        } else {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_pause, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
            playButton.setContentDescription(LocaleController.getString("AccActionPause", R.string.AccActionPause));
        }
        String title = messageObject.getMusicTitle();
        String author = messageObject.getMusicAuthor();
        titleTextView.setText(title);
        authorTextView.setText(author);
        actionBar.setTitle(title);
        actionBar.setSubtitle(author);

        String loadTitle = author + " " + title;
        AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
        if (audioInfo != null && audioInfo.getCover() != null) {
            hasNoCover = 0;
            placeholderImageView.setImageBitmap(audioInfo.getCover());
        } else {
            String artworkUrl = messageObject.getArtworkUrl(false);
            if (!TextUtils.isEmpty(artworkUrl)) {
                placeholderImageView.setImage(artworkUrl, null, null);
                hasNoCover = 2;
            } else {
                placeholderImageView.setImageDrawable(null);
                hasNoCover = 1;
            }
            placeholderImageView.invalidate();
        }

        int duration = messageObject.getDuration();
        if (durationTextView != null) {
            durationTextView.setText(duration != 0 ? AndroidUtilities.formatShortDuration(duration) : "-:--");
        }

        if (duration > 60 * 20) {
            playbackSpeedButton.setVisibility(View.VISIBLE);
        } else {
            playbackSpeedButton.setVisibility(View.GONE);
        }
    }
}
 
Example 17
Source File: AudioPlayerAlert.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void updateTitle(boolean shutdown) {
    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null && shutdown || messageObject != null && !messageObject.isMusic()) {
        dismiss();
    } else {
        if (messageObject == null) {
            return;
        }
        if (messageObject.eventId != 0 || messageObject.getId() <= -2000000000) {
            hasOptions = false;
            menuItem.setVisibility(View.INVISIBLE);
            optionsButton.setVisibility(View.INVISIBLE);
        } else {
            hasOptions = true;
            if (!actionBar.isSearchFieldVisible()) {
                menuItem.setVisibility(View.VISIBLE);
            }
            optionsButton.setVisibility(View.VISIBLE);
        }
        checkIfMusicDownloaded(messageObject);
        updateProgress(messageObject);

        if (MediaController.getInstance().isMessagePaused()) {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
            playButton.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
        } else {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_pause, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
            playButton.setContentDescription(LocaleController.getString("AccActionPause", R.string.AccActionPause));
        }
        String title = messageObject.getMusicTitle();
        String author = messageObject.getMusicAuthor();
        titleTextView.setText(title);
        authorTextView.setText(author);
        actionBar.setTitle(title);
        actionBar.setSubtitle(author);

        String loadTitle = author + " " + title;
        AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
        if (audioInfo != null && audioInfo.getCover() != null) {
            hasNoCover = 0;
            placeholderImageView.setImageBitmap(audioInfo.getCover());
        } else {
            String artworkUrl = messageObject.getArtworkUrl(false);
            if (!TextUtils.isEmpty(artworkUrl)) {
                placeholderImageView.setImage(artworkUrl, null, null);
                hasNoCover = 2;
            } else {
                placeholderImageView.setImageDrawable(null);
                hasNoCover = 1;
            }
            placeholderImageView.invalidate();
        }

        int duration = messageObject.getDuration();
        if (durationTextView != null) {
            durationTextView.setText(duration != 0 ? AndroidUtilities.formatShortDuration(duration) : "-:--");
        }

        if (duration > 60 * 20) {
            playbackSpeedButton.setVisibility(View.VISIBLE);
        } else {
            playbackSpeedButton.setVisibility(View.GONE);
        }
    }
}
 
Example 18
Source File: AudioPlayerAlert.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void updateTitle(boolean shutdown) {
    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null && shutdown || messageObject != null && !messageObject.isMusic()) {
        dismiss();
    } else {
        if (messageObject == null) {
            return;
        }
        if (messageObject.eventId != 0 || messageObject.getId() <= -2000000000) {
            hasOptions = false;
            menuItem.setVisibility(View.INVISIBLE);
            optionsButton.setVisibility(View.INVISIBLE);
        } else {
            hasOptions = true;
            if (!actionBar.isSearchFieldVisible()) {
                menuItem.setVisibility(View.VISIBLE);
            }
            optionsButton.setVisibility(View.VISIBLE);
        }
        checkIfMusicDownloaded(messageObject);
        updateProgress(messageObject);

        if (MediaController.getInstance().isMessagePaused()) {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_play, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
        } else {
            playButton.setImageDrawable(Theme.createSimpleSelectorDrawable(playButton.getContext(), R.drawable.pl_pause, Theme.getColor(Theme.key_player_button), Theme.getColor(Theme.key_player_buttonActive)));
        }
        String title = messageObject.getMusicTitle();
        String author = messageObject.getMusicAuthor();
        titleTextView.setText(title);
        authorTextView.setText(author);
        actionBar.setTitle(title);
        actionBar.setSubtitle(author);

        AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
        if (audioInfo != null && audioInfo.getCover() != null) {
            hasNoCover = false;
            placeholderImageView.setImageBitmap(audioInfo.getCover());
        } else {
            hasNoCover = true;
            placeholderImageView.invalidate();
            placeholderImageView.setImageDrawable(null);
        }

        if (durationTextView != null) {
            int duration = messageObject.getDuration();
            durationTextView.setText(duration != 0 ? String.format("%d:%02d", duration / 60, duration % 60) : "-:--");
        }
    }
}
 
Example 19
Source File: StatisticActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.messagesDidLoad) {
        int guid = (Integer) args[10];
        if (guid == classGuid) {
            ArrayList<MessageObject> messArr = (ArrayList<MessageObject>) args[2];
            ArrayList<RecentPostInfo> deletedMessages = new ArrayList<>();
            int n = messArr.size();
            for (int i = 0; i < n; i++) {
                MessageObject messageObjectFormCache = messArr.get(i);
                int index = recentPostIdtoIndexMap.get(messageObjectFormCache.getId(), -1);
                if (index >= 0 && recentPostsAll.get(index).counters.msg_id == messageObjectFormCache.getId()) {
                    if (messageObjectFormCache.deleted) {
                        deletedMessages.add(recentPostsAll.get(index));
                    } else {
                        recentPostsAll.get(index).message = messageObjectFormCache;
                    }
                }
            }

            recentPostsAll.removeAll(deletedMessages);

            recentPostsLoaded.clear();
            n = recentPostsAll.size();
            for (int i = 0; i < n; i++) {
                RecentPostInfo postInfo = recentPostsAll.get(i);
                if (postInfo.message == null) {
                    loadFromId = postInfo.counters.msg_id;
                    break;
                } else {
                    recentPostsLoaded.add(postInfo);
                }
            }

            if (recentPostsLoaded.size() < 20) {
                loadMessages();
            }
            if (adapter != null) {
                diffUtilsCallback.update();
            }
        }
    }
}
 
Example 20
Source File: DialogsSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void searchMessagesInternal(final String query, int searchId) {
    if (needMessagesSearch == 0 || TextUtils.isEmpty(lastMessagesSearchString) && TextUtils.isEmpty(query)) {
        return;
    }
    if (reqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
        reqId = 0;
    }
    if (TextUtils.isEmpty(query)) {
        searchResultMessages.clear();
        lastReqId = 0;
        lastMessagesSearchString = null;
        searchWas = false;
        notifyDataSetChanged();
        if (delegate != null) {
            delegate.searchStateChanged(false);
        }
        return;
    }

    final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
    req.limit = 20;
    req.q = query;
    if (query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) {
        MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1);
        req.offset_id = lastMessage.getId();
        req.offset_rate = nextSearchRate;
        int id;
        if (lastMessage.messageOwner.to_id.channel_id != 0) {
            id = -lastMessage.messageOwner.to_id.channel_id;
        } else if (lastMessage.messageOwner.to_id.chat_id != 0) {
            id = -lastMessage.messageOwner.to_id.chat_id;
        } else {
            id = lastMessage.messageOwner.to_id.user_id;
        }
        req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id);
    } else {
        req.offset_rate = 0;
        req.offset_id = 0;
        req.offset_peer = new TLRPC.TL_inputPeerEmpty();
    }
    lastMessagesSearchString = query;
    final int currentReqId = ++lastReqId;
    /*if (delegate != null) {
        delegate.searchStateChanged(true);
    }*/
    reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (currentReqId == lastReqId && (searchId <= 0 || searchId == lastSearchId)) {
            if (error == null) {
                TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                if (req.offset_id == 0) {
                    searchResultMessages.clear();
                }
                nextSearchRate = res.next_rate;
                for (int a = 0; a < res.messages.size(); a++) {
                    TLRPC.Message message = res.messages.get(a);
                    long did = MessageObject.getDialogId(message);
                    Integer maxId = MessagesController.getInstance(currentAccount).deletedHistory.get(did);
                    if (maxId != null && message.id <= maxId) {
                        continue;
                    }
                    searchResultMessages.add(new MessageObject(currentAccount, message, false));
                    long dialog_id = MessageObject.getDialogId(message);
                    ConcurrentHashMap<Long, Integer> read_max = message.out ? MessagesController.getInstance(currentAccount).dialogs_read_outbox_max : MessagesController.getInstance(currentAccount).dialogs_read_inbox_max;
                    Integer value = read_max.get(dialog_id);
                    if (value == null) {
                        value = MessagesStorage.getInstance(currentAccount).getDialogReadMax(message.out, dialog_id);
                        read_max.put(dialog_id, value);
                    }
                    message.unread = value < message.id;
                }
                searchWas = true;
                messagesSearchEndReached = res.messages.size() != 20;
                if (searchId > 0) {
                    lastMessagesSearchId = searchId;
                    if (lastLocalSearchId != searchId) {
                        searchResult.clear();
                    }
                    if (lastGlobalSearchId != searchId) {
                        searchAdapterHelper.clear();
                    }
                }
                notifyDataSetChanged();
            }
        }
        reqId = 0;
        if (!searchAdapterHelper.isSearchInProgress() && delegate != null) {
            delegate.searchStateChanged(false);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}