Search in sources :

Example 6 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChannelAdminLogActivity method createMenu.

private void createMenu(View v) {
    MessageObject message = null;
    if (v instanceof ChatMessageCell) {
        message = ((ChatMessageCell) v).getMessageObject();
    } else if (v instanceof ChatActionCell) {
        message = ((ChatActionCell) v).getMessageObject();
    }
    if (message == null) {
        return;
    }
    final int type = getMessageType(message);
    selectedObject = message;
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    ArrayList<CharSequence> items = new ArrayList<>();
    final ArrayList<Integer> options = new ArrayList<>();
    if (selectedObject.type == 0 || selectedObject.caption != null) {
        items.add(LocaleController.getString("Copy", R.string.Copy));
        options.add(3);
    }
    if (type == 1) {
        if (selectedObject.currentEvent != null && selectedObject.currentEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeStickerSet) {
            TLRPC.TL_channelAdminLogEventActionChangeStickerSet action = (TLRPC.TL_channelAdminLogEventActionChangeStickerSet) selectedObject.currentEvent.action;
            TLRPC.InputStickerSet stickerSet = action.new_stickerset;
            if (stickerSet == null || stickerSet instanceof TLRPC.TL_inputStickerSetEmpty) {
                stickerSet = action.prev_stickerset;
            }
            if (stickerSet != null) {
                showDialog(new StickersAlert(getParentActivity(), ChannelAdminLogActivity.this, stickerSet, null, null));
                return;
            }
        } else if (selectedObject.currentEvent != null && selectedObject.currentEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeHistoryTTL) {
            if (ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_DELETE_MESSAGES)) {
                ClearHistoryAlert alert = new ClearHistoryAlert(getParentActivity(), null, currentChat, false, null);
                alert.setDelegate(new ClearHistoryAlert.ClearHistoryAlertDelegate() {

                    @Override
                    public void onAutoDeleteHistory(int ttl, int action) {
                        getMessagesController().setDialogHistoryTTL(-currentChat.id, ttl);
                        TLRPC.ChatFull chatInfo = getMessagesController().getChatFull(currentChat.id);
                        if (chatInfo != null) {
                            undoView.showWithAction(-currentChat.id, action, null, chatInfo.ttl_period, null, null);
                        }
                    }
                });
                showDialog(alert);
            }
        }
    } else if (type == 3) {
        if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && MessageObject.isNewGifDocument(selectedObject.messageOwner.media.webpage.document)) {
            items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
            options.add(11);
        }
    } else if (type == 4) {
        if (selectedObject.isVideo()) {
            items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
            options.add(4);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else if (selectedObject.isMusic()) {
            items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
            options.add(10);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else if (selectedObject.getDocument() != null) {
            if (MessageObject.isNewGifDocument(selectedObject.getDocument())) {
                items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
                options.add(11);
            }
            items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
            options.add(10);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else {
            items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
            options.add(4);
        }
    } else if (type == 5) {
        items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
        options.add(5);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 10) {
        items.add(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
        options.add(5);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 6) {
        items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
        options.add(7);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 7) {
        if (selectedObject.isMask()) {
            items.add(LocaleController.getString("AddToMasks", R.string.AddToMasks));
        } else {
            items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
        }
        options.add(9);
    } else if (type == 8) {
        long uid = selectedObject.messageOwner.media.user_id;
        TLRPC.User user = null;
        if (uid != 0) {
            user = MessagesController.getInstance(currentAccount).getUser(uid);
        }
        if (user != null && user.id != UserConfig.getInstance(currentAccount).getClientUserId() && ContactsController.getInstance(currentAccount).contactsDict.get(user.id) == null) {
            items.add(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
            options.add(15);
        }
        if (!TextUtils.isEmpty(selectedObject.messageOwner.media.phone_number)) {
            items.add(LocaleController.getString("Copy", R.string.Copy));
            options.add(16);
            items.add(LocaleController.getString("Call", R.string.Call));
            options.add(17);
        }
    }
    if (options.isEmpty()) {
        return;
    }
    final CharSequence[] finalItems = items.toArray(new CharSequence[0]);
    builder.setItems(finalItems, (dialogInterface, i) -> {
        if (selectedObject == null || i < 0 || i >= options.size()) {
            return;
        }
        processSelectedOption(options.get(i));
    });
    builder.setTitle(LocaleController.getString("Message", R.string.Message));
    showDialog(builder.create());
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) ClearHistoryAlert(org.telegram.ui.Components.ClearHistoryAlert) Paint(android.graphics.Paint) StickersAlert(org.telegram.ui.Components.StickersAlert) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) MessageObject(org.telegram.messenger.MessageObject)

Example 7 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChannelAdminLogActivity method updateTextureViewPosition.

private void updateTextureViewPosition() {
    boolean foundTextureViewMessage = false;
    int count = chatListView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            ChatMessageCell messageCell = (ChatMessageCell) view;
            MessageObject messageObject = messageCell.getMessageObject();
            if (roundVideoContainer != null && messageObject.isRoundVideo() && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                roundVideoContainer.setTranslationX(imageReceiver.getImageX());
                roundVideoContainer.setTranslationY(fragmentView.getPaddingTop() + messageCell.getTop() + imageReceiver.getImageY());
                fragmentView.invalidate();
                roundVideoContainer.invalidate();
                foundTextureViewMessage = true;
                break;
            }
        }
    }
    if (roundVideoContainer != null) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (!foundTextureViewMessage) {
            roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
            fragmentView.invalidate();
            if (messageObject != null && messageObject.isRoundVideo()) {
                if (checkTextureViewPosition || PipRoundVideoView.getInstance() != null) {
                    MediaController.getInstance().setCurrentVideoVisible(false);
                }
            }
        } else {
            MediaController.getInstance().setCurrentVideoVisible(true);
        }
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) UndoView(org.telegram.ui.Components.UndoView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint)

Example 8 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ForwardingPreviewView method updateMessages.

private void updateMessages() {
    if (itemAnimator.isRunning()) {
        updateAfterAnimations = true;
        return;
    }
    for (int i = 0; i < forwardingMessagesParams.previewMessages.size(); i++) {
        MessageObject messageObject = forwardingMessagesParams.previewMessages.get(i);
        messageObject.forceUpdate = true;
        if (!forwardingMessagesParams.hideForwardSendersName) {
            messageObject.messageOwner.flags |= TLRPC.MESSAGE_FLAG_FWD;
        } else {
            messageObject.messageOwner.flags &= ~TLRPC.MESSAGE_FLAG_FWD;
        }
        if (forwardingMessagesParams.hideCaption) {
            messageObject.caption = null;
        } else {
            messageObject.generateCaption();
        }
        if (messageObject.isPoll()) {
            ForwardingMessagesParams.PreviewMediaPoll mediaPoll = (ForwardingMessagesParams.PreviewMediaPoll) messageObject.messageOwner.media;
            mediaPoll.results.total_voters = forwardingMessagesParams.hideCaption ? 0 : mediaPoll.totalVotersCached;
        }
    }
    for (int i = 0; i < forwardingMessagesParams.pollChoosenAnswers.size(); i++) {
        forwardingMessagesParams.pollChoosenAnswers.get(i).chosen = !forwardingMessagesParams.hideForwardSendersName;
    }
    for (int i = 0; i < forwardingMessagesParams.groupedMessagesMap.size(); i++) {
        itemAnimator.groupWillChanged(forwardingMessagesParams.groupedMessagesMap.valueAt(i));
    }
    adapter.notifyItemRangeChanged(0, forwardingMessagesParams.previewMessages.size());
}
Also used : ForwardingMessagesParams(org.telegram.messenger.ForwardingMessagesParams) MessageObject(org.telegram.messenger.MessageObject) SuppressLint(android.annotation.SuppressLint)

Example 9 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method checkVisibility.

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().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING) {
            show = true;
        } else if (fragment instanceof ChatActivity && fragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) fragment).getDialogId()) != null && !isPlayingVoice()) {
            show = true;
        } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && ((ChatActivity) fragment).getGroupCall().shouldShowPanel() && !GroupCallPip.isShowing() && !isPlayingVoice()) {
            show = true;
        } else {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.getId() != 0) {
                show = true;
            }
        }
    }
    setVisibility(show ? VISIBLE : GONE);
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) DialogsActivity(org.telegram.ui.DialogsActivity) MessageObject(org.telegram.messenger.MessageObject)

