Make option to delete messages work.

This commit is contained in:
B. Petersen
2016-10-27 19:05:56 +02:00
parent 1583bfb733
commit 1781de6ea0
7 changed files with 83 additions and 215 deletions
+6
View File
@@ -203,6 +203,12 @@ JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrMailboxGetMsgById(JNIEnv
}
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrMailboxDeleteMsgById(JNIEnv *env, jclass c, jlong hMailbox, jint id)
{
mrmailbox_delete_msg_by_id((mrmailbox_t*)hMailbox, id);
}
/* MrMailbox - handle config */
JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrMailboxSetConfig(JNIEnv *env, jclass c, jlong hMailbox, jstring key, jstring value)
@@ -598,6 +598,7 @@ public class FileLoader {
public static File getPathToAttach(TLObject attach, String ext, boolean forceCache) {
File dir = null;
String mr_path = null;
if (forceCache) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
@@ -616,7 +617,10 @@ public class FileLoader {
}
} else if (attach instanceof TLRPC.PhotoSize) {
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) attach;
if (photoSize.location == null || photoSize.location.key != null || photoSize.location.volume_id == Integer.MIN_VALUE && photoSize.location.local_id < 0 || photoSize.size < 0) {
if( photoSize.location != null && photoSize.location.mr_path != null ) {
mr_path = photoSize.location.mr_path;
}
else if (photoSize.location == null || photoSize.location.key != null || photoSize.location.volume_id == Integer.MIN_VALUE && photoSize.location.local_id < 0 || photoSize.size < 0) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_IMAGE);
@@ -630,10 +634,24 @@ public class FileLoader {
}
}
}
if (dir == null) {
return new File("");
File f = null;
if( mr_path!=null ) {
try {
f = new File(mr_path);
}
catch (Exception e) {
}
}
return new File(dir, getAttachFileName(attach, ext));
else if (dir == null) {
f = new File("");
}
else {
f = new File(dir, getAttachFileName(attach, ext));
}
return f;
}
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int side) {
@@ -1648,7 +1648,10 @@ public class MessageObject {
if (type == 1) {
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
if (currentPhotoObject != null) {
mediaExists = FileLoader.getPathToMessage(messageOwner).exists();
File f = FileLoader.getPathToMessage(messageOwner);
if( f != null ) {
mediaExists = f.exists();
}
}
} else if (type == 8 || type == 3 || type == 9 || type == 2 || type == 14) {
if (messageOwner.attachPath != null && messageOwner.attachPath.length() > 0) {
@@ -1672,5 +1675,10 @@ public class MessageObject {
}
}
}
if( mediaExists && !attachPathExists && messageOwner.created_by_mr ) {
attachPathExists = true; // EDIT BY MR: we use the attachPath for the normal images
mediaExists = false;
}
}
}
@@ -84,40 +84,49 @@ public class MrMailbox {
ret.flags = 0; // posible flags: MESSAGE_FLAG_HAS_FROM_ID, however, this seems to be read only
ret.post = false; // ? true=avatar wird in gruppen nicht angezeigt
ret.out = ret.from_id==1; // true=outgoing message, read eg. in MessageObject.isOutOwner()
ret. created_by_mr= true;
if( type == MrMailbox.MR_MSG_TEXT ) {
ret.message = MrMailbox.MrMsgGetText(hMsg);
}
else if( type == MrMailbox.MR_MSG_IMAGE ) {
String path = MrMailbox.MrMsgGetParam(hMsg, 'f', "");
TLRPC.TL_photo photo = null;
if( !path.isEmpty() ) {
try {
//TLRPC.TL_photo photo;
// TODO: It is very inefficient to load all photos on dialog loading! FIX ME!
//photo = SendMessagesHelper.getInstance().generatePhotoSizes(path, null); // TODO: does this degrade image quality?
//ret.message = "-1";
//ret.attachPath = new TLRPC.TL_messageMediaPhoto();
//ret.media.photo = photo;// search for TL_messageMediaPhoto
/*
photo = new TLRPC.TL_photo();
TLRPC.TL_photoSize photoSize = new TLRPC.TL_photoSize();
photoSize.w = MrMailbox.MrMsgGetParamInt(hMsg, 'w', 800);
photoSize.h = MrMailbox.MrMsgGetParamInt(hMsg, 'w', 800);
photoSize.h = MrMailbox.MrMsgGetParamInt(hMsg, 'h', 800);
photoSize.size = 0;
photoSize.location = new TLRPC.TL_fileLocation();
photoSize.location.mr_path = path;
photoSize.location.local_id = -ret.id;
photoSize.type = "x";
photo = new TLRPC.TL_photo();
photo.sizes.add(photoSize);
*/
} catch (Exception e) {
// the most common reason is a simple "file not found error"
}
}
if(photo!=null) {
ret.message = "-1";
ret.media = new TLRPC.TL_messageMediaPhoto();
ret.media.photo = photo;
ret.attachPath = path;
}
else {
ret.message = "<cannot load file>";
}
}
else {
ret.message = "Messages of this type are not yet supported.";
ret.message = "<unsupported message type.>";
}
// ret.attachPath
// +obj.attachPathExists
@@ -151,7 +160,7 @@ public class MrMailbox {
@Override
public void run() {
reloadMainChatlist();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
});
return 0;
@@ -180,7 +189,7 @@ public class MrMailbox {
public native static int MrMailboxCreateChatByContactId(long hMailbox, int contact_id); // returns chat_id
public native static long MrMailboxGetMsgById (long hMailbox, int id); // return hMsg which must be unref'd after usage
public native static void MrMailboxDeleteMsgById (long hMailbox, int id);
public native static int MrMailboxSetConfig (long hMailbox, String key, String value); // value may be NULL
public native static String MrMailboxGetConfig (long hMailbox, String key, String def); // def may be NULL, returns empty string as NULL
public native static int MrMailboxGetConfigInt (long hMailbox, String key, int def); // def may be NULL, returns empty string as NULL
@@ -4805,7 +4805,7 @@ public class TLRPC {
public int dc_id;
public long volume_id;
public int local_id;
public long secret;
public String mr_path; // if set, this superseeds the calculation of the path from dc_id/volume_id/local_id
public byte[] key;
public byte[] iv;
@@ -6858,10 +6858,10 @@ public class TLRPC {
//public int seq_in; //custom
//public int seq_out; //custom
public TLRPC.Message replyMessage; //custom
public boolean created_by_mr;
public static Message TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
Message result = null;
return result;
return null;
}
}
@@ -4325,17 +4325,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
Theme.clockMediaDrawable.draw(canvas);
}
}
/*if (isBroadcast) {
if (drawCheck1 || drawCheck2) {
if (!mediaBackground) {
setDrawableBounds(Theme.broadcastDrawable, layoutWidth - dp(20.5f) - Theme.broadcastDrawable.getIntrinsicWidth(), layoutHeight - dp(8.0f) - Theme.broadcastDrawable.getIntrinsicHeight());
Theme.broadcastDrawable.draw(canvas);
} else {
setDrawableBounds(Theme.broadcastMediaDrawable, layoutWidth - dp(24.0f) - Theme.broadcastMediaDrawable.getIntrinsicWidth(), layoutHeight - dp(13.0f) - Theme.broadcastMediaDrawable.getIntrinsicHeight());
Theme.broadcastMediaDrawable.draw(canvas);
}
}
} else */
{
if (drawCheck2) {
if (!mediaBackground) {
@@ -4787,8 +4787,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
int mrCount = MrMailbox.MrMsglistGetCnt(hMsglist);
for (int a = 0; a < mrCount; a++ ) {
long hMsg = MrMailbox.MrMsglistGetMsgByIndex(hMsglist, a);
MessageObject mo = new MessageObject(MrMailbox.hMsg2Message(hMsg), null, true);
messages.add(0, mo);
TLRPC.Message msg = MrMailbox.hMsg2Message(hMsg);
MessageObject msgDrawObj = new MessageObject(msg, null, true);
//msgDrawObj.attachPathExists = true;
messages.add(0, msgDrawObj);
MrMailbox.MrMsgUnref(hMsg);
}
@@ -6385,81 +6388,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
checkRaiseSensors();
}
public void showAlert(TLRPC.User user, String message) {
if (alertView == null || user == null || message == null) {
return;
}
if (alertView.getTag() != null) {
alertView.setTag(null);
if (alertViewAnimator != null) {
alertViewAnimator.cancel();
alertViewAnimator = null;
}
alertView.setVisibility(View.VISIBLE);
alertViewAnimator = new AnimatorSet();
alertViewAnimator.playTogether(ObjectAnimator.ofFloat(alertView, "translationY", 0));
alertViewAnimator.setDuration(200);
alertViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
}
}
});
alertViewAnimator.start();
}
alertNameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
alertTextView.setText(Emoji.replaceEmoji(message.replace('\n', ' '), alertTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
if (hideAlertViewRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(hideAlertViewRunnable);
}
AndroidUtilities.runOnUIThread(hideAlertViewRunnable = new Runnable() {
@Override
public void run() {
if (hideAlertViewRunnable != this) {
return;
}
if (alertView.getTag() == null) {
alertView.setTag(1);
if (alertViewAnimator != null) {
alertViewAnimator.cancel();
alertViewAnimator = null;
}
alertViewAnimator = new AnimatorSet();
alertViewAnimator.playTogether(ObjectAnimator.ofFloat(alertView, "translationY", -AndroidUtilities.dp(50)));
alertViewAnimator.setDuration(200);
alertViewAnimator.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertView.setVisibility(View.GONE);
alertViewAnimator = null;
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (alertViewAnimator != null && alertViewAnimator.equals(animation)) {
alertViewAnimator = null;
}
}
});
alertViewAnimator.start();
}
}
}, 3000);
}
private void hidePinnedMessageView(boolean animated) {
if (pinnedMessageView.getTag() == null) {
pinnedMessageView.setTag(1);
@@ -6956,119 +6884,28 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private void createDeleteMessagesAlert(final MessageObject finalSelectedObject) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("messages", finalSelectedObject != null ? 1 : selectedMessagesIds[0].size() + selectedMessagesIds[1].size())));
//final boolean[] checks = new boolean[3];
//TLRPC.User user = null;
/*
if (currentChat != null && currentChat.megagroup) {
if (finalSelectedObject != null) {
if (finalSelectedObject.messageOwner.action == null || finalSelectedObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) {
user = MessagesController.getInstance().getUser(finalSelectedObject.messageOwner.from_id);
}
} else {
int from_id = -1;
for (int a = 1; a >= 0; a--) {
int channelId = 0;
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) {
MessageObject msg = entry.getValue();
if (from_id == -1) {
from_id = msg.messageOwner.from_id;
}
if (from_id < 0 || from_id != msg.messageOwner.from_id) {
from_id = -2;
break;
}
}
if (from_id == -2) {
break;
}
}
if (from_id != -1) {
user = MessagesController.getInstance().getUser(from_id);
}
}
if (user != null && user.id != UserConfig.getClientUserId()) {
FrameLayout frameLayout = new FrameLayout(getParentActivity());
if (Build.VERSION.SDK_INT >= 21) {
frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0);
}
for (int a = 0; a < 3; a++) {
CheckBoxCell cell = new CheckBoxCell(getParentActivity());
cell.setBackgroundResource(R.drawable.list_selector);
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 if (a == 2) {
cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(user.first_name, user.last_name)), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 48 * a, 8, 0));
cell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBoxCell cell = (CheckBoxCell) v;
Integer num = (Integer) cell.getTag();
checks[num] = !checks[num];
cell.setChecked(checks[num], true);
}
});
}
builder.setView(frameLayout);
} else {
user = null;
}
}
*/
//final TLRPC.User userFinal = user;
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getParentActivity(), LocaleController.getString("NotYetImplemented", R.string.NotYetImplemented), Toast.LENGTH_LONG).show();
ArrayList<Integer> ids = null;
if (finalSelectedObject != null) {
// delete a single selected message by the single-click-message menu (we don't use this approach)
/*
ids = new ArrayList<>();
ids.add(finalSelectedObject.getId());
ArrayList<Long> random_ids = null;
if (currentEncryptedChat != null && finalSelectedObject.messageOwner.random_id != 0 && finalSelectedObject.type != 10) {
random_ids = new ArrayList<>();
random_ids.add(finalSelectedObject.messageOwner.random_id);
for (int a = 1; a >= 0; a--) {
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) {
MessageObject msg = entry.getValue();
int id_to_del = msg.messageOwner.id;
MrMailbox.MrMailboxDeleteMsgById(MrMailbox.hMailbox, id_to_del);
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, finalSelectedObject.messageOwner.to_id.channel_id);
*/
} else {
// delete all selected messages
/*
for (int a = 1; a >= 0; a--) {
ids = new ArrayList<>(selectedMessagesIds[a].keySet());
ArrayList<Long> random_ids = null;
int channelId = 0;
if (!ids.isEmpty()) {
MessageObject msg = selectedMessagesIds[a].get(ids.get(0));
if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) {
channelId = msg.messageOwner.to_id.channel_id;
}
}
if (currentEncryptedChat != null) {
random_ids = new ArrayList<>();
for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds[a].entrySet()) {
MessageObject msg = entry.getValue();
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId);
}
*/
actionBar.hideActionMode();
updatePinnedMessageView(true);
updateVisibleRows();
}
actionBar.hideActionMode();
updatePinnedMessageView(true);
updateVisibleRows();
MrMailbox.reloadMainChatlist();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
/*
if (userFinal != null) {
if (checks[0]) {