mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bc34daf35 | |||
| c47482851b | |||
| e2fb3968ca | |||
| ceffc5df1c | |||
| e6fd96bf35 |
@@ -122,9 +122,6 @@ public abstract class BaseConversationListFragment extends Fragment implements A
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
if (SendRelayedMessageUtil.containsVideoType(context, uris)) {
|
||||
message += "\n\n" + getString(R.string.videos_sent_without_recoding);
|
||||
}
|
||||
new AlertDialog.Builder(context)
|
||||
.setMessage(message)
|
||||
.setCancelable(false)
|
||||
@@ -132,11 +129,16 @@ public abstract class BaseConversationListFragment extends Fragment implements A
|
||||
.setPositiveButton(
|
||||
R.string.menu_send,
|
||||
(dialog, which) -> {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
SendRelayedMessageUtil.immediatelyRelay(
|
||||
getActivity(), selectedChats.toArray(new Long[selectedChats.size()]));
|
||||
activity,
|
||||
selectedChats.toArray(new Long[selectedChats.size()]),
|
||||
() -> activity.finish());
|
||||
actionMode.finish();
|
||||
actionMode = null;
|
||||
getActivity().finish();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@@ -860,9 +860,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private void askSendingFiles(ArrayList<Uri> uriList, Runnable onConfirm) {
|
||||
String message =
|
||||
String.format(getString(R.string.ask_send_files_to_chat), uriList.size(), dcChat.getName());
|
||||
if (SendRelayedMessageUtil.containsVideoType(context, uriList)) {
|
||||
message += "\n\n" + getString(R.string.videos_sent_without_recoding);
|
||||
}
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setCancelable(false)
|
||||
|
||||
@@ -626,14 +626,18 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
final DcContext dcContext = DcHelper.getContext(this);
|
||||
int fwdAccId = getForwardedMessageAccountId(this);
|
||||
if (fwdAccId == dcContext.getAccountId() && dcContext.getChat(chatId).isSelfTalk()) {
|
||||
SendRelayedMessageUtil.immediatelyRelay(this, chatId);
|
||||
Toast.makeText(
|
||||
this,
|
||||
DynamicTheme.getCheckmarkEmoji(this) + " " + getString(R.string.saved),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
handleResetRelaying();
|
||||
finish();
|
||||
SendRelayedMessageUtil.immediatelyRelay(
|
||||
this,
|
||||
chatId,
|
||||
() -> {
|
||||
Toast.makeText(
|
||||
this,
|
||||
DynamicTheme.getCheckmarkEmoji(this) + " " + getString(R.string.saved),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
handleResetRelaying();
|
||||
finish();
|
||||
});
|
||||
} else {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.ACCOUNT_ID_EXTRA, dcContext.getAccountId());
|
||||
|
||||
@@ -9,6 +9,7 @@ import static org.thoughtcrime.securesms.util.ShareUtil.isSharing;
|
||||
import static org.thoughtcrime.securesms.util.ShareUtil.resetRelayingMessageContent;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
@@ -26,57 +27,75 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.thoughtcrime.securesms.ConversationListRelayingActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.video.recode.VideoRecoder;
|
||||
|
||||
public class SendRelayedMessageUtil {
|
||||
private static final String TAG = SendRelayedMessageUtil.class.getSimpleName();
|
||||
|
||||
public static void immediatelyRelay(Activity activity, int chatId) {
|
||||
immediatelyRelay(activity, new Long[] {(long) chatId});
|
||||
immediatelyRelay(activity, chatId, null);
|
||||
}
|
||||
|
||||
public static void immediatelyRelay(Activity activity, int chatId, Runnable onCompletion) {
|
||||
immediatelyRelay(activity, new Long[] {(long) chatId}, onCompletion);
|
||||
}
|
||||
|
||||
public static void immediatelyRelay(Activity activity, final Long[] chatIds) {
|
||||
ConversationListRelayingActivity.finishActivity();
|
||||
immediatelyRelay(activity, chatIds, null);
|
||||
}
|
||||
|
||||
public static void immediatelyRelay(
|
||||
Activity activity, final Long[] chatIds, Runnable onCompletion) {
|
||||
if (isForwarding(activity)) {
|
||||
int forwardedMsgAccId = getForwardedMessageAccountId(activity);
|
||||
int[] forwardedMessageIDs = getForwardedMessageIDs(activity);
|
||||
resetRelayingMessageContent(activity);
|
||||
if (forwardedMessageIDs == null || forwardedMsgAccId <= 0) return;
|
||||
if (forwardedMessageIDs == null || forwardedMsgAccId <= 0) {
|
||||
runOnCompletion(onCompletion);
|
||||
return;
|
||||
}
|
||||
|
||||
Util.runOnAnyBackgroundThread(
|
||||
() -> {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
int accId = dcContext.getAccountId();
|
||||
if (forwardedMsgAccId != accId) {
|
||||
Rpc rpc = DcHelper.getRpc(activity);
|
||||
List<Integer> list = Util.toList(forwardedMessageIDs);
|
||||
for (long longChatId : chatIds) {
|
||||
try {
|
||||
rpc.forwardMessagesToAccount(forwardedMsgAccId, list, accId, (int) longChatId);
|
||||
} catch (RpcException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (long longChatId : chatIds) {
|
||||
int chatId = (int) longChatId;
|
||||
if (dcContext.getChat(chatId).isSelfTalk()) {
|
||||
for (int msgId : forwardedMessageIDs) {
|
||||
DcMsg msg = dcContext.getMsg(msgId);
|
||||
if (msg.canSave() && msg.getSavedMsgId() == 0 && msg.getChatId() != chatId) {
|
||||
dcContext.saveMsgs(new int[] {msgId});
|
||||
} else {
|
||||
handleForwarding(activity, chatId, new int[] {msgId});
|
||||
try {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
int accId = dcContext.getAccountId();
|
||||
if (forwardedMsgAccId != accId) {
|
||||
Rpc rpc = DcHelper.getRpc(activity);
|
||||
List<Integer> list = Util.toList(forwardedMessageIDs);
|
||||
for (long longChatId : chatIds) {
|
||||
try {
|
||||
rpc.forwardMessagesToAccount(forwardedMsgAccId, list, accId, (int) longChatId);
|
||||
} catch (RpcException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleForwarding(activity, chatId, forwardedMessageIDs);
|
||||
return;
|
||||
}
|
||||
|
||||
for (long longChatId : chatIds) {
|
||||
int chatId = (int) longChatId;
|
||||
if (dcContext.getChat(chatId).isSelfTalk()) {
|
||||
for (int msgId : forwardedMessageIDs) {
|
||||
DcMsg msg = dcContext.getMsg(msgId);
|
||||
if (msg.canSave() && msg.getSavedMsgId() == 0 && msg.getChatId() != chatId) {
|
||||
dcContext.saveMsgs(new int[] {msgId});
|
||||
} else {
|
||||
handleForwarding(activity, chatId, new int[] {msgId});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleForwarding(activity, chatId, forwardedMessageIDs);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
runOnCompletion(onCompletion);
|
||||
}
|
||||
});
|
||||
} else if (isSharing(activity)) {
|
||||
@@ -88,14 +107,30 @@ public class SendRelayedMessageUtil {
|
||||
resetRelayingMessageContent(activity);
|
||||
Util.runOnAnyBackgroundThread(
|
||||
() -> {
|
||||
for (long chatId : chatIds) {
|
||||
sendMultipleMsgs(
|
||||
activity, (int) chatId, sharedUris, msgType, sharedHtml, subject, sharedText);
|
||||
try {
|
||||
for (long chatId : chatIds) {
|
||||
sendMultipleMsgs(
|
||||
activity, (int) chatId, sharedUris, msgType, sharedHtml, subject, sharedText);
|
||||
}
|
||||
} finally {
|
||||
runOnCompletion(onCompletion);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
runOnCompletion(onCompletion);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runOnCompletion(Runnable onCompletion) {
|
||||
Util.runOnMain(
|
||||
() -> {
|
||||
ConversationListRelayingActivity.finishActivity();
|
||||
if (onCompletion != null) {
|
||||
onCompletion.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void handleForwarding(Context context, int chatId, int[] forwardedMessageIDs) {
|
||||
DcContext dcContext = DcHelper.getContext(context);
|
||||
dcContext.forwardMsgs(forwardedMessageIDs, chatId);
|
||||
@@ -118,17 +153,64 @@ public class SendRelayedMessageUtil {
|
||||
ArrayList<Uri> uris = sharedUris;
|
||||
String text = sharedText;
|
||||
|
||||
boolean hasVideos = containsVideoType(context, uris);
|
||||
AtomicReference<ProgressDialog> progressDialogRef = new AtomicReference<>(null);
|
||||
if (hasVideos && context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
Util.runOnMain(
|
||||
() -> {
|
||||
try {
|
||||
if (!activity.isFinishing()) {
|
||||
progressDialogRef.set(
|
||||
ProgressDialog.show(
|
||||
activity, "", context.getString(R.string.one_moment), true, false));
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(TAG, "Failed to show recoding progress dialog", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (uris.size() == 1) {
|
||||
dcContext.sendMsg(
|
||||
chatId, createMessage(context, uris.get(0), msgType, sharedHtml, subject, text));
|
||||
DcMsg msg = createMessage(context, uris.get(0), msgType, sharedHtml, subject, text);
|
||||
if (msg.getType() == DcMsg.DC_MSG_VIDEO) {
|
||||
if (!VideoRecoder.prepareVideo(context, chatId, msg)) {
|
||||
dismissProgressDialog(progressDialogRef);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dcContext.sendMsg(chatId, msg);
|
||||
} else {
|
||||
if (text != null || sharedHtml != null) {
|
||||
dcContext.sendMsg(chatId, createMessage(context, null, null, sharedHtml, subject, text));
|
||||
}
|
||||
for (Uri uri : uris) {
|
||||
dcContext.sendMsg(chatId, createMessage(context, uri, null, null, subject, null));
|
||||
DcMsg msg = createMessage(context, uri, null, null, subject, null);
|
||||
if (msg.getType() == DcMsg.DC_MSG_VIDEO) {
|
||||
if (!VideoRecoder.prepareVideo(context, chatId, msg)) {
|
||||
Log.w(TAG, "prepareVideo failed for " + uri + ", skipping");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dcContext.sendMsg(chatId, msg);
|
||||
}
|
||||
}
|
||||
|
||||
dismissProgressDialog(progressDialogRef);
|
||||
}
|
||||
|
||||
private static void dismissProgressDialog(AtomicReference<ProgressDialog> progressDialogRef) {
|
||||
ProgressDialog dialog = progressDialogRef.get();
|
||||
if (dialog != null) {
|
||||
Util.runOnMain(
|
||||
() -> {
|
||||
try {
|
||||
dialog.dismiss();
|
||||
} catch (final IllegalArgumentException e) {
|
||||
// The activity is finishing/destroyed, do nothing.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean containsVideoType(Context context, ArrayList<Uri> uris) {
|
||||
|
||||
Reference in New Issue
Block a user