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());
}
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);
}
}
}
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());
}
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);
}
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);
}
Aggregations