From 963327dd6461a93a0ffa7c3c209b3ca41d9cb3ec Mon Sep 17 00:00:00 2001 From: Hocuri Date: Wed, 11 Dec 2024 13:53:36 +0100 Subject: [PATCH] Remove prepareMsg (and OUT_PREPARING message state) (#3468) This PR removes prepareMsg, which put messages into the OUT_PREPARING state and was used while videos were recoded. It also removes the now-unused method isIncreation(). - It was buggy because when you forwarded a message while it was InPreparation, or when the app was killed while a message is InPreparation, the message would stay InPreparation forever. - Android is the only UI using this InPreparation (according to @r10s, I didn't check this myself), so we can simplify some things in core, which will also make it easier to deduplicate blob files. --- jni/dc_wrapper.c | 12 ------------ src/main/java/com/b44t/messenger/DcContext.java | 1 - src/main/java/com/b44t/messenger/DcMsg.java | 1 - .../thoughtcrime/securesms/ConversationActivity.java | 12 ++++++++++++ .../securesms/video/recode/VideoRecoder.java | 6 ++---- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 5bca008d5..31f57802f 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -702,12 +702,6 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_resendMsgs(JNIEnv *env, job } -JNIEXPORT jint Java_com_b44t_messenger_DcContext_prepareMsg(JNIEnv *env, jobject obj, jint chat_id, jobject msg) -{ - return dc_prepare_msg(get_dc_context(env, obj), chat_id, get_dc_msg(env, msg)); -} - - JNIEXPORT jint Java_com_b44t_messenger_DcContext_sendMsg(JNIEnv *env, jobject obj, jint chat_id, jobject msg) { return dc_send_msg(get_dc_context(env, obj), chat_id, get_dc_msg(env, msg)); @@ -1578,12 +1572,6 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_isForwarded(JNIEnv *env, jobjec } -JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_isIncreation(JNIEnv *env, jobject obj) -{ - return dc_msg_is_increation(get_dc_msg(env, obj))!=0; -} - - JNIEXPORT jboolean Java_com_b44t_messenger_DcMsg_isInfo(JNIEnv *env, jobject obj) { return dc_msg_is_info(get_dc_msg(env, obj))!=0; diff --git a/src/main/java/com/b44t/messenger/DcContext.java b/src/main/java/com/b44t/messenger/DcContext.java index 6fd130f36..0f9ae87c7 100644 --- a/src/main/java/com/b44t/messenger/DcContext.java +++ b/src/main/java/com/b44t/messenger/DcContext.java @@ -194,7 +194,6 @@ protected void finalize() throws Throwable { public native void deleteMsgs (int msg_ids[]); public native void forwardMsgs (int msg_ids[], int chat_id); public native boolean resendMsgs (int msg_ids[]); - public native int prepareMsg (int chat_id, DcMsg msg); public native int sendMsg (int chat_id, DcMsg msg); public native int sendTextMsg (int chat_id, String text); public native int sendVideochatInvitation(int chat_id); diff --git a/src/main/java/com/b44t/messenger/DcMsg.java b/src/main/java/com/b44t/messenger/DcMsg.java index 45d2ed51f..e41b237a6 100644 --- a/src/main/java/com/b44t/messenger/DcMsg.java +++ b/src/main/java/com/b44t/messenger/DcMsg.java @@ -155,7 +155,6 @@ public JSONObject getWebxdcInfo () { public native String getSetupCodeBegin (); public native String getVideochatUrl (); public native int getVideochatType (); - public native boolean isIncreation (); public native void setText (String text); public native void setFile (String file, String filemime); public native void setDimension (int width, int height); diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationActivity.java b/src/main/java/org/thoughtcrime/securesms/ConversationActivity.java index e8ddffd28..62a2b3f31 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationActivity.java @@ -117,6 +117,7 @@ import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener; import org.thoughtcrime.securesms.util.guava.Optional; +import org.thoughtcrime.securesms.util.views.ProgressDialog; import org.thoughtcrime.securesms.util.views.Stub; import org.thoughtcrime.securesms.video.recode.VideoRecoder; import org.thoughtcrime.securesms.videochat.VideochatUtil; @@ -171,6 +172,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private View composePanel; private ScaleStableImageView backgroundView; private MessageRequestsBottomView messageRequestBottomView; + private ProgressDialog progressDialog; private AttachmentTypeSelector attachmentTypeSelector; private AttachmentManager attachmentManager; @@ -1072,7 +1074,17 @@ protected Void doInBackground(Object... param) { { boolean doSend = true; if (recompress==DcMsg.DC_MSG_VIDEO) { + Util.runOnMain(() -> { + progressDialog = ProgressDialog.show( + ConversationActivity.this, + "", + getString(R.string.one_moment), + true, + false + ); + }); doSend = VideoRecoder.prepareVideo(ConversationActivity.this, dcChat.getId(), msg); + Util.runOnMain(() -> progressDialog.dismiss()); } if (doSend) { diff --git a/src/main/java/org/thoughtcrime/securesms/video/recode/VideoRecoder.java b/src/main/java/org/thoughtcrime/securesms/video/recode/VideoRecoder.java index 98a483a90..b47f0e864 100644 --- a/src/main/java/org/thoughtcrime/securesms/video/recode/VideoRecoder.java +++ b/src/main/java/org/thoughtcrime/securesms/video/recode/VideoRecoder.java @@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.Util; +import org.thoughtcrime.securesms.util.views.ProgressDialog; import java.io.File; import java.nio.ByteBuffer; @@ -551,11 +552,9 @@ private static void alert(Context context, String str) } // prepareVideo() assumes the msg object is set up properly to being sent; - // the function fills out missing information and also recodes the video as needed; - // to get a responsive ui, DcChat.prepareMsg() may be called. + // the function fills out missing information and also recodes the video as needed. // return: true=video might be prepared, can be sent, false=error public static boolean prepareVideo(Context context, int chatId, DcMsg msg) { - try { String inPath = msg.getFile(); Log.i(TAG, "Preparing video: " + inPath); @@ -623,7 +622,6 @@ public static boolean prepareVideo(Context context, int chatId, DcMsg msg) { msg.setDimension(vei.resultWidth, vei.resultHeight); } msg.setDuration((int) resultDurationMs); - DcHelper.getContext(context).prepareMsg(chatId, msg); // calculate bytes vei.estimatedBytes = VideoRecoder.calculateEstimatedSize((float) resultDurationMs / vei.originalDurationMs,