use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class AlertsCreator method createDeleteMessagesAlert.
public static void createDeleteMessagesAlert(BaseFragment fragment, TLRPC.User user, TLRPC.Chat chat, TLRPC.EncryptedChat encryptedChat, TLRPC.ChatFull chatInfo, long mergeDialogId, MessageObject selectedMessage, SparseArray<MessageObject>[] selectedMessages, MessageObject.GroupedMessages selectedGroup, boolean scheduled, int loadParticipant, Runnable onDelete, Runnable hideDim, Theme.ResourcesProvider resourcesProvider) {
if (fragment == null || user == null && chat == null && encryptedChat == null) {
return;
}
Activity activity = fragment.getParentActivity();
if (activity == null) {
return;
}
int currentAccount = fragment.getCurrentAccount();
AlertDialog.Builder builder = new AlertDialog.Builder(activity, resourcesProvider);
builder.setDimEnabled(hideDim == null);
int count;
if (selectedGroup != null) {
count = selectedGroup.messages.size();
} else if (selectedMessage != null) {
count = 1;
} else {
count = selectedMessages[0].size() + selectedMessages[1].size();
}
long dialogId;
if (encryptedChat != null) {
dialogId = DialogObject.makeEncryptedDialogId(encryptedChat.id);
} else if (user != null) {
dialogId = user.id;
} else {
dialogId = -chat.id;
}
int currentDate = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
boolean hasNonDiceMessages = false;
if (selectedMessage != null) {
hasNonDiceMessages = !selectedMessage.isDice() || Math.abs(currentDate - selectedMessage.messageOwner.date) > 24 * 60 * 60;
} else {
for (int a = 0; a < 2; a++) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (!msg.isDice() || Math.abs(currentDate - msg.messageOwner.date) > 24 * 60 * 60) {
hasNonDiceMessages = true;
break;
}
}
}
}
final boolean[] checks = new boolean[3];
final boolean[] deleteForAll = new boolean[1];
TLRPC.User actionUser = null;
TLRPC.Chat actionChat = null;
boolean canRevokeInbox = user != null && MessagesController.getInstance(currentAccount).canRevokePmInbox;
int revokeTimeLimit;
if (user != null) {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimePmLimit;
} else {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimeLimit;
}
boolean hasDeleteForAllCheck = false;
boolean hasNotOut = false;
int myMessagesCount = 0;
boolean canDeleteInbox = encryptedChat == null && user != null && canRevokeInbox && revokeTimeLimit == 0x7fffffff;
if (chat != null && chat.megagroup && !scheduled) {
boolean canBan = ChatObject.canBlockUsers(chat);
if (selectedMessage != null) {
if (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
if (selectedMessage.messageOwner.from_id.user_id != 0) {
actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id);
} else if (selectedMessage.messageOwner.from_id.channel_id != 0) {
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.channel_id);
} else if (selectedMessage.messageOwner.from_id.chat_id != 0) {
actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.chat_id);
}
}
boolean hasOutgoing = !selectedMessage.isSendError() && selectedMessage.getDialogId() == mergeDialogId && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && selectedMessage.isOut() && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
if (hasOutgoing) {
myMessagesCount++;
}
} else {
long from_id = -1;
for (int a = 1; a >= 0; a--) {
long channelId = 0;
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (from_id == -1) {
from_id = msg.getFromChatId();
}
if (from_id < 0 || from_id != msg.getSenderId()) {
from_id = -2;
break;
}
}
if (from_id == -2) {
break;
}
}
for (int a = 1; a >= 0; a--) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (a == 1) {
if (msg.isOut() && msg.messageOwner.action == null) {
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
myMessagesCount++;
}
}
}
}
}
if (from_id != -1) {
actionUser = MessagesController.getInstance(currentAccount).getUser(from_id);
}
}
if ((actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) || (actionChat != null && !ChatObject.hasAdminRights(actionChat))) {
if (loadParticipant == 1 && !chat.creator && actionUser != null) {
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(activity, 3) };
TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant();
req.channel = MessagesController.getInputChannel(chat);
req.participant = MessagesController.getInputPeer(actionUser);
int requestId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
int loadType = 2;
if (response != null) {
TLRPC.TL_channels_channelParticipant participant = (TLRPC.TL_channels_channelParticipant) response;
if (!(participant.participant instanceof TLRPC.TL_channelParticipantAdmin || participant.participant instanceof TLRPC.TL_channelParticipantCreator)) {
loadType = 0;
}
} else if (error != null && "USER_NOT_PARTICIPANT".equals(error.text)) {
loadType = 0;
}
createDeleteMessagesAlert(fragment, user, chat, encryptedChat, chatInfo, mergeDialogId, selectedMessage, selectedMessages, selectedGroup, scheduled, loadType, onDelete, hideDim, resourcesProvider);
}));
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> ConnectionsManager.getInstance(currentAccount).cancelRequest(requestId, true));
fragment.showDialog(progressDialog[0]);
}, 1000);
return;
}
FrameLayout frameLayout = new FrameLayout(activity);
int num = 0;
String name = actionUser != null ? ContactsController.formatName(actionUser.first_name, actionUser.last_name) : actionChat.title;
for (int a = 0; a < 3; a++) {
if ((loadParticipant == 2 || !canBan) && a == 0) {
continue;
}
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
cell.setTag(a);
if (a == 0) {
cell.setText(LocaleController.getString("DeleteBanUser", R.string.DeleteBanUser), "", false, false);
} else if (a == 1) {
cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false);
} else {
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, name), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 48 * num, 0, 0));
cell.setOnClickListener(v -> {
if (!v.isEnabled()) {
return;
}
CheckBoxCell cell13 = (CheckBoxCell) v;
Integer num1 = (Integer) cell13.getTag();
checks[num1] = !checks[num1];
cell13.setChecked(checks[num1], true);
});
num++;
}
builder.setView(frameLayout);
} else if (!hasNotOut && myMessagesCount > 0 && hasNonDiceMessages) {
hasDeleteForAllCheck = true;
FrameLayout frameLayout = new FrameLayout(activity);
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (chat != null && hasNotOut) {
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
} else {
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell12 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell12.setChecked(deleteForAll[0], true);
});
builder.setView(frameLayout);
builder.setCustomViewOffset(9);
} else {
actionUser = null;
}
} else if (!scheduled && !ChatObject.isChannel(chat) && encryptedChat == null) {
if (user != null && user.id != UserConfig.getInstance(currentAccount).getClientUserId() && (!user.bot || user.support) || chat != null) {
if (selectedMessage != null) {
boolean hasOutgoing = !selectedMessage.isSendError() && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) && (selectedMessage.isOut() || canRevokeInbox || ChatObject.hasAdminRights(chat)) && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit;
if (hasOutgoing) {
myMessagesCount++;
}
hasNotOut = !selectedMessage.isOut();
} else {
for (int a = 1; a >= 0; a--) {
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (!(msg.messageOwner.action == null || msg.messageOwner.action instanceof TLRPC.TL_messageActionEmpty || msg.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall || msg.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage || msg.messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached)) {
continue;
}
if ((msg.isOut() || canRevokeInbox) || chat != null && ChatObject.canBlockUsers(chat)) {
if ((currentDate - msg.messageOwner.date) <= revokeTimeLimit) {
myMessagesCount++;
if (!hasNotOut && !msg.isOut()) {
hasNotOut = true;
}
}
}
}
}
}
}
if (myMessagesCount > 0 && hasNonDiceMessages && (user == null || !UserObject.isDeleted(user))) {
hasDeleteForAllCheck = true;
FrameLayout frameLayout = new FrameLayout(activity);
CheckBoxCell cell = new CheckBoxCell(activity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (canDeleteInbox) {
cell.setText(LocaleController.formatString("DeleteMessagesOptionAlso", R.string.DeleteMessagesOptionAlso, UserObject.getFirstName(user)), "", false, false);
} else if (chat != null && (hasNotOut || myMessagesCount == count)) {
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
} else {
cell.setText(LocaleController.getString("DeleteMessagesOption", R.string.DeleteMessagesOption), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell1.setChecked(deleteForAll[0], true);
});
builder.setView(frameLayout);
builder.setCustomViewOffset(9);
}
}
final TLRPC.User userFinal = actionUser;
final TLRPC.Chat chatFinal = actionChat;
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
ArrayList<Integer> ids = null;
if (selectedMessage != null) {
ids = new ArrayList<>();
ArrayList<Long> random_ids = null;
if (selectedGroup != null) {
for (int a = 0; a < selectedGroup.messages.size(); a++) {
MessageObject messageObject = selectedGroup.messages.get(a);
ids.add(messageObject.getId());
if (encryptedChat != null && messageObject.messageOwner.random_id != 0 && messageObject.type != 10) {
if (random_ids == null) {
random_ids = new ArrayList<>();
}
random_ids.add(messageObject.messageOwner.random_id);
}
}
} else {
ids.add(selectedMessage.getId());
if (encryptedChat != null && selectedMessage.messageOwner.random_id != 0 && selectedMessage.type != 10) {
random_ids = new ArrayList<>();
random_ids.add(selectedMessage.messageOwner.random_id);
}
}
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, deleteForAll[0], scheduled);
} else {
for (int a = 1; a >= 0; a--) {
ids = new ArrayList<>();
for (int b = 0; b < selectedMessages[a].size(); b++) {
ids.add(selectedMessages[a].keyAt(b));
}
ArrayList<Long> random_ids = null;
long channelId = 0;
if (!ids.isEmpty()) {
MessageObject msg = selectedMessages[a].get(ids.get(0));
if (msg.messageOwner.peer_id.channel_id != 0) {
channelId = msg.messageOwner.peer_id.channel_id;
}
}
if (encryptedChat != null) {
random_ids = new ArrayList<>();
for (int b = 0; b < selectedMessages[a].size(); b++) {
MessageObject msg = selectedMessages[a].valueAt(b);
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, encryptedChat, dialogId, deleteForAll[0], scheduled);
selectedMessages[a].clear();
}
}
if (userFinal != null || chatFinal != null) {
if (checks[0]) {
MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatFinal, chatInfo, false, false);
}
if (checks[1]) {
TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam();
req.channel = MessagesController.getInputChannel(chat);
if (userFinal != null) {
req.participant = MessagesController.getInputPeer(userFinal);
} else {
req.participant = MessagesController.getInputPeer(chatFinal);
}
req.id = ids;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
});
}
if (checks[2]) {
MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, chatFinal, 0);
}
}
if (onDelete != null) {
onDelete.run();
}
});
if (count == 1) {
builder.setTitle(LocaleController.getString("DeleteSingleMessagesTitle", R.string.DeleteSingleMessagesTitle));
} else {
builder.setTitle(LocaleController.formatString("DeleteMessagesTitle", R.string.DeleteMessagesTitle, LocaleController.formatPluralString("messages", count)));
}
if (chat != null && hasNotOut) {
if (hasDeleteForAllCheck && myMessagesCount != count) {
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroupPart", R.string.DeleteMessagesTextGroupPart, LocaleController.formatPluralString("messages", myMessagesCount)));
} else if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
}
} else if (hasDeleteForAllCheck && !canDeleteInbox && myMessagesCount != count) {
if (chat != null) {
builder.setMessage(LocaleController.formatString("DeleteMessagesTextGroup", R.string.DeleteMessagesTextGroup, LocaleController.formatPluralString("messages", myMessagesCount)));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("DeleteMessagesText", R.string.DeleteMessagesText, LocaleController.formatPluralString("messages", myMessagesCount), UserObject.getFirstName(user))));
}
} else {
if (chat != null && chat.megagroup && !scheduled) {
if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessageMega", R.string.AreYouSureDeleteSingleMessageMega));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessagesMega", R.string.AreYouSureDeleteFewMessagesMega));
}
} else {
if (count == 1) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteSingleMessage", R.string.AreYouSureDeleteSingleMessage));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteFewMessages", R.string.AreYouSureDeleteFewMessages));
}
}
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setOnPreDismissListener(di -> {
if (hideDim != null) {
hideDim.run();
}
});
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class AudioPlayerAlert method didReceivedNotification.
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset) {
updateTitle(id == NotificationCenter.messagePlayingDidReset && (Boolean) args[1]);
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingPlayStateChanged) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof AudioPlayerCell) {
AudioPlayerCell cell = (AudioPlayerCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && (messageObject.isVoice() || messageObject.isMusic())) {
cell.updateButtonState(false, true);
}
}
}
if (id == NotificationCenter.messagePlayingPlayStateChanged) {
if (MediaController.getInstance().getPlayingMessageObject() != null) {
if (MediaController.getInstance().isMessagePaused()) {
startForwardRewindingSeek();
} else if (rewindingState == 1 && rewindingProgress != -1f) {
AndroidUtilities.cancelRunOnUIThread(forwardSeek);
lastUpdateRewindingPlayerTime = 0;
forwardSeek.run();
rewindingProgress = -1f;
}
}
}
} else {
MessageObject messageObject = (MessageObject) args[0];
if (messageObject.eventId != 0) {
return;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof AudioPlayerCell) {
AudioPlayerCell cell = (AudioPlayerCell) view;
MessageObject messageObject1 = cell.getMessageObject();
if (messageObject1 != null && (messageObject1.isVoice() || messageObject1.isMusic())) {
cell.updateButtonState(false, true);
}
}
}
}
} else if (id == NotificationCenter.messagePlayingProgressDidChanged) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isMusic()) {
updateProgress(messageObject);
}
} else if (id == NotificationCenter.musicDidLoad) {
playlist = MediaController.getInstance().getPlaylist();
listAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.moreMusicDidLoad) {
playlist = MediaController.getInstance().getPlaylist();
listAdapter.notifyDataSetChanged();
if (SharedConfig.playOrderReversed) {
listView.stopScroll();
int addedCount = (Integer) args[0];
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int position = layoutManager.findLastVisibleItemPosition();
if (position != RecyclerView.NO_POSITION) {
View firstVisView = layoutManager.findViewByPosition(position);
int offset = firstVisView == null ? 0 : firstVisView.getTop();
layoutManager.scrollToPositionWithOffset(position + addedCount, offset);
}
}
} else if (id == NotificationCenter.fileLoaded) {
String name = (String) args[0];
if (name.equals(currentFile)) {
updateTitle(false);
currentAudioFinishedLoading = true;
}
} else if (id == NotificationCenter.fileLoadProgressChanged) {
String name = (String) args[0];
if (name.equals(currentFile)) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null) {
return;
}
Long loadedSize = (Long) args[1];
Long totalSize = (Long) args[2];
float bufferedProgress;
if (currentAudioFinishedLoading) {
bufferedProgress = 1.0f;
} else {
long newTime = SystemClock.elapsedRealtime();
if (Math.abs(newTime - lastBufferedPositionCheck) >= 500) {
bufferedProgress = MediaController.getInstance().isStreamingCurrentAudio() ? FileLoader.getInstance(currentAccount).getBufferedProgressFromPosition(messageObject.audioProgress, currentFile) : 1.0f;
lastBufferedPositionCheck = newTime;
} else {
bufferedProgress = -1;
}
}
if (bufferedProgress != -1) {
seekBarView.setBufferedProgress(bufferedProgress);
}
}
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivityEnterView method setEditingMessageObject.
public void setEditingMessageObject(MessageObject messageObject, boolean caption) {
if (audioToSend != null || videoToSendMessageObject != null || editingMessageObject == messageObject) {
return;
}
boolean hadEditingMessage = editingMessageObject != null;
editingMessageObject = messageObject;
editingCaption = caption;
CharSequence textToSetWithKeyboard;
if (editingMessageObject != null) {
if (doneButtonAnimation != null) {
doneButtonAnimation.cancel();
doneButtonAnimation = null;
}
doneButtonContainer.setVisibility(View.VISIBLE);
doneButtonImage.setScaleX(0.1f);
doneButtonImage.setScaleY(0.1f);
doneButtonImage.setAlpha(0.0f);
doneButtonImage.animate().alpha(1f).scaleX(1).scaleY(1).setDuration(150).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
CharSequence editingText;
if (caption) {
currentLimit = accountInstance.getMessagesController().maxCaptionLength;
editingText = editingMessageObject.caption;
} else {
currentLimit = accountInstance.getMessagesController().maxMessageLength;
editingText = editingMessageObject.messageText;
}
if (editingText != null) {
ArrayList<TLRPC.MessageEntity> entities = editingMessageObject.messageOwner.entities;
MediaDataController.sortEntities(entities);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(editingText);
Object[] spansToRemove = stringBuilder.getSpans(0, stringBuilder.length(), Object.class);
if (spansToRemove != null && spansToRemove.length > 0) {
for (int a = 0; a < spansToRemove.length; a++) {
stringBuilder.removeSpan(spansToRemove[a]);
}
}
if (entities != null) {
try {
for (int a = 0; a < entities.size(); a++) {
TLRPC.MessageEntity entity = entities.get(a);
if (entity.offset + entity.length > stringBuilder.length()) {
continue;
}
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
if (entity.offset + entity.length < stringBuilder.length() && stringBuilder.charAt(entity.offset + entity.length) == ' ') {
entity.length++;
}
stringBuilder.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id, 3), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityMentionName) {
if (entity.offset + entity.length < stringBuilder.length() && stringBuilder.charAt(entity.offset + entity.length) == ' ') {
entity.length++;
}
stringBuilder.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) entity).user_id, 3), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_MONO;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
} else if (entity instanceof TLRPC.TL_messageEntityBold) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_BOLD;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
} else if (entity instanceof TLRPC.TL_messageEntityItalic) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_ITALIC;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
} else if (entity instanceof TLRPC.TL_messageEntityStrike) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_STRIKE;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
} else if (entity instanceof TLRPC.TL_messageEntityUnderline) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_UNDERLINE;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
} else if (entity instanceof TLRPC.TL_messageEntityTextUrl) {
stringBuilder.setSpan(new URLSpanReplacement(entity.url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntitySpoiler) {
TextStyleSpan.TextStyleRun run = new TextStyleSpan.TextStyleRun();
run.flags |= TextStyleSpan.FLAG_STYLE_SPOILER;
MediaDataController.addStyleToText(new TextStyleSpan(run), entity.offset, entity.offset + entity.length, stringBuilder, true);
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
textToSetWithKeyboard = Emoji.replaceEmoji(new SpannableStringBuilder(stringBuilder), messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
} else {
textToSetWithKeyboard = "";
}
if (draftMessage == null && !hadEditingMessage) {
draftMessage = messageEditText.length() > 0 ? messageEditText.getText() : null;
draftSearchWebpage = messageWebPageSearch;
}
messageWebPageSearch = editingMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage;
if (!keyboardVisible) {
AndroidUtilities.runOnUIThread(setTextFieldRunnable = () -> {
setFieldText(textToSetWithKeyboard);
setTextFieldRunnable = null;
}, 200);
} else {
if (setTextFieldRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(setTextFieldRunnable);
setTextFieldRunnable = null;
}
setFieldText(textToSetWithKeyboard);
}
messageEditText.requestFocus();
openKeyboard();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(4);
messageEditText.setLayoutParams(layoutParams);
sendButton.setVisibility(GONE);
setSlowModeButtonVisible(false);
cancelBotButton.setVisibility(GONE);
audioVideoButtonContainer.setVisibility(GONE);
attachLayout.setVisibility(GONE);
sendButtonContainer.setVisibility(GONE);
if (scheduledButton != null) {
scheduledButton.setVisibility(GONE);
}
} else {
if (setTextFieldRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(setTextFieldRunnable);
setTextFieldRunnable = null;
}
doneButtonContainer.setVisibility(View.GONE);
currentLimit = -1;
delegate.onMessageEditEnd(false);
sendButtonContainer.setVisibility(VISIBLE);
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
cancelBotButton.setVisibility(GONE);
if (slowModeTimer > 0 && !isInScheduleMode()) {
if (slowModeTimer == Integer.MAX_VALUE) {
sendButton.setScaleX(1.0f);
sendButton.setScaleY(1.0f);
sendButton.setAlpha(1.0f);
sendButton.setVisibility(VISIBLE);
slowModeButton.setScaleX(0.1f);
slowModeButton.setScaleY(0.1f);
slowModeButton.setAlpha(0.0f);
setSlowModeButtonVisible(false);
} else {
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
sendButton.setVisibility(GONE);
slowModeButton.setScaleX(1.0f);
slowModeButton.setScaleY(1.0f);
slowModeButton.setAlpha(1.0f);
setSlowModeButtonVisible(true);
}
attachLayout.setScaleX(0.01f);
attachLayout.setAlpha(0.0f);
attachLayout.setVisibility(GONE);
audioVideoButtonContainer.setScaleX(0.1f);
audioVideoButtonContainer.setScaleY(0.1f);
audioVideoButtonContainer.setAlpha(0.0f);
audioVideoButtonContainer.setVisibility(GONE);
} else {
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
sendButton.setVisibility(GONE);
slowModeButton.setScaleX(0.1f);
slowModeButton.setScaleY(0.1f);
slowModeButton.setAlpha(0.0f);
setSlowModeButtonVisible(false);
attachLayout.setScaleX(1.0f);
attachLayout.setAlpha(1.0f);
attachLayout.setVisibility(VISIBLE);
audioVideoButtonContainer.setScaleX(1.0f);
audioVideoButtonContainer.setScaleY(1.0f);
audioVideoButtonContainer.setAlpha(1.0f);
audioVideoButtonContainer.setVisibility(VISIBLE);
}
if (scheduledButton.getTag() != null) {
scheduledButton.setScaleX(1.0f);
scheduledButton.setScaleY(1.0f);
scheduledButton.setAlpha(1.0f);
scheduledButton.setVisibility(VISIBLE);
}
messageEditText.setText(draftMessage);
messageWebPageSearch = draftSearchWebpage;
messageEditText.setSelection(messageEditText.length());
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
updateFieldRight(1);
}
updateFieldHint(false);
updateSendAsButton();
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertAudioLayout method didReceivedNotification.
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged) {
if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingPlayStateChanged) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject = cell.getMessage();
if (messageObject != null) {
cell.updateButtonState(false, true);
}
}
}
} else if (id == NotificationCenter.messagePlayingDidStart) {
MessageObject messageObject = (MessageObject) args[0];
if (messageObject.eventId != 0) {
return;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
if (view instanceof SharedAudioCell) {
SharedAudioCell cell = (SharedAudioCell) view;
MessageObject messageObject1 = cell.getMessage();
if (messageObject1 != null) {
cell.updateButtonState(false, true);
}
}
}
}
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelAdminLogActivity method showInviteLinkBottomSheet.
private void showInviteLinkBottomSheet(TLRPC.TL_messages_exportedChatInvite invite, HashMap<Long, TLRPC.User> usersMap) {
TLRPC.ChatFull chatInfo = getMessagesController().getChatFull(currentChat.id);
InviteLinkBottomSheet inviteLinkBottomSheet = new InviteLinkBottomSheet(contentView.getContext(), (TLRPC.TL_chatInviteExported) invite.invite, chatInfo, usersMap, ChannelAdminLogActivity.this, chatInfo.id, false, ChatObject.isChannel(currentChat));
inviteLinkBottomSheet.setInviteDelegate(new InviteLinkBottomSheet.InviteDelegate() {
@Override
public void permanentLinkReplaced(TLRPC.TL_chatInviteExported oldLink, TLRPC.TL_chatInviteExported newLink) {
}
@Override
public void linkRevoked(TLRPC.TL_chatInviteExported invite) {
TLRPC.TL_channelAdminLogEvent event = new TLRPC.TL_channelAdminLogEvent();
int size = messages.size();
invite.revoked = true;
TLRPC.TL_channelAdminLogEventActionExportedInviteRevoke revokeAction = new TLRPC.TL_channelAdminLogEventActionExportedInviteRevoke();
revokeAction.invite = invite;
event.action = revokeAction;
event.date = (int) (System.currentTimeMillis() / 1000L);
event.user_id = getAccountInstance().getUserConfig().clientUserId;
MessageObject messageObject = new MessageObject(currentAccount, event, messages, messagesByDays, currentChat, mid, true);
if (messageObject.contentType < 0) {
return;
}
int addCount = messages.size() - size;
if (addCount > 0) {
chatListItemAnimator.setShouldAnimateEnterFromBottom(true);
chatAdapter.notifyItemRangeInserted(chatAdapter.messagesEndRow, addCount);
moveScrollToLastMessage();
}
invitesCache.remove(invite.link);
}
@Override
public void onLinkDeleted(TLRPC.TL_chatInviteExported invite) {
int size = messages.size();
int messagesEndRow = chatAdapter.messagesEndRow;
TLRPC.TL_channelAdminLogEvent event = new TLRPC.TL_channelAdminLogEvent();
TLRPC.TL_channelAdminLogEventActionExportedInviteDelete deleteAction = new TLRPC.TL_channelAdminLogEventActionExportedInviteDelete();
deleteAction.invite = invite;
event.action = deleteAction;
event.date = (int) (System.currentTimeMillis() / 1000L);
event.user_id = getAccountInstance().getUserConfig().clientUserId;
MessageObject messageObject = new MessageObject(currentAccount, event, messages, messagesByDays, currentChat, mid, true);
if (messageObject.contentType < 0) {
return;
}
int addCount = messages.size() - size;
if (addCount > 0) {
chatListItemAnimator.setShouldAnimateEnterFromBottom(true);
chatAdapter.notifyItemRangeInserted(chatAdapter.messagesEndRow, addCount);
moveScrollToLastMessage();
}
invitesCache.remove(invite.link);
}
@Override
public void onLinkEdited(TLRPC.TL_chatInviteExported invite) {
TLRPC.TL_channelAdminLogEvent event = new TLRPC.TL_channelAdminLogEvent();
TLRPC.TL_channelAdminLogEventActionExportedInviteEdit editAction = new TLRPC.TL_channelAdminLogEventActionExportedInviteEdit();
editAction.new_invite = invite;
editAction.prev_invite = invite;
event.action = editAction;
event.date = (int) (System.currentTimeMillis() / 1000L);
event.user_id = getAccountInstance().getUserConfig().clientUserId;
MessageObject messageObject = new MessageObject(currentAccount, event, messages, messagesByDays, currentChat, mid, true);
if (messageObject.contentType < 0) {
return;
}
chatAdapter.notifyDataSetChanged();
moveScrollToLastMessage();
}
});
inviteLinkBottomSheet.show();
}
Aggregations