Example 10 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsSearchAdapter method searchMessagesInternal.

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();
        return;
    }
    final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
    req.limit = 20;
    req.q = query;
    req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
    req.flags |= 1;
    req.folder_id = folderId;
    if (query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) {
        MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1);
        req.offset_id = lastMessage.getId();
        req.offset_rate = nextSearchRate;
        long id = MessageObject.getPeerId(lastMessage.messageOwner.peer_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;
    reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        final ArrayList<MessageObject> messageObjects = new ArrayList<>();
        if (error == null) {
            TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
            LongSparseArray<TLRPC.Chat> chatsMap = new LongSparseArray<>();
            LongSparseArray<TLRPC.User> usersMap = new LongSparseArray<>();
            for (int a = 0; a < res.chats.size(); a++) {
                TLRPC.Chat chat = res.chats.get(a);
                chatsMap.put(chat.id, chat);
            }
            for (int a = 0; a < res.users.size(); a++) {
                TLRPC.User user = res.users.get(a);
                usersMap.put(user.id, user);
            }
            for (int a = 0; a < res.messages.size(); a++) {
                TLRPC.Message message = res.messages.get(a);
                MessageObject messageObject = new MessageObject(currentAccount, message, usersMap, chatsMap, false, true);
                messageObjects.add(messageObject);
                messageObject.setQuery(query);
            }
        }
        AndroidUtilities.runOnUIThread(() -> {
            if (currentReqId == lastReqId && (searchId <= 0 || searchId == lastSearchId)) {
                waitingResponseCount--;
                if (error == null) {
                    currentMessagesQuery = query;
                    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);
                        int maxId = MessagesController.getInstance(currentAccount).deletedHistory.get(did);
                        if (maxId != 0 && message.id <= maxId) {
                            continue;
                        }
                        searchResultMessages.add(messageObjects.get(a));
                        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();
                        }
                    }
                    if (delegate != null) {
                        delegate.searchStateChanged(waitingResponseCount > 0, true);
                        delegate.runResultsEnterAnimation();
                    }
                    globalSearchCollapsed = true;
                    phoneCollapsed = true;
                    notifyDataSetChanged();
                }
            }
            reqId = 0;
        });
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
Also used : Context(android.content.Context) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) Spanned(android.text.Spanned) Theme(org.telegram.ui.ActionBar.Theme) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TextCell(org.telegram.ui.Cells.TextCell) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) TLObject(org.telegram.tgnet.TLObject) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) View(android.view.View) MessageObject(org.telegram.messenger.MessageObject) MediaDataController(org.telegram.messenger.MediaDataController) RecyclerView(androidx.recyclerview.widget.RecyclerView) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) Utilities(org.telegram.messenger.Utilities) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) FilteredSearchView(org.telegram.ui.FilteredSearchView) R(org.telegram.messenger.R) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) FileLog(org.telegram.messenger.FileLog) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) UserConfig(org.telegram.messenger.UserConfig) UserObject(org.telegram.messenger.UserObject) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) ChatObject(org.telegram.messenger.ChatObject) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LongSparseArray(androidx.collection.LongSparseArray) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

MessageObject (org.telegram.messenger.MessageObject)156 Paint (android.graphics.Paint)107 TLRPC (org.telegram.tgnet.TLRPC)88 SuppressLint (android.annotation.SuppressLint)87 TextPaint (android.text.TextPaint)80 View (android.view.View)59 ArrayList (java.util.ArrayList)59 TextView (android.widget.TextView)53 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)52 RecyclerView (androidx.recyclerview.widget.RecyclerView)50 ImageView (android.widget.ImageView)48 RecyclerListView (org.telegram.ui.Components.RecyclerListView)46 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)39 UndoView (org.telegram.ui.Components.UndoView)36 TextureView (android.view.TextureView)34 File (java.io.File)33 ChatObject (org.telegram.messenger.ChatObject)32 DialogObject (org.telegram.messenger.DialogObject)30 MediaController (org.telegram.messenger.MediaController)30 TLObject (org.telegram.tgnet.TLObject)30