2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
import static eu.siacs.conversations.ui.XmppActivity.EXTRA_ACCOUNT;
|
|
|
|
import static eu.siacs.conversations.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION;
|
|
|
|
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
|
|
|
|
import static eu.siacs.conversations.utils.PermissionUtils.allGranted;
|
|
|
|
import static eu.siacs.conversations.utils.PermissionUtils.getFirstDenied;
|
|
|
|
import static eu.siacs.conversations.utils.PermissionUtils.writeGranted;
|
|
|
|
|
2018-02-25 08:46:44 +00:00
|
|
|
import android.Manifest;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2015-07-19 16:36:28 +00:00
|
|
|
import android.app.Activity;
|
2021-09-21 09:41:35 +00:00
|
|
|
import android.app.Fragment;
|
|
|
|
import android.app.FragmentManager;
|
2014-05-01 20:33:49 +00:00
|
|
|
import android.app.PendingIntent;
|
2022-02-22 15:23:51 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2014-07-31 11:26:05 +00:00
|
|
|
import android.content.Context;
|
2014-02-16 15:32:15 +00:00
|
|
|
import android.content.DialogInterface;
|
2014-03-04 01:51:01 +00:00
|
|
|
import android.content.Intent;
|
2014-02-27 23:22:56 +00:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2021-01-23 08:25:34 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.os.Bundle;
|
2016-05-12 08:39:04 +00:00
|
|
|
import android.os.Handler;
|
2017-11-17 20:00:01 +00:00
|
|
|
import android.os.SystemClock;
|
2021-01-23 08:25:34 +00:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.MediaStore;
|
2016-11-25 14:06:43 +00:00
|
|
|
import android.text.Editable;
|
2018-10-19 13:39:31 +00:00
|
|
|
import android.text.TextUtils;
|
2016-09-12 19:18:56 +00:00
|
|
|
import android.util.Log;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2014-06-01 16:52:27 +00:00
|
|
|
import android.view.Gravity;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.LayoutInflater;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.view.MenuItem;
|
2017-11-17 20:00:01 +00:00
|
|
|
import android.view.MotionEvent;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.View;
|
2014-01-26 02:27:55 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-07-31 11:26:05 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2014-06-14 14:59:07 +00:00
|
|
|
import android.widget.AbsListView;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
2014-10-23 19:27:41 +00:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
2018-02-20 13:54:32 +00:00
|
|
|
import android.widget.CheckBox;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.ListView;
|
2017-03-20 11:55:48 +00:00
|
|
|
import android.widget.PopupMenu;
|
2014-11-04 17:52:29 +00:00
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
2014-03-04 03:09:15 +00:00
|
|
|
import android.widget.Toast;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.IdRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.core.view.inputmethod.InputConnectionCompat;
|
|
|
|
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
|
2020-04-27 09:53:31 +00:00
|
|
|
import com.google.common.base.Optional;
|
2022-08-08 19:08:28 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-04-27 09:53:31 +00:00
|
|
|
|
2014-11-04 17:52:29 +00:00
|
|
|
import java.util.ArrayList;
|
2017-04-07 17:47:33 +00:00
|
|
|
import java.util.Arrays;
|
2020-05-16 15:51:14 +00:00
|
|
|
import java.util.Collection;
|
2015-09-27 17:17:44 +00:00
|
|
|
import java.util.Collections;
|
2017-11-19 00:53:04 +00:00
|
|
|
import java.util.HashSet;
|
2018-02-20 13:54:32 +00:00
|
|
|
import java.util.Iterator;
|
2014-11-04 17:52:29 +00:00
|
|
|
import java.util.List;
|
2017-11-19 00:53:04 +00:00
|
|
|
import java.util.Set;
|
2016-02-15 22:15:04 +00:00
|
|
|
import java.util.UUID;
|
2017-03-03 10:56:08 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2014-11-04 17:52:29 +00:00
|
|
|
|
2015-02-21 10:06:52 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
|
|
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
2018-02-21 10:04:48 +00:00
|
|
|
import eu.siacs.conversations.databinding.FragmentConversationBinding;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2017-03-20 11:55:48 +00:00
|
|
|
import eu.siacs.conversations.entities.Blockable;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2018-07-09 09:35:30 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversational;
|
2014-11-15 14:16:40 +00:00
|
|
|
import eu.siacs.conversations.entities.DownloadableFile;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2018-08-26 15:32:30 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions.User;
|
2016-01-17 21:28:38 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2017-11-19 00:53:04 +00:00
|
|
|
import eu.siacs.conversations.entities.ReadByMarker;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.entities.Transferable;
|
|
|
|
import eu.siacs.conversations.entities.TransferablePlaceholder;
|
2016-03-04 10:24:40 +00:00
|
|
|
import eu.siacs.conversations.http.HttpDownloadConnection;
|
2017-01-09 16:00:08 +00:00
|
|
|
import eu.siacs.conversations.persistance.FileBackend;
|
2016-02-21 16:32:46 +00:00
|
|
|
import eu.siacs.conversations.services.MessageArchiveService;
|
2019-01-27 10:38:20 +00:00
|
|
|
import eu.siacs.conversations.services.QuickConversationsService;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2018-09-11 07:56:29 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.MediaPreviewAdapter;
|
2014-11-04 17:52:29 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ActivityResult;
|
2018-09-11 07:56:29 +00:00
|
|
|
import eu.siacs.conversations.ui.util.Attachment;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
|
2018-04-28 14:32:23 +00:00
|
|
|
import eu.siacs.conversations.ui.util.DateSeparator;
|
2018-06-11 13:32:18 +00:00
|
|
|
import eu.siacs.conversations.ui.util.EditMessageActionModeCallback;
|
2018-04-26 15:02:31 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ListViewUtils;
|
2018-03-18 22:32:30 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
2018-08-26 15:32:30 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
|
2018-02-21 22:07:53 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PresenceSelector;
|
2018-02-25 15:57:59 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ScrollState;
|
2018-02-20 07:21:07 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SendButtonAction;
|
2018-02-20 13:54:32 +00:00
|
|
|
import eu.siacs.conversations.ui.util.SendButtonTool;
|
2018-04-28 14:32:23 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ShareUtil;
|
2019-01-12 09:29:41 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ViewUtil;
|
2017-09-29 17:44:30 +00:00
|
|
|
import eu.siacs.conversations.ui.widget.EditMessage;
|
2019-01-27 10:38:20 +00:00
|
|
|
import eu.siacs.conversations.utils.AccountUtils;
|
2019-01-12 09:09:45 +00:00
|
|
|
import eu.siacs.conversations.utils.Compatibility;
|
2018-05-01 10:03:35 +00:00
|
|
|
import eu.siacs.conversations.utils.GeoHelper;
|
2017-11-07 21:22:28 +00:00
|
|
|
import eu.siacs.conversations.utils.MessageUtils;
|
2017-04-07 17:47:33 +00:00
|
|
|
import eu.siacs.conversations.utils.NickValidityChecker;
|
2018-05-04 09:39:03 +00:00
|
|
|
import eu.siacs.conversations.utils.Patterns;
|
2022-08-08 19:08:28 +00:00
|
|
|
import eu.siacs.conversations.utils.PermissionUtils;
|
2018-04-11 16:07:40 +00:00
|
|
|
import eu.siacs.conversations.utils.QuickLoader;
|
2017-11-05 20:34:40 +00:00
|
|
|
import eu.siacs.conversations.utils.StylingHelper;
|
2020-05-09 07:42:33 +00:00
|
|
|
import eu.siacs.conversations.utils.TimeFrameUtils;
|
2015-05-13 14:23:20 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2020-05-30 12:56:12 +00:00
|
|
|
import eu.siacs.conversations.xml.Namespace;
|
2021-01-23 08:25:34 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2016-02-14 22:53:17 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2015-02-21 10:06:52 +00:00
|
|
|
import eu.siacs.conversations.xmpp.chatstate.ChatState;
|
2020-04-27 09:53:31 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
2020-05-02 07:50:17 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
|
2020-04-01 08:45:03 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleFileTransferConnection;
|
2020-05-02 07:50:17 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.Media;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.OngoingRtpSession;
|
2020-04-03 14:44:29 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
|
2014-11-04 17:52:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
public class ConversationFragment extends XmppFragment
|
|
|
|
implements EditMessage.KeyboardListener,
|
|
|
|
MessageAdapter.OnContactPictureLongClicked,
|
|
|
|
MessageAdapter.OnContactPictureClicked {
|
2018-02-20 13:54:32 +00:00
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
public static final int REQUEST_SEND_MESSAGE = 0x0201;
|
|
|
|
public static final int REQUEST_DECRYPT_PGP = 0x0202;
|
|
|
|
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
|
|
|
|
public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208;
|
2018-09-16 13:58:05 +00:00
|
|
|
public static final int REQUEST_TRUST_KEYS_ATTACHMENTS = 0x0209;
|
2018-09-11 07:56:29 +00:00
|
|
|
public static final int REQUEST_START_DOWNLOAD = 0x0210;
|
|
|
|
public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211;
|
2018-10-24 18:00:06 +00:00
|
|
|
public static final int REQUEST_COMMIT_ATTACHMENTS = 0x0212;
|
2020-04-09 17:45:21 +00:00
|
|
|
public static final int REQUEST_START_AUDIO_CALL = 0x213;
|
2020-04-15 14:26:53 +00:00
|
|
|
public static final int REQUEST_START_VIDEO_CALL = 0x214;
|
2018-09-11 07:56:29 +00:00
|
|
|
public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
|
|
|
|
public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
|
|
|
|
public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
|
|
|
|
public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
|
|
|
|
public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305;
|
|
|
|
public static final int ATTACHMENT_CHOICE_INVALID = 0x0306;
|
|
|
|
public static final int ATTACHMENT_CHOICE_RECORD_VIDEO = 0x0307;
|
|
|
|
|
|
|
|
public static final String RECENTLY_USED_QUICK_ACTION = "recently_used_quick_action";
|
2022-08-08 19:08:28 +00:00
|
|
|
public static final String STATE_CONVERSATION_UUID =
|
|
|
|
ConversationFragment.class.getName() + ".uuid";
|
|
|
|
public static final String STATE_SCROLL_POSITION =
|
|
|
|
ConversationFragment.class.getName() + ".scroll_position";
|
|
|
|
public static final String STATE_PHOTO_URI =
|
|
|
|
ConversationFragment.class.getName() + ".media_previews";
|
|
|
|
public static final String STATE_MEDIA_PREVIEWS =
|
|
|
|
ConversationFragment.class.getName() + ".take_photo_uri";
|
2018-09-11 07:56:29 +00:00
|
|
|
private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid";
|
|
|
|
|
|
|
|
private final List<Message> messageList = new ArrayList<>();
|
|
|
|
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
|
|
|
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
|
2018-09-12 20:20:19 +00:00
|
|
|
private final PendingItem<ArrayList<Attachment>> pendingMediaPreviews = new PendingItem<>();
|
2018-09-11 07:56:29 +00:00
|
|
|
private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
|
|
|
|
private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>();
|
|
|
|
private final PendingItem<ScrollState> pendingScrollState = new PendingItem<>();
|
|
|
|
private final PendingItem<String> pendingLastMessageUuid = new PendingItem<>();
|
|
|
|
private final PendingItem<Message> pendingMessage = new PendingItem<>();
|
|
|
|
public Uri mPendingEditorContent = null;
|
|
|
|
protected MessageAdapter messageListAdapter;
|
|
|
|
private MediaPreviewAdapter mediaPreviewAdapter;
|
|
|
|
private String lastMessageUuid = null;
|
|
|
|
private Conversation conversation;
|
|
|
|
private FragmentConversationBinding binding;
|
|
|
|
private Toast messageLoaderToast;
|
|
|
|
private ConversationsActivity activity;
|
|
|
|
private boolean reInitRequiredOnStart = true;
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnClickListener clickToMuc =
|
|
|
|
new OnClickListener() {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
ConferenceDetailsActivity.open(getActivity(), conversation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnClickListener leaveMuc =
|
|
|
|
new OnClickListener() {
|
2018-12-09 17:25:11 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.xmppConnectionService.archiveConversation(conversation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnClickListener joinMuc =
|
|
|
|
new OnClickListener() {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
activity.xmppConnectionService.joinMuc(conversation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private final OnClickListener acceptJoin =
|
|
|
|
new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
conversation.setAttribute("accept_non_anonymous", true);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
activity.xmppConnectionService.joinMuc(conversation);
|
|
|
|
}
|
|
|
|
};
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnClickListener enterPassword =
|
|
|
|
new OnClickListener() {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
MucOptions muc = conversation.getMucOptions();
|
|
|
|
String password = muc.getPassword();
|
|
|
|
if (password == null) {
|
|
|
|
password = "";
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.quickPasswordEdit(
|
|
|
|
password,
|
|
|
|
value -> {
|
|
|
|
activity.xmppConnectionService.providePasswordForMuc(
|
|
|
|
conversation, value);
|
|
|
|
return null;
|
2018-09-11 07:56:29 +00:00
|
|
|
});
|
2022-08-08 19:08:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnScrollListener mOnScrollListener =
|
|
|
|
new OnScrollListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
if (AbsListView.OnScrollListener.SCROLL_STATE_IDLE == scrollState) {
|
|
|
|
fireReadEvent();
|
|
|
|
}
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void onScroll(
|
|
|
|
final AbsListView view,
|
|
|
|
int firstVisibleItem,
|
|
|
|
int visibleItemCount,
|
|
|
|
int totalItemCount) {
|
|
|
|
toggleScrollDownButton(view);
|
|
|
|
synchronized (ConversationFragment.this.messageList) {
|
|
|
|
if (firstVisibleItem < 5
|
|
|
|
&& conversation != null
|
|
|
|
&& conversation.messagesLoaded.compareAndSet(true, false)
|
|
|
|
&& messageList.size() > 0) {
|
|
|
|
long timestamp;
|
|
|
|
if (messageList.get(0).getType() == Message.TYPE_STATUS
|
|
|
|
&& messageList.size() >= 2) {
|
|
|
|
timestamp = messageList.get(1).getTimeSent();
|
|
|
|
} else {
|
|
|
|
timestamp = messageList.get(0).getTimeSent();
|
|
|
|
}
|
|
|
|
activity.xmppConnectionService.loadMoreMessages(
|
|
|
|
conversation,
|
|
|
|
timestamp,
|
|
|
|
new XmppConnectionService.OnMoreMessagesLoaded() {
|
|
|
|
@Override
|
|
|
|
public void onMoreMessagesLoaded(
|
|
|
|
final int c, final Conversation conversation) {
|
|
|
|
if (ConversationFragment.this.conversation
|
|
|
|
!= conversation) {
|
|
|
|
conversation.messagesLoaded.set(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
runOnUiThread(
|
|
|
|
() -> {
|
|
|
|
synchronized (messageList) {
|
|
|
|
final int oldPosition =
|
|
|
|
binding.messagesView
|
|
|
|
.getFirstVisiblePosition();
|
|
|
|
Message message = null;
|
|
|
|
int childPos;
|
|
|
|
for (childPos = 0;
|
|
|
|
childPos + oldPosition
|
|
|
|
< messageList.size();
|
|
|
|
++childPos) {
|
|
|
|
message =
|
|
|
|
messageList.get(
|
|
|
|
oldPosition
|
|
|
|
+ childPos);
|
|
|
|
if (message.getType()
|
|
|
|
!= Message.TYPE_STATUS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final String uuid =
|
|
|
|
message != null
|
|
|
|
? message.getUuid()
|
|
|
|
: null;
|
|
|
|
View v =
|
|
|
|
binding.messagesView.getChildAt(
|
|
|
|
childPos);
|
|
|
|
final int pxOffset =
|
|
|
|
(v == null) ? 0 : v.getTop();
|
|
|
|
ConversationFragment.this.conversation
|
|
|
|
.populateWithMessages(
|
|
|
|
ConversationFragment
|
|
|
|
.this
|
|
|
|
.messageList);
|
|
|
|
try {
|
|
|
|
updateStatusMessages();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"caught illegal state exception while updating status messages");
|
|
|
|
}
|
|
|
|
messageListAdapter
|
|
|
|
.notifyDataSetChanged();
|
|
|
|
int pos =
|
|
|
|
Math.max(
|
|
|
|
getIndexOf(
|
|
|
|
uuid,
|
|
|
|
messageList),
|
|
|
|
0);
|
|
|
|
binding.messagesView
|
|
|
|
.setSelectionFromTop(
|
|
|
|
pos, pxOffset);
|
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
|
|
|
conversation.messagesLoaded.set(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void informUser(final int resId) {
|
|
|
|
|
|
|
|
runOnUiThread(
|
|
|
|
() -> {
|
|
|
|
if (messageLoaderToast != null) {
|
|
|
|
messageLoaderToast.cancel();
|
|
|
|
}
|
|
|
|
if (ConversationFragment.this.conversation
|
|
|
|
!= conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
messageLoaderToast =
|
|
|
|
Toast.makeText(
|
|
|
|
view.getContext(),
|
|
|
|
resId,
|
|
|
|
Toast.LENGTH_LONG);
|
|
|
|
messageLoaderToast.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
};
|
|
|
|
private final EditMessage.OnCommitContentListener mEditorContentListener =
|
|
|
|
new EditMessage.OnCommitContentListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onCommitContent(
|
|
|
|
InputContentInfoCompat inputContentInfo,
|
|
|
|
int flags,
|
|
|
|
Bundle opts,
|
|
|
|
String[] contentMimeTypes) {
|
|
|
|
// try to get permission to read the image, if applicable
|
|
|
|
if ((flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION)
|
|
|
|
!= 0) {
|
|
|
|
try {
|
|
|
|
inputContentInfo.requestPermission();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"InputContentInfoCompat#requestPermission() failed.",
|
|
|
|
e);
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
activity.getString(
|
|
|
|
R.string.no_permission_to_access_x,
|
|
|
|
inputContentInfo.getDescription()),
|
|
|
|
Toast.LENGTH_LONG)
|
|
|
|
.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasPermissions(
|
|
|
|
REQUEST_ADD_EDITOR_CONTENT,
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
attachEditorContentToConversation(inputContentInfo.getContentUri());
|
|
|
|
} else {
|
|
|
|
mPendingEditorContent = inputContentInfo.getContentUri();
|
|
|
|
}
|
|
|
|
return true;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
};
|
2018-09-11 07:56:29 +00:00
|
|
|
private Message selectedMessage;
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnClickListener mEnableAccountListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Account account = conversation == null ? null : conversation.getAccount();
|
|
|
|
if (account != null) {
|
|
|
|
account.setOption(Account.OPTION_DISABLED, false);
|
|
|
|
activity.xmppConnectionService.updateAccount(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnClickListener mUnblockClickListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
v.post(() -> v.setVisibility(View.INVISIBLE));
|
|
|
|
if (conversation.isDomainBlocked()) {
|
|
|
|
BlockContactDialog.show(activity, conversation);
|
|
|
|
} else {
|
|
|
|
unblockConversation(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-12-22 13:30:54 +00:00
|
|
|
private final OnClickListener mBlockClickListener = this::showBlockSubmenu;
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnClickListener mAddBackClickListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Contact contact = conversation == null ? null : conversation.getContact();
|
|
|
|
if (contact != null) {
|
|
|
|
activity.xmppConnectionService.createContact(contact, true);
|
|
|
|
activity.switchToContactDetails(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-12-22 13:30:54 +00:00
|
|
|
private final View.OnLongClickListener mLongPressBlockListener = this::showBlockSubmenu;
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnClickListener mAllowPresenceSubscription =
|
|
|
|
new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Contact contact = conversation == null ? null : conversation.getContact();
|
|
|
|
if (contact != null) {
|
|
|
|
activity.xmppConnectionService.sendPresencePacket(
|
|
|
|
contact.getAccount(),
|
|
|
|
activity.xmppConnectionService
|
|
|
|
.getPresenceGenerator()
|
|
|
|
.sendPresenceUpdatesTo(contact));
|
|
|
|
hideSnackbar();
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
};
|
|
|
|
protected OnClickListener clickToDecryptListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
PendingIntent pendingIntent =
|
|
|
|
conversation.getAccount().getPgpDecryptionService().getPendingIntent();
|
|
|
|
if (pendingIntent != null) {
|
|
|
|
try {
|
|
|
|
getActivity()
|
|
|
|
.startIntentSenderForResult(
|
|
|
|
pendingIntent.getIntentSender(),
|
|
|
|
REQUEST_DECRYPT_PGP,
|
|
|
|
null,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
} catch (SendIntentException e) {
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
R.string.unable_to_connect_to_keychain,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
|
|
|
conversation
|
|
|
|
.getAccount()
|
|
|
|
.getPgpDecryptionService()
|
|
|
|
.continueDecryption(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateSnackBar(conversation);
|
|
|
|
}
|
|
|
|
};
|
2020-12-22 13:30:54 +00:00
|
|
|
private final AtomicBoolean mSendingPgpMessage = new AtomicBoolean(false);
|
2022-08-08 19:08:28 +00:00
|
|
|
private final OnEditorActionListener mEditorActionListener =
|
|
|
|
(v, actionId, event) -> {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager)
|
|
|
|
activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
if (imm != null && imm.isFullscreenMode()) {
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnClickListener mScrollButtonListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
stopScrolling();
|
|
|
|
setSelection(binding.messagesView.getCount() - 1, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private final OnClickListener mSendButtonListener =
|
|
|
|
new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Object tag = v.getTag();
|
|
|
|
if (tag instanceof SendButtonAction) {
|
|
|
|
SendButtonAction action = (SendButtonAction) tag;
|
|
|
|
switch (action) {
|
|
|
|
case TAKE_PHOTO:
|
|
|
|
case RECORD_VIDEO:
|
|
|
|
case SEND_LOCATION:
|
|
|
|
case RECORD_VOICE:
|
|
|
|
case CHOOSE_PICTURE:
|
|
|
|
attachFile(action.toChoice());
|
|
|
|
break;
|
|
|
|
case CANCEL:
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation.setCorrectingMessage(null)) {
|
|
|
|
binding.textinput.setText("");
|
|
|
|
binding.textinput.append(conversation.getDraftMessage());
|
|
|
|
conversation.setDraftMessage(null);
|
|
|
|
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
conversation.setNextCounterpart(null);
|
|
|
|
binding.textinput.setText("");
|
|
|
|
} else {
|
|
|
|
binding.textinput.setText("");
|
|
|
|
}
|
|
|
|
updateChatMsgHint();
|
|
|
|
updateSendButton();
|
|
|
|
updateEditablity();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendMessage();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
} else {
|
2018-09-11 07:56:29 +00:00
|
|
|
sendMessage();
|
2022-08-08 19:08:28 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
};
|
2018-09-11 07:56:29 +00:00
|
|
|
private int completionIndex = 0;
|
|
|
|
private int lastCompletionLength = 0;
|
|
|
|
private String incomplete;
|
|
|
|
private int lastCompletionCursor;
|
|
|
|
private boolean firstWord = false;
|
|
|
|
private Message mPendingDownloadableMessage;
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
private static ConversationFragment findConversationFragment(Activity activity) {
|
|
|
|
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
|
2019-04-26 09:18:16 +00:00
|
|
|
if (fragment instanceof ConversationFragment) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return (ConversationFragment) fragment;
|
|
|
|
}
|
2021-09-21 09:41:35 +00:00
|
|
|
fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
2019-04-26 09:18:16 +00:00
|
|
|
if (fragment instanceof ConversationFragment) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return (ConversationFragment) fragment;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static void startStopPending(Activity activity) {
|
|
|
|
ConversationFragment fragment = findConversationFragment(activity);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (fragment != null) {
|
|
|
|
fragment.messageListAdapter.startStopPending();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static void downloadFile(Activity activity, Message message) {
|
|
|
|
ConversationFragment fragment = findConversationFragment(activity);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (fragment != null) {
|
|
|
|
fragment.startDownloadable(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static void registerPendingMessage(Activity activity, Message message) {
|
|
|
|
ConversationFragment fragment = findConversationFragment(activity);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (fragment != null) {
|
|
|
|
fragment.pendingMessage.push(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static void openPendingMessage(Activity activity) {
|
|
|
|
ConversationFragment fragment = findConversationFragment(activity);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (fragment != null) {
|
|
|
|
Message message = fragment.pendingMessage.pop();
|
|
|
|
if (message != null) {
|
|
|
|
fragment.messageListAdapter.openDownloadable(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static Conversation getConversation(Activity activity) {
|
|
|
|
return getConversation(activity, R.id.secondary_fragment);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
private static Conversation getConversation(Activity activity, @IdRes int res) {
|
|
|
|
final Fragment fragment = activity.getFragmentManager().findFragmentById(res);
|
2020-12-22 13:30:54 +00:00
|
|
|
if (fragment instanceof ConversationFragment) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return ((ConversationFragment) fragment).getConversation();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static ConversationFragment get(Activity activity) {
|
|
|
|
FragmentManager fragmentManager = activity.getFragmentManager();
|
2018-09-11 07:56:29 +00:00
|
|
|
Fragment fragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
2020-12-22 13:30:54 +00:00
|
|
|
if (fragment instanceof ConversationFragment) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return (ConversationFragment) fragment;
|
|
|
|
} else {
|
|
|
|
fragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
2022-08-08 19:08:28 +00:00
|
|
|
return fragment instanceof ConversationFragment
|
|
|
|
? (ConversationFragment) fragment
|
|
|
|
: null;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:41:35 +00:00
|
|
|
public static Conversation getConversationReliable(Activity activity) {
|
|
|
|
final Conversation conversation = getConversation(activity, R.id.secondary_fragment);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (conversation != null) {
|
|
|
|
return conversation;
|
|
|
|
}
|
2021-09-21 09:41:35 +00:00
|
|
|
return getConversation(activity, R.id.main_fragment);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean scrolledToBottom(AbsListView listView) {
|
|
|
|
final int count = listView.getCount();
|
|
|
|
if (count == 0) {
|
|
|
|
return true;
|
|
|
|
} else if (listView.getLastVisiblePosition() == count - 1) {
|
|
|
|
final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
|
|
|
|
return lastChild != null && lastChild.getBottom() <= listView.getHeight();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleScrollDownButton() {
|
|
|
|
toggleScrollDownButton(binding.messagesView);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void toggleScrollDownButton(AbsListView listView) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scrolledToBottom(listView)) {
|
|
|
|
lastMessageUuid = null;
|
|
|
|
hideUnreadMessagesCount();
|
|
|
|
} else {
|
|
|
|
binding.scrollToBottomButton.setEnabled(true);
|
2018-10-04 14:46:35 +00:00
|
|
|
binding.scrollToBottomButton.show();
|
2018-09-11 07:56:29 +00:00
|
|
|
if (lastMessageUuid == null) {
|
|
|
|
lastMessageUuid = conversation.getLatestMessage().getUuid();
|
|
|
|
}
|
|
|
|
if (conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid) > 0) {
|
|
|
|
binding.unreadCountCustomView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getIndexOf(String uuid, List<Message> messages) {
|
|
|
|
if (uuid == null) {
|
|
|
|
return messages.size() - 1;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < messages.size(); ++i) {
|
|
|
|
if (uuid.equals(messages.get(i).getUuid())) {
|
|
|
|
return i;
|
|
|
|
} else {
|
|
|
|
Message next = messages.get(i);
|
|
|
|
while (next != null && next.wasMergedIntoPrevious()) {
|
|
|
|
if (uuid.equals(next.getUuid())) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
next = next.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ScrollState getScrollPosition() {
|
2018-12-05 08:27:10 +00:00
|
|
|
final ListView listView = this.binding == null ? null : this.binding.messagesView;
|
2022-08-08 19:08:28 +00:00
|
|
|
if (listView == null
|
|
|
|
|| listView.getCount() == 0
|
|
|
|
|| listView.getLastVisiblePosition() == listView.getCount() - 1) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
final int pos = listView.getFirstVisiblePosition();
|
|
|
|
final View view = listView.getChildAt(0);
|
|
|
|
if (view == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return new ScrollState(pos, view.getTop());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setScrollPosition(ScrollState scrollPosition, String lastMessageUuid) {
|
|
|
|
if (scrollPosition != null) {
|
|
|
|
|
|
|
|
this.lastMessageUuid = lastMessageUuid;
|
|
|
|
if (lastMessageUuid != null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
binding.unreadCountCustomView.setUnreadCount(
|
|
|
|
conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid));
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
// TODO maybe this needs a 'post'
|
|
|
|
this.binding.messagesView.setSelectionFromTop(
|
|
|
|
scrollPosition.position, scrollPosition.offset);
|
2018-09-11 07:56:29 +00:00
|
|
|
toggleScrollDownButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void attachLocationToConversation(Conversation conversation, Uri uri) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService.attachLocationToConversation(
|
|
|
|
conversation,
|
|
|
|
uri,
|
|
|
|
new UiCallback<Message>() {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void success(Message message) {}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void error(int errorCode, Message object) {
|
|
|
|
// TODO show possible pgp error
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void userInputRequired(PendingIntent pi, Message object) {}
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void attachFileToConversation(Conversation conversation, Uri uri, String type) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final Toast prepareFileToast =
|
|
|
|
Toast.makeText(getActivity(), getText(R.string.preparing_file), Toast.LENGTH_LONG);
|
2018-09-11 07:56:29 +00:00
|
|
|
prepareFileToast.show();
|
|
|
|
activity.delegateUriPermissionsToService(uri);
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService.attachFileToConversation(
|
|
|
|
conversation,
|
|
|
|
uri,
|
|
|
|
type,
|
|
|
|
new UiInformableCallback<Message>() {
|
|
|
|
@Override
|
|
|
|
public void inform(final String text) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
runOnUiThread(() -> activity.replaceToast(text));
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
runOnUiThread(() -> activity.hideToast());
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void error(final int errorCode, Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
runOnUiThread(() -> activity.replaceToast(getString(errorCode)));
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void userInputRequired(PendingIntent pi, Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void attachEditorContentToConversation(Uri uri) {
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), uri, Attachment.Type.FILE));
|
2018-09-11 07:56:29 +00:00
|
|
|
toggleInputMethod();
|
|
|
|
}
|
|
|
|
|
2021-11-07 10:35:00 +00:00
|
|
|
private void attachImageToConversation(Conversation conversation, Uri uri, String type) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final Toast prepareFileToast =
|
|
|
|
Toast.makeText(getActivity(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
2018-09-11 07:56:29 +00:00
|
|
|
prepareFileToast.show();
|
|
|
|
activity.delegateUriPermissionsToService(uri);
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService.attachImageToConversation(
|
|
|
|
conversation,
|
|
|
|
uri,
|
|
|
|
type,
|
2018-09-11 07:56:29 +00:00
|
|
|
new UiCallback<Message>() {
|
|
|
|
|
|
|
|
@Override
|
2019-06-26 15:40:05 +00:00
|
|
|
public void userInputRequired(PendingIntent pi, Message object) {
|
2018-09-11 07:56:29 +00:00
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
hidePrepareFileToast(prepareFileToast);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-07-09 12:46:18 +00:00
|
|
|
public void error(final int error, final Message message) {
|
2018-09-11 07:56:29 +00:00
|
|
|
hidePrepareFileToast(prepareFileToast);
|
2022-07-09 12:46:18 +00:00
|
|
|
final ConversationsActivity activity = ConversationFragment.this.activity;
|
|
|
|
if (activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.runOnUiThread(() -> activity.replaceToast(getString(error)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hidePrepareFileToast(final Toast prepareFileToast) {
|
|
|
|
if (prepareFileToast != null && activity != null) {
|
|
|
|
activity.runOnUiThread(prepareFileToast::cancel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendMessage() {
|
|
|
|
if (mediaPreviewAdapter.hasAttachments()) {
|
|
|
|
commitAttachments();
|
|
|
|
return;
|
|
|
|
}
|
2018-10-03 21:23:44 +00:00
|
|
|
final Editable text = this.binding.textinput.getText();
|
2018-10-24 18:00:06 +00:00
|
|
|
final String body = text == null ? "" : text.toString();
|
2018-09-11 07:56:29 +00:00
|
|
|
final Conversation conversation = this.conversation;
|
|
|
|
if (body.length() == 0 || conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-04 15:52:17 +00:00
|
|
|
if (trustKeysIfNeeded(conversation, REQUEST_TRUST_KEYS_TEXT)) {
|
2018-10-03 21:23:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
final Message message;
|
|
|
|
if (conversation.getCorrectingMessage() == null) {
|
|
|
|
message = new Message(conversation, body, conversation.getNextEncryption());
|
2019-04-27 09:46:43 +00:00
|
|
|
Message.configurePrivateMessage(message);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
|
|
|
message = conversation.getCorrectingMessage();
|
|
|
|
message.setBody(body);
|
2018-12-01 14:52:44 +00:00
|
|
|
message.putEdited(message.getUuid(), message.getServerMsgId());
|
|
|
|
message.setServerMsgId(null);
|
2018-09-11 07:56:29 +00:00
|
|
|
message.setUuid(UUID.randomUUID().toString());
|
|
|
|
}
|
|
|
|
switch (conversation.getNextEncryption()) {
|
|
|
|
case Message.ENCRYPTION_PGP:
|
|
|
|
sendPgpMessage(message);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 15:52:17 +00:00
|
|
|
private boolean trustKeysIfNeeded(final Conversation conversation, final int requestCode) {
|
2022-08-08 19:08:28 +00:00
|
|
|
return conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL
|
|
|
|
&& trustKeysIfNeeded(requestCode);
|
2021-05-04 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
protected boolean trustKeysIfNeeded(int requestCode) {
|
|
|
|
AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
|
|
|
|
final List<Jid> targets = axolotlService.getCryptoTargets(conversation);
|
|
|
|
boolean hasUnaccepted = !conversation.getAcceptedCryptoTargets().containsAll(targets);
|
2022-08-08 19:08:28 +00:00
|
|
|
boolean hasUndecidedOwn =
|
|
|
|
!axolotlService
|
|
|
|
.getKeysWithTrust(FingerprintStatus.createActiveUndecided())
|
|
|
|
.isEmpty();
|
|
|
|
boolean hasUndecidedContacts =
|
|
|
|
!axolotlService
|
|
|
|
.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets)
|
|
|
|
.isEmpty();
|
2018-09-11 07:56:29 +00:00
|
|
|
boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(conversation).isEmpty();
|
|
|
|
boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
|
|
|
|
boolean downloadInProgress = axolotlService.hasPendingKeyFetches(targets);
|
2022-08-08 19:08:28 +00:00
|
|
|
if (hasUndecidedOwn
|
|
|
|
|| hasUndecidedContacts
|
|
|
|
|| hasPendingKeys
|
|
|
|
|| hasNoTrustedKeys
|
|
|
|
|| hasUnaccepted
|
|
|
|
|| downloadInProgress) {
|
2018-09-11 07:56:29 +00:00
|
|
|
axolotlService.createSessionsIfNeeded(conversation);
|
|
|
|
Intent intent = new Intent(getActivity(), TrustKeysActivity.class);
|
|
|
|
String[] contacts = new String[targets.size()];
|
|
|
|
for (int i = 0; i < contacts.length; ++i) {
|
|
|
|
contacts[i] = targets.get(i).toString();
|
|
|
|
}
|
|
|
|
intent.putExtra("contacts", contacts);
|
2022-08-08 19:08:28 +00:00
|
|
|
intent.putExtra(
|
|
|
|
EXTRA_ACCOUNT,
|
|
|
|
conversation.getAccount().getJid().asBareJid().toEscapedString());
|
2018-09-11 07:56:29 +00:00
|
|
|
intent.putExtra("conversation", conversation.getUuid());
|
|
|
|
startActivityForResult(intent, requestCode);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateChatMsgHint() {
|
|
|
|
final boolean multi = conversation.getMode() == Conversation.MODE_MULTI;
|
|
|
|
if (conversation.getCorrectingMessage() != null) {
|
2019-04-26 08:23:26 +00:00
|
|
|
this.binding.textInputHint.setVisibility(View.GONE);
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.setHint(R.string.send_corrected_message);
|
|
|
|
} else if (multi && conversation.getNextCounterpart() != null) {
|
2019-04-26 08:23:26 +00:00
|
|
|
this.binding.textinput.setHint(R.string.send_unencrypted_message);
|
|
|
|
this.binding.textInputHint.setVisibility(View.VISIBLE);
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.textInputHint.setText(
|
|
|
|
getString(
|
|
|
|
R.string.send_private_message_to,
|
|
|
|
conversation.getNextCounterpart().getResource()));
|
2018-09-11 07:56:29 +00:00
|
|
|
} else if (multi && !conversation.getMucOptions().participating()) {
|
2019-04-26 08:23:26 +00:00
|
|
|
this.binding.textInputHint.setVisibility(View.GONE);
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.setHint(R.string.you_are_not_participating);
|
|
|
|
} else {
|
2019-04-26 08:23:26 +00:00
|
|
|
this.binding.textInputHint.setVisibility(View.GONE);
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.setHint(UIHelper.getMessageHint(getActivity(), conversation));
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setupIme() {
|
|
|
|
this.binding.textinput.refreshIme();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleActivityResult(ActivityResult activityResult) {
|
|
|
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
|
|
|
handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
|
|
|
|
} else {
|
|
|
|
handleNegativeActivityResult(activityResult.requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_TRUST_KEYS_TEXT:
|
2018-10-03 21:23:44 +00:00
|
|
|
sendMessage();
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
2018-09-16 13:58:05 +00:00
|
|
|
case REQUEST_TRUST_KEYS_ATTACHMENTS:
|
|
|
|
commitAttachments();
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
2021-05-04 15:52:17 +00:00
|
|
|
case REQUEST_START_AUDIO_CALL:
|
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
|
|
|
break;
|
|
|
|
case REQUEST_START_VIDEO_CALL:
|
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
|
2022-08-08 19:08:28 +00:00
|
|
|
final List<Attachment> imageUris =
|
|
|
|
Attachment.extractAttachments(getActivity(), data, Attachment.Type.IMAGE);
|
2018-09-11 07:56:29 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(imageUris);
|
|
|
|
toggleInputMethod();
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_TAKE_PHOTO:
|
|
|
|
final Uri takePhotoUri = pendingTakePhotoUri.pop();
|
|
|
|
if (takePhotoUri != null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), takePhotoUri, Attachment.Type.IMAGE));
|
2018-09-11 07:56:29 +00:00
|
|
|
toggleInputMethod();
|
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG, "lost take photo uri. unable to to attach");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_FILE:
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
2022-08-08 19:08:28 +00:00
|
|
|
final Attachment.Type type =
|
|
|
|
requestCode == ATTACHMENT_CHOICE_RECORD_VOICE
|
|
|
|
? Attachment.Type.RECORDING
|
|
|
|
: Attachment.Type.FILE;
|
|
|
|
final List<Attachment> fileUris =
|
|
|
|
Attachment.extractAttachments(getActivity(), data, type);
|
2018-09-11 07:56:29 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(fileUris);
|
|
|
|
toggleInputMethod();
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_LOCATION:
|
2021-11-18 10:24:10 +00:00
|
|
|
final double latitude = data.getDoubleExtra("latitude", 0);
|
|
|
|
final double longitude = data.getDoubleExtra("longitude", 0);
|
|
|
|
final int accuracy = data.getIntExtra("accuracy", 0);
|
|
|
|
final Uri geo;
|
|
|
|
if (accuracy > 0) {
|
|
|
|
geo = Uri.parse(String.format("geo:%s,%s;u=%s", latitude, longitude, accuracy));
|
|
|
|
} else {
|
|
|
|
geo = Uri.parse(String.format("geo:%s,%s", latitude, longitude));
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), geo, Attachment.Type.LOCATION));
|
2018-09-12 12:37:41 +00:00
|
|
|
toggleInputMethod();
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case REQUEST_INVITE_TO_CONVERSATION:
|
|
|
|
XmppActivity.ConferenceInvite invite = XmppActivity.ConferenceInvite.parse(data);
|
|
|
|
if (invite != null) {
|
|
|
|
if (invite.execute(activity)) {
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.mToast =
|
|
|
|
Toast.makeText(
|
|
|
|
activity, R.string.creating_conference, Toast.LENGTH_LONG);
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.mToast.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void commitAttachments() {
|
2020-05-16 15:51:14 +00:00
|
|
|
final List<Attachment> attachments = mediaPreviewAdapter.getAttachments();
|
2022-08-08 19:08:28 +00:00
|
|
|
if (anyNeedsExternalStoragePermission(attachments)
|
|
|
|
&& !hasPermissions(
|
|
|
|
REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
2018-10-24 18:00:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-04 15:52:17 +00:00
|
|
|
if (trustKeysIfNeeded(conversation, REQUEST_TRUST_KEYS_ATTACHMENTS)) {
|
2018-09-16 13:58:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final PresenceSelector.OnPresenceSelected callback =
|
|
|
|
() -> {
|
|
|
|
for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) {
|
|
|
|
final Attachment attachment = i.next();
|
|
|
|
if (attachment.getType() == Attachment.Type.LOCATION) {
|
|
|
|
attachLocationToConversation(conversation, attachment.getUri());
|
|
|
|
} else if (attachment.getType() == Attachment.Type.IMAGE) {
|
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE");
|
|
|
|
attachImageToConversation(
|
|
|
|
conversation, attachment.getUri(), attachment.getMime());
|
|
|
|
} else {
|
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"ConversationsActivity.commitAttachments() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
|
|
|
|
attachFileToConversation(
|
|
|
|
conversation, attachment.getUri(), attachment.getMime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mediaPreviewAdapter.notifyDataSetChanged();
|
|
|
|
toggleInputMethod();
|
|
|
|
};
|
2019-04-27 12:41:43 +00:00
|
|
|
if (conversation == null
|
|
|
|
|| conversation.getMode() == Conversation.MODE_MULTI
|
|
|
|
|| Attachment.canBeSendInband(attachments)
|
2022-08-08 19:08:28 +00:00
|
|
|
|| (conversation.getAccount().httpUploadAvailable()
|
|
|
|
&& FileBackend.allFilesUnderSize(
|
|
|
|
getActivity(), attachments, getMaxHttpUploadSize(conversation)))) {
|
2018-09-11 07:56:29 +00:00
|
|
|
callback.onPresenceSelected();
|
|
|
|
} else {
|
|
|
|
activity.selectPresence(conversation, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
private static boolean anyNeedsExternalStoragePermission(
|
|
|
|
final Collection<Attachment> attachments) {
|
2020-06-21 14:28:57 +00:00
|
|
|
for (final Attachment attachment : attachments) {
|
2020-05-16 15:51:14 +00:00
|
|
|
if (attachment.getType() != Attachment.Type.LOCATION) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
public void toggleInputMethod() {
|
|
|
|
boolean hasAttachments = mediaPreviewAdapter.hasAttachments();
|
|
|
|
binding.textinput.setVisibility(hasAttachments ? View.GONE : View.VISIBLE);
|
|
|
|
binding.mediaPreview.setVisibility(hasAttachments ? View.VISIBLE : View.GONE);
|
|
|
|
updateSendButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleNegativeActivityResult(int requestCode) {
|
|
|
|
switch (requestCode) {
|
2018-09-16 08:09:22 +00:00
|
|
|
case ATTACHMENT_CHOICE_TAKE_PHOTO:
|
|
|
|
if (pendingTakePhotoUri.clear()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"cleared pending photo uri after negative activity result");
|
2018-09-16 08:09:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
|
|
|
|
if (activity != null && activity.xmppConnectionService != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
} else {
|
|
|
|
this.postponedActivityResult.push(activityResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unblockConversation(final Blockable conversation) {
|
|
|
|
activity.xmppConnectionService.sendUnblockRequest(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.onAttach()");
|
|
|
|
if (activity instanceof ConversationsActivity) {
|
|
|
|
this.activity = (ConversationsActivity) activity;
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"Trying to attach fragment to activity that is not the ConversationsActivity");
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
super.onDetach();
|
2022-08-08 19:08:28 +00:00
|
|
|
this.activity = null; // TODO maybe not a good idea since some callbacks really need it
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
|
|
|
|
menuInflater.inflate(R.menu.fragment_conversation, menu);
|
|
|
|
final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
|
|
|
|
final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
|
|
|
|
final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
|
|
|
|
final MenuItem menuMute = menu.findItem(R.id.action_mute);
|
|
|
|
final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
|
2020-04-03 14:44:29 +00:00
|
|
|
final MenuItem menuCall = menu.findItem(R.id.action_call);
|
2020-04-27 09:53:31 +00:00
|
|
|
final MenuItem menuOngoingCall = menu.findItem(R.id.action_ongoing_call);
|
2020-04-15 14:54:54 +00:00
|
|
|
final MenuItem menuVideoCall = menu.findItem(R.id.action_video_call);
|
2020-05-16 10:10:26 +00:00
|
|
|
final MenuItem menuTogglePinned = menu.findItem(R.id.action_toggle_pinned);
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
menuContactDetails.setVisible(false);
|
|
|
|
menuInviteContact.setVisible(conversation.getMucOptions().canInvite());
|
2022-08-08 19:08:28 +00:00
|
|
|
menuMucDetails.setTitle(
|
|
|
|
conversation.getMucOptions().isPrivateAndNonAnonymous()
|
|
|
|
? R.string.action_muc_details
|
|
|
|
: R.string.channel_details);
|
2020-04-03 14:44:29 +00:00
|
|
|
menuCall.setVisible(false);
|
2020-04-27 09:53:31 +00:00
|
|
|
menuOngoingCall.setVisible(false);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
final XmppConnectionService service =
|
|
|
|
activity == null ? null : activity.xmppConnectionService;
|
|
|
|
final Optional<OngoingRtpSession> ongoingRtpSession =
|
|
|
|
service == null
|
|
|
|
? Optional.absent()
|
|
|
|
: service.getJingleConnectionManager()
|
|
|
|
.getOngoingRtpConnection(conversation.getContact());
|
2020-04-27 09:53:31 +00:00
|
|
|
if (ongoingRtpSession.isPresent()) {
|
|
|
|
menuOngoingCall.setVisible(true);
|
|
|
|
menuCall.setVisible(false);
|
|
|
|
} else {
|
|
|
|
menuOngoingCall.setVisible(false);
|
2022-08-08 19:08:28 +00:00
|
|
|
final RtpCapability.Capability rtpCapability =
|
|
|
|
RtpCapability.check(conversation.getContact());
|
|
|
|
final boolean cameraAvailable =
|
|
|
|
activity != null && activity.isCameraFeatureAvailable();
|
2020-04-27 09:53:31 +00:00
|
|
|
menuCall.setVisible(rtpCapability != RtpCapability.Capability.NONE);
|
2022-08-08 19:08:28 +00:00
|
|
|
menuVideoCall.setVisible(
|
|
|
|
rtpCapability == RtpCapability.Capability.VIDEO && cameraAvailable);
|
2020-04-27 09:53:31 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
menuContactDetails.setVisible(!this.conversation.withSelf());
|
|
|
|
menuMucDetails.setVisible(false);
|
2022-08-08 19:08:28 +00:00
|
|
|
menuInviteContact.setVisible(
|
|
|
|
service != null
|
|
|
|
&& service.findConferenceServer(conversation.getAccount()) != null);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
if (conversation.isMuted()) {
|
|
|
|
menuMute.setVisible(false);
|
|
|
|
} else {
|
|
|
|
menuUnmute.setVisible(false);
|
|
|
|
}
|
|
|
|
ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu);
|
|
|
|
ConversationMenuConfigurator.configureEncryptionMenu(conversation, menu);
|
2020-05-16 10:10:26 +00:00
|
|
|
if (conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false)) {
|
|
|
|
menuTogglePinned.setTitle(R.string.remove_from_favorites);
|
|
|
|
} else {
|
|
|
|
menuTogglePinned.setTitle(R.string.add_to_favorites);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
super.onCreateOptionsMenu(menu, menuInflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-08-08 19:08:28 +00:00
|
|
|
public View onCreateView(
|
|
|
|
final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
this.binding =
|
|
|
|
DataBindingUtil.inflate(inflater, R.layout.fragment_conversation, container, false);
|
|
|
|
binding.getRoot().setOnClickListener(null); // TODO why the fuck did we do this?
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
binding.textinput.addTextChangedListener(
|
|
|
|
new StylingHelper.MessageEditorStyler(binding.textinput));
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
binding.textinput.setOnEditorActionListener(mEditorActionListener);
|
2022-08-08 19:08:28 +00:00
|
|
|
binding.textinput.setRichContentListener(new String[] {"image/*"}, mEditorContentListener);
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
binding.textSendButton.setOnClickListener(this.mSendButtonListener);
|
|
|
|
|
|
|
|
binding.scrollToBottomButton.setOnClickListener(this.mScrollButtonListener);
|
|
|
|
binding.messagesView.setOnScrollListener(mOnScrollListener);
|
|
|
|
binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
|
|
|
mediaPreviewAdapter = new MediaPreviewAdapter(this);
|
|
|
|
binding.mediaPreview.setAdapter(mediaPreviewAdapter);
|
|
|
|
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
|
2018-12-04 11:23:14 +00:00
|
|
|
messageListAdapter.setOnContactPictureClicked(this);
|
|
|
|
messageListAdapter.setOnContactPictureLongClicked(this);
|
2018-09-11 07:56:29 +00:00
|
|
|
binding.messagesView.setAdapter(messageListAdapter);
|
|
|
|
|
|
|
|
registerForContextMenu(binding.messagesView);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.textinput.setCustomInsertionActionModeCallback(
|
|
|
|
new EditMessageActionModeCallback(this.binding.textinput));
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return binding.getRoot();
|
|
|
|
}
|
2020-11-13 11:50:05 +00:00
|
|
|
|
2020-10-04 14:02:55 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
super.onDestroyView();
|
2020-11-13 11:50:05 +00:00
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.onDestroyView()");
|
2020-10-04 14:02:55 +00:00
|
|
|
messageListAdapter.setOnContactPictureClicked(null);
|
|
|
|
messageListAdapter.setOnContactPictureLongClicked(null);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
private void quoteText(String text) {
|
|
|
|
if (binding.textinput.isEnabled()) {
|
|
|
|
binding.textinput.insertAsQuote(text);
|
|
|
|
binding.textinput.requestFocus();
|
2022-08-08 19:08:28 +00:00
|
|
|
InputMethodManager inputMethodManager =
|
|
|
|
(InputMethodManager)
|
|
|
|
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (inputMethodManager != null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
inputMethodManager.showSoftInput(
|
|
|
|
binding.textinput, InputMethodManager.SHOW_IMPLICIT);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void quoteMessage(Message message) {
|
|
|
|
quoteText(MessageUtils.prepareQuote(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
2022-08-08 19:08:28 +00:00
|
|
|
// This should cancel any remaining click events that would otherwise trigger links
|
2020-12-08 06:10:54 +00:00
|
|
|
v.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0f, 0f, 0));
|
2018-09-11 07:56:29 +00:00
|
|
|
synchronized (this.messageList) {
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
|
|
|
this.selectedMessage = this.messageList.get(acmi.position);
|
|
|
|
populateContextMenu(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void populateContextMenu(ContextMenu menu) {
|
|
|
|
final Message m = this.selectedMessage;
|
|
|
|
final Transferable t = m.getTransferable();
|
|
|
|
Message relevantForCorrection = m;
|
|
|
|
while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
|
|
|
|
relevantForCorrection = relevantForCorrection.next();
|
|
|
|
}
|
2020-04-12 17:18:40 +00:00
|
|
|
if (m.getType() != Message.TYPE_STATUS && m.getType() != Message.TYPE_RTP_SESSION) {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
if (m.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE
|
|
|
|
|| m.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
if (m.getStatus() == Message.STATUS_RECEIVED
|
|
|
|
&& t != null
|
|
|
|
&& (t.getStatus() == Transferable.STATUS_CANCELLED
|
|
|
|
|| t.getStatus() == Transferable.STATUS_FAILED)) {
|
2019-10-05 20:05:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:52:27 +00:00
|
|
|
final boolean deleted = m.isDeleted();
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean encrypted =
|
|
|
|
m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED
|
|
|
|
|| m.getEncryption() == Message.ENCRYPTION_PGP;
|
|
|
|
final boolean receiving =
|
|
|
|
m.getStatus() == Message.STATUS_RECEIVED
|
|
|
|
&& (t instanceof JingleFileTransferConnection
|
|
|
|
|| t instanceof HttpDownloadConnection);
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.getMenuInflater().inflate(R.menu.message_context, menu);
|
|
|
|
menu.setHeaderTitle(R.string.message_options);
|
2019-01-11 09:13:25 +00:00
|
|
|
MenuItem openWith = menu.findItem(R.id.open_with);
|
2018-09-11 07:56:29 +00:00
|
|
|
MenuItem copyMessage = menu.findItem(R.id.copy_message);
|
|
|
|
MenuItem copyLink = menu.findItem(R.id.copy_link);
|
|
|
|
MenuItem quoteMessage = menu.findItem(R.id.quote_message);
|
|
|
|
MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
|
|
|
|
MenuItem correctMessage = menu.findItem(R.id.correct_message);
|
|
|
|
MenuItem shareWith = menu.findItem(R.id.share_with);
|
|
|
|
MenuItem sendAgain = menu.findItem(R.id.send_again);
|
|
|
|
MenuItem copyUrl = menu.findItem(R.id.copy_url);
|
|
|
|
MenuItem downloadFile = menu.findItem(R.id.download_file);
|
|
|
|
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
|
|
|
|
MenuItem deleteFile = menu.findItem(R.id.delete_file);
|
|
|
|
MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
|
2021-01-21 17:35:12 +00:00
|
|
|
final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(m);
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean showError =
|
|
|
|
m.getStatus() == Message.STATUS_SEND_FAILED
|
|
|
|
&& m.getErrorMessage() != null
|
|
|
|
&& !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
|
|
|
|
if (!m.isFileOrImage()
|
|
|
|
&& !encrypted
|
|
|
|
&& !m.isGeoUri()
|
|
|
|
&& !m.treatAsDownloadable()
|
|
|
|
&& !unInitiatedButKnownSize
|
|
|
|
&& t == null) {
|
2018-09-11 07:56:29 +00:00
|
|
|
copyMessage.setVisible(true);
|
2018-11-18 10:45:24 +00:00
|
|
|
quoteMessage.setVisible(!showError && MessageUtils.prepareQuote(m).length() > 0);
|
2022-10-12 16:43:05 +00:00
|
|
|
final String scheme = ShareUtil.getLinkScheme(m.getMergedBody());
|
|
|
|
if ("xmpp".equals(scheme)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
copyLink.setTitle(R.string.copy_jabber_id);
|
|
|
|
copyLink.setVisible(true);
|
2022-10-12 16:43:05 +00:00
|
|
|
} else if (scheme != null) {
|
2018-09-11 07:56:29 +00:00
|
|
|
copyLink.setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 20:24:24 +00:00
|
|
|
if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
|
2018-09-11 07:56:29 +00:00
|
|
|
retryDecryption.setVisible(true);
|
|
|
|
}
|
2018-11-18 10:45:24 +00:00
|
|
|
if (!showError
|
|
|
|
&& relevantForCorrection.getType() == Message.TYPE_TEXT
|
2019-01-11 09:13:25 +00:00
|
|
|
&& !m.isGeoUri()
|
2018-09-11 07:56:29 +00:00
|
|
|
&& relevantForCorrection.isLastCorrectableMessage()
|
2019-02-07 17:11:07 +00:00
|
|
|
&& m.getConversation() instanceof Conversation) {
|
2018-09-11 07:56:29 +00:00
|
|
|
correctMessage.setVisible(true);
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
if ((m.isFileOrImage() && !deleted && !receiving)
|
|
|
|
|| (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())
|
|
|
|
&& !unInitiatedButKnownSize
|
|
|
|
&& t == null) {
|
2018-09-11 07:56:29 +00:00
|
|
|
shareWith.setVisible(true);
|
|
|
|
}
|
|
|
|
if (m.getStatus() == Message.STATUS_SEND_FAILED) {
|
|
|
|
sendAgain.setVisible(true);
|
|
|
|
}
|
|
|
|
if (m.hasFileOnRemoteHost()
|
|
|
|
|| m.isGeoUri()
|
|
|
|
|| m.treatAsDownloadable()
|
2021-01-21 17:35:12 +00:00
|
|
|
|| unInitiatedButKnownSize
|
2018-10-08 08:31:41 +00:00
|
|
|
|| t instanceof HttpDownloadConnection) {
|
2018-09-11 07:56:29 +00:00
|
|
|
copyUrl.setVisible(true);
|
|
|
|
}
|
|
|
|
if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) {
|
|
|
|
downloadFile.setVisible(true);
|
2022-08-08 19:08:28 +00:00
|
|
|
downloadFile.setTitle(
|
|
|
|
activity.getString(
|
|
|
|
R.string.download_x_file,
|
|
|
|
UIHelper.getFileDescriptionString(activity, m)));
|
|
|
|
}
|
|
|
|
final boolean waitingOfferedSending =
|
|
|
|
m.getStatus() == Message.STATUS_WAITING
|
|
|
|
|| m.getStatus() == Message.STATUS_UNSEND
|
|
|
|
|| m.getStatus() == Message.STATUS_OFFERED;
|
|
|
|
final boolean cancelable =
|
|
|
|
(t != null && !deleted) || waitingOfferedSending && m.needsUploading();
|
2018-10-11 02:33:12 +00:00
|
|
|
if (cancelable) {
|
2018-09-11 07:56:29 +00:00
|
|
|
cancelTransmission.setVisible(true);
|
|
|
|
}
|
2018-10-11 02:33:12 +00:00
|
|
|
if (m.isFileOrImage() && !deleted && !cancelable) {
|
2022-03-10 14:54:23 +00:00
|
|
|
final String path = m.getRelativeFilePath();
|
2022-08-08 19:08:28 +00:00
|
|
|
if (path == null
|
|
|
|
|| !path.startsWith("/")
|
|
|
|
|| FileBackend.inConversationsDirectory(requireActivity(), path)) {
|
2022-03-10 14:54:23 +00:00
|
|
|
deleteFile.setVisible(true);
|
2022-08-08 19:08:28 +00:00
|
|
|
deleteFile.setTitle(
|
|
|
|
activity.getString(
|
|
|
|
R.string.delete_x_file,
|
|
|
|
UIHelper.getFileDescriptionString(activity, m)));
|
2022-03-10 14:54:23 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2018-11-18 10:45:24 +00:00
|
|
|
if (showError) {
|
2018-09-11 07:56:29 +00:00
|
|
|
showErrorMessage.setVisible(true);
|
|
|
|
}
|
2019-01-12 09:29:41 +00:00
|
|
|
final String mime = m.isFileOrImage() ? m.getMimeType() : null;
|
2022-08-08 19:08:28 +00:00
|
|
|
if ((m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(), m))
|
|
|
|
|| (mime != null && mime.startsWith("audio/"))) {
|
2019-01-11 09:13:25 +00:00
|
|
|
openWith.setVisible(true);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.share_with:
|
|
|
|
ShareUtil.share(activity, selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.correct_message:
|
|
|
|
correctMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_message:
|
|
|
|
ShareUtil.copyToClipboard(activity, selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_link:
|
|
|
|
ShareUtil.copyLinkToClipboard(activity, selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.quote_message:
|
|
|
|
quoteMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.send_again:
|
|
|
|
resendMessage(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.copy_url:
|
|
|
|
ShareUtil.copyUrlToClipboard(activity, selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.download_file:
|
|
|
|
startDownloadable(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.cancel_transmission:
|
|
|
|
cancelTransmission(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.retry_decryption:
|
|
|
|
retryDecryption(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.delete_file:
|
|
|
|
deleteFile(selectedMessage);
|
|
|
|
return true;
|
|
|
|
case R.id.show_error_message:
|
|
|
|
showErrorMessage(selectedMessage);
|
|
|
|
return true;
|
2019-01-11 09:13:25 +00:00
|
|
|
case R.id.open_with:
|
|
|
|
openWith(selectedMessage);
|
|
|
|
return true;
|
2018-09-11 07:56:29 +00:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
|
|
|
if (MenuDoubleTabUtil.shouldIgnoreTap()) {
|
|
|
|
return false;
|
|
|
|
} else if (conversation == null) {
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.encryption_choice_axolotl:
|
|
|
|
case R.id.encryption_choice_pgp:
|
|
|
|
case R.id.encryption_choice_none:
|
|
|
|
handleEncryptionSelection(item);
|
|
|
|
break;
|
|
|
|
case R.id.attach_choose_picture:
|
|
|
|
case R.id.attach_take_picture:
|
|
|
|
case R.id.attach_record_video:
|
|
|
|
case R.id.attach_choose_file:
|
|
|
|
case R.id.attach_record_voice:
|
|
|
|
case R.id.attach_location:
|
|
|
|
handleAttachmentSelection(item);
|
|
|
|
break;
|
2020-08-29 06:16:08 +00:00
|
|
|
case R.id.action_search:
|
|
|
|
startSearch();
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
case R.id.action_archive:
|
|
|
|
activity.xmppConnectionService.archiveConversation(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_contact_details:
|
|
|
|
activity.switchToContactDetails(conversation.getContact());
|
|
|
|
break;
|
|
|
|
case R.id.action_muc_details:
|
2021-08-25 18:04:47 +00:00
|
|
|
ConferenceDetailsActivity.open(getActivity(), conversation);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_invite:
|
2022-08-08 19:08:28 +00:00
|
|
|
startActivityForResult(
|
|
|
|
ChooseContactActivity.create(activity, conversation),
|
|
|
|
REQUEST_INVITE_TO_CONVERSATION);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_clear_history:
|
|
|
|
clearHistoryDialog(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_mute:
|
|
|
|
muteConversationDialog(conversation);
|
|
|
|
break;
|
|
|
|
case R.id.action_unmute:
|
2022-08-08 19:08:28 +00:00
|
|
|
unMuteConversation(conversation);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_block:
|
|
|
|
case R.id.action_unblock:
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity instanceof XmppActivity) {
|
|
|
|
BlockContactDialog.show((XmppActivity) activity, conversation);
|
|
|
|
}
|
|
|
|
break;
|
2020-04-15 14:26:53 +00:00
|
|
|
case R.id.action_audio_call:
|
|
|
|
checkPermissionAndTriggerAudioCall();
|
|
|
|
break;
|
|
|
|
case R.id.action_video_call:
|
|
|
|
checkPermissionAndTriggerVideoCall();
|
2020-04-04 09:31:53 +00:00
|
|
|
break;
|
2020-04-27 09:53:31 +00:00
|
|
|
case R.id.action_ongoing_call:
|
|
|
|
returnToOngoingCall();
|
|
|
|
break;
|
2020-05-16 10:10:26 +00:00
|
|
|
case R.id.action_toggle_pinned:
|
|
|
|
togglePinned();
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2020-08-29 06:16:08 +00:00
|
|
|
private void startSearch() {
|
|
|
|
final Intent intent = new Intent(getActivity(), SearchActivity.class);
|
|
|
|
intent.putExtra(SearchActivity.EXTRA_CONVERSATION_UUID, conversation.getUuid());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2020-04-27 09:53:31 +00:00
|
|
|
private void returnToOngoingCall() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final Optional<OngoingRtpSession> ongoingRtpSession =
|
|
|
|
activity.xmppConnectionService
|
|
|
|
.getJingleConnectionManager()
|
|
|
|
.getOngoingRtpConnection(conversation.getContact());
|
2020-04-27 09:53:31 +00:00
|
|
|
if (ongoingRtpSession.isPresent()) {
|
2020-05-02 07:50:17 +00:00
|
|
|
final OngoingRtpSession id = ongoingRtpSession.get();
|
2020-04-27 09:53:31 +00:00
|
|
|
final Intent intent = new Intent(getActivity(), RtpSessionActivity.class);
|
2022-08-08 19:08:28 +00:00
|
|
|
intent.putExtra(
|
|
|
|
RtpSessionActivity.EXTRA_ACCOUNT,
|
|
|
|
id.getAccount().getJid().asBareJid().toEscapedString());
|
2020-05-02 07:50:17 +00:00
|
|
|
intent.putExtra(RtpSessionActivity.EXTRA_WITH, id.getWith().toEscapedString());
|
|
|
|
if (id instanceof AbstractJingleConnection.Id) {
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra(RtpSessionActivity.EXTRA_SESSION_ID, id.getSessionId());
|
|
|
|
} else if (id instanceof JingleConnectionManager.RtpSessionProposal) {
|
|
|
|
if (((JingleConnectionManager.RtpSessionProposal) id).media.contains(Media.VIDEO)) {
|
|
|
|
intent.setAction(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
|
|
|
} else {
|
|
|
|
intent.setAction(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 09:53:31 +00:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 10:10:26 +00:00
|
|
|
private void togglePinned() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean pinned =
|
|
|
|
conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false);
|
2020-05-16 10:10:26 +00:00
|
|
|
conversation.setAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, !pinned);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
2020-05-19 17:38:36 +00:00
|
|
|
activity.invalidateOptionsMenu();
|
2020-05-16 10:10:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 14:26:53 +00:00
|
|
|
private void checkPermissionAndTriggerAudioCall() {
|
2020-04-19 06:04:36 +00:00
|
|
|
if (activity.mUseTor || conversation.getAccount().isOnion()) {
|
2020-04-10 14:28:15 +00:00
|
|
|
Toast.makeText(activity, R.string.disable_tor_to_make_call, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final List<String> permissions;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
|
|
permissions =
|
|
|
|
Arrays.asList(
|
|
|
|
Manifest.permission.RECORD_AUDIO,
|
|
|
|
Manifest.permission.BLUETOOTH_CONNECT);
|
|
|
|
} else {
|
|
|
|
permissions = Collections.singletonList(Manifest.permission.RECORD_AUDIO);
|
|
|
|
}
|
|
|
|
if (hasPermissions(REQUEST_START_AUDIO_CALL, permissions)) {
|
2020-04-15 14:26:53 +00:00
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
2020-04-09 17:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:26:53 +00:00
|
|
|
private void checkPermissionAndTriggerVideoCall() {
|
2020-04-19 06:04:36 +00:00
|
|
|
if (activity.mUseTor || conversation.getAccount().isOnion()) {
|
2020-04-15 14:26:53 +00:00
|
|
|
Toast.makeText(activity, R.string.disable_tor_to_make_call, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final List<String> permissions;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
|
|
permissions =
|
|
|
|
Arrays.asList(
|
|
|
|
Manifest.permission.RECORD_AUDIO,
|
|
|
|
Manifest.permission.CAMERA,
|
|
|
|
Manifest.permission.BLUETOOTH_CONNECT);
|
|
|
|
} else {
|
|
|
|
permissions =
|
|
|
|
Arrays.asList(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA);
|
|
|
|
}
|
|
|
|
if (hasPermissions(REQUEST_START_VIDEO_CALL, permissions)) {
|
2020-04-15 14:26:53 +00:00
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 14:28:15 +00:00
|
|
|
|
2020-04-15 14:26:53 +00:00
|
|
|
private void triggerRtpSession(final String action) {
|
2020-04-19 08:12:33 +00:00
|
|
|
if (activity.xmppConnectionService.getJingleConnectionManager().isBusy()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.only_one_call_at_a_time, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
2020-04-19 08:12:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-19 06:49:08 +00:00
|
|
|
final Contact contact = conversation.getContact();
|
2020-05-30 12:56:12 +00:00
|
|
|
if (contact.getPresences().anySupport(Namespace.JINGLE_MESSAGE)) {
|
2020-06-21 14:28:57 +00:00
|
|
|
triggerRtpSession(contact.getAccount(), contact.getJid().asBareJid(), action);
|
2020-05-30 12:56:12 +00:00
|
|
|
} else {
|
|
|
|
final RtpCapability.Capability capability;
|
|
|
|
if (action.equals(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL)) {
|
|
|
|
capability = RtpCapability.Capability.VIDEO;
|
|
|
|
} else {
|
|
|
|
capability = RtpCapability.Capability.AUDIO;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
PresenceSelector.selectFullJidForDirectRtpConnection(
|
|
|
|
activity,
|
|
|
|
contact,
|
|
|
|
capability,
|
|
|
|
fullJid -> {
|
|
|
|
triggerRtpSession(contact.getAccount(), fullJid, action);
|
|
|
|
});
|
2020-05-30 12:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void triggerRtpSession(final Account account, final Jid with, final String action) {
|
2020-04-19 06:49:08 +00:00
|
|
|
final Intent intent = new Intent(activity, RtpSessionActivity.class);
|
|
|
|
intent.setAction(action);
|
2020-05-30 12:56:12 +00:00
|
|
|
intent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, account.getJid().toEscapedString());
|
|
|
|
intent.putExtra(RtpSessionActivity.EXTRA_WITH, with.toEscapedString());
|
2020-04-19 08:12:33 +00:00
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
2020-04-19 06:49:08 +00:00
|
|
|
startActivity(intent);
|
2020-04-04 09:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
private void handleAttachmentSelection(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.attach_choose_picture:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_take_picture:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
|
|
|
|
break;
|
|
|
|
case R.id.attach_record_video:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_RECORD_VIDEO);
|
|
|
|
break;
|
|
|
|
case R.id.attach_choose_file:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_record_voice:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
|
|
|
|
break;
|
|
|
|
case R.id.attach_location:
|
|
|
|
attachFile(ATTACHMENT_CHOICE_LOCATION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEncryptionSelection(MenuItem item) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-07 12:18:42 +00:00
|
|
|
final boolean updated;
|
2018-09-11 07:56:29 +00:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.encryption_choice_none:
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
2018-09-11 07:56:29 +00:00
|
|
|
item.setChecked(true);
|
|
|
|
break;
|
|
|
|
case R.id.encryption_choice_pgp:
|
|
|
|
if (activity.hasPgp()) {
|
|
|
|
if (conversation.getAccount().getPgpSignature() != null) {
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
2018-09-11 07:56:29 +00:00
|
|
|
item.setChecked(true);
|
|
|
|
} else {
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = false;
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.announcePgp(
|
|
|
|
conversation.getAccount(),
|
|
|
|
conversation,
|
|
|
|
null,
|
|
|
|
activity.onOpenPGPKeyPublished);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = false;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.encryption_choice_axolotl:
|
2022-08-08 19:08:28 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
AxolotlService.getLogprefix(conversation.getAccount())
|
|
|
|
+ "Enabled axolotl for Contact "
|
|
|
|
+ conversation.getContact().getJid());
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
|
2018-09-11 07:56:29 +00:00
|
|
|
item.setChecked(true);
|
|
|
|
break;
|
|
|
|
default:
|
2019-02-07 12:18:42 +00:00
|
|
|
updated = conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-07 12:18:42 +00:00
|
|
|
if (updated) {
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
updateChatMsgHint();
|
|
|
|
getActivity().invalidateOptionsMenu();
|
|
|
|
activity.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attachFile(final int attachmentChoice) {
|
2020-06-21 14:28:57 +00:00
|
|
|
attachFile(attachmentChoice, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attachFile(final int attachmentChoice, final boolean updateRecentlyUsed) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (!hasPermissions(
|
|
|
|
attachmentChoice,
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
Manifest.permission.RECORD_AUDIO)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
} else if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO
|
|
|
|
|| attachmentChoice == ATTACHMENT_CHOICE_RECORD_VIDEO) {
|
|
|
|
if (!hasPermissions(
|
|
|
|
attachmentChoice,
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
Manifest.permission.CAMERA)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
|
|
|
|
if (!hasPermissions(attachmentChoice, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 14:28:57 +00:00
|
|
|
if (updateRecentlyUsed) {
|
|
|
|
storeRecentlyUsedQuickAction(attachmentChoice);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
final int encryption = conversation.getNextEncryption();
|
|
|
|
final int mode = conversation.getMode();
|
|
|
|
if (encryption == Message.ENCRYPTION_PGP) {
|
|
|
|
if (activity.hasPgp()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (mode == Conversation.MODE_SINGLE
|
|
|
|
&& conversation.getContact().getPgpKeyId() != 0) {
|
|
|
|
activity.xmppConnectionService
|
|
|
|
.getPgpEngine()
|
|
|
|
.hasKey(
|
|
|
|
conversation.getContact(),
|
|
|
|
new UiCallback<Contact>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequired(
|
|
|
|
PendingIntent pi, Contact contact) {
|
|
|
|
startPendingIntent(pi, attachmentChoice);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void success(Contact contact) {
|
|
|
|
invokeAttachFileIntent(attachmentChoice);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void error(int error, Contact contact) {
|
|
|
|
activity.replaceToast(getString(error));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (mode == Conversation.MODE_MULTI
|
|
|
|
&& conversation.getMucOptions().pgpKeysInUse()) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast warning =
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
R.string.missing_public_keys,
|
|
|
|
Toast.LENGTH_LONG);
|
2018-09-11 07:56:29 +00:00
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
2019-04-27 12:41:43 +00:00
|
|
|
invokeAttachFileIntent(attachmentChoice);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
showNoPGPKeyDialog(
|
|
|
|
false,
|
|
|
|
(dialog, which) -> {
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
invokeAttachFileIntent(attachmentChoice);
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-27 12:41:43 +00:00
|
|
|
invokeAttachFileIntent(attachmentChoice);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 14:28:57 +00:00
|
|
|
private void storeRecentlyUsedQuickAction(final int attachmentChoice) {
|
|
|
|
try {
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.getPreferences()
|
|
|
|
.edit()
|
|
|
|
.putString(
|
|
|
|
RECENTLY_USED_QUICK_ACTION,
|
|
|
|
SendButtonAction.of(attachmentChoice).toString())
|
2020-06-21 14:28:57 +00:00
|
|
|
.apply();
|
|
|
|
} catch (IllegalArgumentException e) {
|
2022-08-08 19:08:28 +00:00
|
|
|
// just do not save
|
2020-06-21 14:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
@Override
|
2022-08-08 19:08:28 +00:00
|
|
|
public void onRequestPermissionsResult(
|
|
|
|
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
final PermissionUtils.PermissionResult permissionResult =
|
|
|
|
PermissionUtils.removeBluetoothConnect(permissions, grantResults);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (grantResults.length > 0) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (allGranted(permissionResult.grantResults)) {
|
2018-10-24 18:00:06 +00:00
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_START_DOWNLOAD:
|
|
|
|
if (this.mPendingDownloadableMessage != null) {
|
|
|
|
startDownloadable(this.mPendingDownloadableMessage);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REQUEST_ADD_EDITOR_CONTENT:
|
|
|
|
if (this.mPendingEditorContent != null) {
|
|
|
|
attachEditorContentToConversation(this.mPendingEditorContent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REQUEST_COMMIT_ATTACHMENTS:
|
|
|
|
commitAttachments();
|
|
|
|
break;
|
2020-04-09 17:45:21 +00:00
|
|
|
case REQUEST_START_AUDIO_CALL:
|
2020-04-15 14:26:53 +00:00
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
|
|
|
|
break;
|
|
|
|
case REQUEST_START_VIDEO_CALL:
|
|
|
|
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
|
2020-04-09 17:45:21 +00:00
|
|
|
break;
|
2018-10-24 18:00:06 +00:00
|
|
|
default:
|
|
|
|
attachFile(requestCode);
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
@StringRes int res;
|
2022-08-08 19:08:28 +00:00
|
|
|
String firstDenied =
|
|
|
|
getFirstDenied(permissionResult.grantResults, permissionResult.permissions);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (Manifest.permission.RECORD_AUDIO.equals(firstDenied)) {
|
|
|
|
res = R.string.no_microphone_permission;
|
|
|
|
} else if (Manifest.permission.CAMERA.equals(firstDenied)) {
|
|
|
|
res = R.string.no_camera_permission;
|
|
|
|
} else {
|
|
|
|
res = R.string.no_storage_permission;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
getString(res, getString(R.string.app_name)),
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (writeGranted(grantResults, permissions)) {
|
|
|
|
if (activity != null && activity.xmppConnectionService != null) {
|
2021-09-20 07:54:42 +00:00
|
|
|
activity.xmppConnectionService.getBitmapCache().evictAll();
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.xmppConnectionService.restartFileObserver();
|
|
|
|
}
|
2018-10-24 18:00:06 +00:00
|
|
|
refresh();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startDownloadable(Message message) {
|
|
|
|
if (!hasPermissions(REQUEST_START_DOWNLOAD, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
this.mPendingDownloadableMessage = message;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Transferable transferable = message.getTransferable();
|
|
|
|
if (transferable != null) {
|
|
|
|
if (transferable instanceof TransferablePlaceholder && message.hasFileOnRemoteHost()) {
|
|
|
|
createNewConnection(message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!transferable.start()) {
|
|
|
|
Log.d(Config.LOGTAG, "type: " + transferable.getClass().getName());
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
} else if (message.treatAsDownloadable()
|
|
|
|
|| message.hasFileOnRemoteHost()
|
|
|
|
|| MessageUtils.unInitiatedButKnownSize(message)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
createNewConnection(message);
|
2019-12-26 17:58:54 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
message.getConversation().getAccount() + ": unable to start downloadable");
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createNewConnection(final Message message) {
|
2021-03-19 13:57:15 +00:00
|
|
|
if (!activity.xmppConnectionService.hasInternetConnection()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService
|
|
|
|
.getHttpConnectionManager()
|
|
|
|
.createNewDownloadConnection(message, true);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
protected void clearHistoryDialog(final Conversation conversation) {
|
2021-09-20 07:54:42 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.setTitle(getString(R.string.clear_conversation_history));
|
2022-08-08 19:08:28 +00:00
|
|
|
final View dialogView =
|
|
|
|
requireActivity().getLayoutInflater().inflate(R.layout.dialog_clear_history, null);
|
|
|
|
final CheckBox endConversationCheckBox =
|
|
|
|
dialogView.findViewById(R.id.end_conversation_checkbox);
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.setView(dialogView);
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2022-08-08 19:08:28 +00:00
|
|
|
builder.setPositiveButton(
|
|
|
|
getString(R.string.confirm),
|
|
|
|
(dialog, which) -> {
|
|
|
|
this.activity.xmppConnectionService.clearConversationHistory(conversation);
|
|
|
|
if (endConversationCheckBox.isChecked()) {
|
|
|
|
this.activity.xmppConnectionService.archiveConversation(conversation);
|
|
|
|
this.activity.onConversationArchived(conversation);
|
|
|
|
} else {
|
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void muteConversationDialog(final Conversation conversation) {
|
2021-09-20 07:54:42 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.setTitle(R.string.disable_notifications);
|
|
|
|
final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
|
|
|
|
final CharSequence[] labels = new CharSequence[durations.length];
|
|
|
|
for (int i = 0; i < durations.length; ++i) {
|
|
|
|
if (durations[i] == -1) {
|
|
|
|
labels[i] = getString(R.string.until_further_notice);
|
|
|
|
} else {
|
2020-05-09 07:42:33 +00:00
|
|
|
labels[i] = TimeFrameUtils.resolve(activity, 1000L * durations[i]);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
builder.setItems(
|
|
|
|
labels,
|
|
|
|
(dialog, which) -> {
|
|
|
|
final long till;
|
|
|
|
if (durations[which] == -1) {
|
|
|
|
till = Long.MAX_VALUE;
|
|
|
|
} else {
|
|
|
|
till = System.currentTimeMillis() + (durations[which] * 1000L);
|
|
|
|
}
|
|
|
|
conversation.setMutedTill(till);
|
|
|
|
activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
|
|
|
requireActivity().invalidateOptionsMenu();
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
private boolean hasPermissions(int requestCode, List<String> permissions) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
final List<String> missingPermissions = new ArrayList<>();
|
|
|
|
for (String permission : permissions) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (Config.ONLY_INTERNAL_STORAGE
|
|
|
|
&& permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
missingPermissions.add(permission);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (missingPermissions.size() == 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
requestPermissions(
|
|
|
|
missingPermissions.toArray(new String[0]),
|
|
|
|
requestCode);
|
2018-09-11 07:56:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
private boolean hasPermissions(int requestCode, String... permissions) {
|
|
|
|
return hasPermissions(requestCode, ImmutableList.copyOf(permissions));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unMuteConversation(final Conversation conversation) {
|
2018-09-11 07:56:29 +00:00
|
|
|
conversation.setMutedTill(0);
|
|
|
|
this.activity.xmppConnectionService.updateConversation(conversation);
|
|
|
|
this.activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
2021-09-20 08:08:11 +00:00
|
|
|
requireActivity().invalidateOptionsMenu();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 12:41:43 +00:00
|
|
|
protected void invokeAttachFileIntent(final int attachmentChoice) {
|
|
|
|
Intent intent = new Intent();
|
|
|
|
boolean chooser = false;
|
|
|
|
switch (attachmentChoice) {
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
|
|
|
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
2021-09-20 08:08:11 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
2019-04-27 12:41:43 +00:00
|
|
|
intent.setType("image/*");
|
|
|
|
chooser = true;
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VIDEO:
|
|
|
|
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_TAKE_PHOTO:
|
|
|
|
final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
|
|
|
|
pendingTakePhotoUri.push(uri);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_CHOOSE_FILE:
|
|
|
|
chooser = true;
|
|
|
|
intent.setType("*/*");
|
2021-09-20 08:08:11 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
2019-04-27 12:41:43 +00:00
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_RECORD_VOICE:
|
|
|
|
intent = new Intent(getActivity(), RecordingActivity.class);
|
|
|
|
break;
|
|
|
|
case ATTACHMENT_CHOICE_LOCATION:
|
|
|
|
intent = GeoHelper.getFetchIntent(activity);
|
|
|
|
break;
|
|
|
|
}
|
2019-09-16 12:20:15 +00:00
|
|
|
final Context context = getActivity();
|
2020-11-13 11:50:05 +00:00
|
|
|
if (context == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-22 15:23:51 +00:00
|
|
|
try {
|
2019-04-27 12:41:43 +00:00
|
|
|
if (chooser) {
|
|
|
|
startActivityForResult(
|
|
|
|
Intent.createChooser(intent, getString(R.string.perform_action_with)),
|
|
|
|
attachmentChoice);
|
|
|
|
} else {
|
|
|
|
startActivityForResult(intent, attachmentChoice);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2022-02-22 15:23:51 +00:00
|
|
|
} catch (final ActivityNotFoundException e) {
|
2020-11-13 11:50:05 +00:00
|
|
|
Toast.makeText(context, R.string.no_application_found, Toast.LENGTH_LONG).show();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
binding.messagesView.post(this::fireReadEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fireReadEvent() {
|
|
|
|
if (activity != null && this.conversation != null) {
|
|
|
|
String uuid = getLastVisibleMessageUuid();
|
|
|
|
if (uuid != null) {
|
|
|
|
activity.onConversationRead(this.conversation, uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getLastVisibleMessageUuid() {
|
|
|
|
if (binding == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
synchronized (this.messageList) {
|
|
|
|
int pos = binding.messagesView.getLastVisiblePosition();
|
|
|
|
if (pos >= 0) {
|
|
|
|
Message message = null;
|
|
|
|
for (int i = pos; i >= 0; --i) {
|
|
|
|
try {
|
|
|
|
message = (Message) binding.messagesView.getItemAtPosition(i);
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
2022-08-08 19:08:28 +00:00
|
|
|
// should not happen if we synchronize properly. however if that fails we
|
|
|
|
// just gonna try item -1
|
2018-09-11 07:56:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (message.getType() != Message.TYPE_STATUS) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (message != null) {
|
|
|
|
while (message.next() != null && message.next().wasMergedIntoPrevious()) {
|
|
|
|
message = message.next();
|
|
|
|
}
|
|
|
|
return message.getUuid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:13:25 +00:00
|
|
|
private void openWith(final Message message) {
|
|
|
|
if (message.isGeoUri()) {
|
2020-04-04 09:31:53 +00:00
|
|
|
GeoHelper.view(getActivity(), message);
|
2019-01-12 09:29:41 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
final DownloadableFile file =
|
|
|
|
activity.xmppConnectionService.getFileBackend().getFile(message);
|
2019-01-12 09:29:41 +00:00
|
|
|
ViewUtil.view(activity, file);
|
2019-01-11 09:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
private void showErrorMessage(final Message message) {
|
2021-09-20 08:08:11 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.setTitle(R.string.error_message);
|
2019-02-20 20:44:06 +00:00
|
|
|
final String errorMessage = message.getErrorMessage();
|
2022-08-08 19:08:28 +00:00
|
|
|
final String[] errorMessageParts =
|
|
|
|
errorMessage == null ? new String[0] : errorMessage.split("\\u001f");
|
2019-02-20 20:44:06 +00:00
|
|
|
final String displayError;
|
|
|
|
if (errorMessageParts.length == 2) {
|
|
|
|
displayError = errorMessageParts[1];
|
|
|
|
} else {
|
|
|
|
displayError = errorMessage;
|
|
|
|
}
|
|
|
|
builder.setMessage(displayError);
|
2022-08-08 19:08:28 +00:00
|
|
|
builder.setNegativeButton(
|
|
|
|
R.string.copy_to_clipboard,
|
|
|
|
(dialog, which) -> {
|
|
|
|
activity.copyTextToClipboard(displayError, R.string.error_message);
|
|
|
|
Toast.makeText(
|
|
|
|
activity,
|
|
|
|
R.string.error_message_copied_to_clipboard,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
builder.setPositiveButton(R.string.confirm, null);
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2018-10-06 12:59:23 +00:00
|
|
|
private void deleteFile(final Message message) {
|
2021-09-20 08:08:11 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
2018-10-06 12:59:23 +00:00
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
builder.setTitle(R.string.delete_file_dialog);
|
|
|
|
builder.setMessage(R.string.delete_file_dialog_msg);
|
2022-08-08 19:08:28 +00:00
|
|
|
builder.setPositiveButton(
|
|
|
|
R.string.confirm,
|
|
|
|
(dialog, which) -> {
|
|
|
|
if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) {
|
|
|
|
message.setDeleted(true);
|
|
|
|
activity.xmppConnectionService.evictPreview(message.getUuid());
|
|
|
|
activity.xmppConnectionService.updateMessage(message, false);
|
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
});
|
2018-10-06 12:59:23 +00:00
|
|
|
builder.create().show();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void resendMessage(final Message message) {
|
|
|
|
if (message.isFileOrImage()) {
|
|
|
|
if (!(message.getConversation() instanceof Conversation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Conversation conversation = (Conversation) message.getConversation();
|
2022-08-08 19:08:28 +00:00
|
|
|
final DownloadableFile file =
|
|
|
|
activity.xmppConnectionService.getFileBackend().getFile(message);
|
2019-01-12 09:09:45 +00:00
|
|
|
if ((file.exists() && file.canRead()) || message.hasFileOnRemoteHost()) {
|
2018-09-11 07:56:29 +00:00
|
|
|
final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection();
|
|
|
|
if (!message.hasFileOnRemoteHost()
|
|
|
|
&& xmppConnection != null
|
2018-11-23 12:11:51 +00:00
|
|
|
&& conversation.getMode() == Conversational.MODE_SINGLE
|
2022-08-08 19:08:28 +00:00
|
|
|
&& !xmppConnection
|
|
|
|
.getFeatures()
|
|
|
|
.httpUpload(message.getFileParams().getSize())) {
|
|
|
|
activity.selectPresence(
|
|
|
|
conversation,
|
|
|
|
() -> {
|
|
|
|
message.setCounterpart(conversation.getNextCounterpart());
|
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
|
|
|
new Handler()
|
|
|
|
.post(
|
|
|
|
() -> {
|
|
|
|
int size = messageList.size();
|
|
|
|
this.binding.messagesView.setSelection(
|
|
|
|
size - 1);
|
|
|
|
});
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-12 09:09:45 +00:00
|
|
|
} else if (!Compatibility.hasStoragePermission(getActivity())) {
|
|
|
|
Toast.makeText(activity, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
|
|
|
Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
|
2019-01-10 13:52:27 +00:00
|
|
|
message.setDeleted(true);
|
|
|
|
activity.xmppConnectionService.updateMessage(message, false);
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activity.xmppConnectionService.resendFailedMessages(message);
|
2022-08-08 19:08:28 +00:00
|
|
|
new Handler()
|
|
|
|
.post(
|
|
|
|
() -> {
|
|
|
|
int size = messageList.size();
|
|
|
|
this.binding.messagesView.setSelection(size - 1);
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelTransmission(Message message) {
|
|
|
|
Transferable transferable = message.getTransferable();
|
|
|
|
if (transferable != null) {
|
|
|
|
transferable.cancel();
|
|
|
|
} else if (message.getStatus() != Message.STATUS_RECEIVED) {
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService.markMessage(
|
|
|
|
message, Message.STATUS_SEND_FAILED, Message.ERROR_MESSAGE_CANCELLED);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void retryDecryption(Message message) {
|
|
|
|
message.setEncryption(Message.ENCRYPTION_PGP);
|
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
refresh();
|
|
|
|
conversation.getAccount().getPgpDecryptionService().decrypt(message, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void privateMessageWith(final Jid counterpart) {
|
2020-01-18 11:08:03 +00:00
|
|
|
if (conversation.setOutgoingChatState(Config.DEFAULT_CHAT_STATE)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
|
|
|
this.binding.textinput.setText("");
|
|
|
|
this.conversation.setNextCounterpart(counterpart);
|
|
|
|
updateChatMsgHint();
|
|
|
|
updateSendButton();
|
|
|
|
updateEditablity();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void correctMessage(Message message) {
|
|
|
|
while (message.mergeable(message.next())) {
|
|
|
|
message = message.next();
|
|
|
|
}
|
|
|
|
this.conversation.setCorrectingMessage(message);
|
|
|
|
final Editable editable = binding.textinput.getText();
|
|
|
|
this.conversation.setDraftMessage(editable.toString());
|
|
|
|
this.binding.textinput.setText("");
|
|
|
|
this.binding.textinput.append(message.getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void highlightInConference(String nick) {
|
|
|
|
final Editable editable = this.binding.textinput.getText();
|
|
|
|
String oldString = editable.toString().trim();
|
|
|
|
final int pos = this.binding.textinput.getSelectionStart();
|
|
|
|
if (oldString.isEmpty() || pos == 0) {
|
|
|
|
editable.insert(0, nick + ": ");
|
|
|
|
} else {
|
|
|
|
final char before = editable.charAt(pos - 1);
|
|
|
|
final char after = editable.length() > pos ? editable.charAt(pos) : '\0';
|
|
|
|
if (before == '\n') {
|
|
|
|
editable.insert(pos, nick + ": ");
|
|
|
|
} else {
|
|
|
|
if (pos > 2 && editable.subSequence(pos - 2, pos).toString().equals(": ")) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (NickValidityChecker.check(
|
|
|
|
conversation,
|
|
|
|
Arrays.asList(
|
|
|
|
editable.subSequence(0, pos - 2).toString().split(", ")))) {
|
2018-09-11 07:56:29 +00:00
|
|
|
editable.insert(pos - 2, ", " + nick);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
editable.insert(
|
|
|
|
pos,
|
|
|
|
(Character.isWhitespace(before) ? "" : " ")
|
|
|
|
+ nick
|
|
|
|
+ (Character.isWhitespace(after) ? "" : " "));
|
2018-09-11 07:56:29 +00:00
|
|
|
if (Character.isWhitespace(after)) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.textinput.setSelection(
|
|
|
|
this.binding.textinput.getSelectionStart() + 1);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:09:22 +00:00
|
|
|
@Override
|
|
|
|
public void startActivityForResult(Intent intent, int requestCode) {
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity instanceof ConversationsActivity) {
|
|
|
|
((ConversationsActivity) activity).clearPendingViewIntent();
|
|
|
|
}
|
|
|
|
super.startActivityForResult(intent, requestCode);
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
@Override
|
2021-09-20 08:08:11 +00:00
|
|
|
public void onSaveInstanceState(@NotNull Bundle outState) {
|
2018-09-11 07:56:29 +00:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
if (conversation != null) {
|
|
|
|
outState.putString(STATE_CONVERSATION_UUID, conversation.getUuid());
|
|
|
|
outState.putString(STATE_LAST_MESSAGE_UUID, lastMessageUuid);
|
|
|
|
final Uri uri = pendingTakePhotoUri.peek();
|
|
|
|
if (uri != null) {
|
|
|
|
outState.putString(STATE_PHOTO_URI, uri.toString());
|
|
|
|
}
|
|
|
|
final ScrollState scrollState = getScrollPosition();
|
|
|
|
if (scrollState != null) {
|
|
|
|
outState.putParcelable(STATE_SCROLL_POSITION, scrollState);
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final ArrayList<Attachment> attachments =
|
|
|
|
mediaPreviewAdapter == null
|
|
|
|
? new ArrayList<>()
|
|
|
|
: mediaPreviewAdapter.getAttachments();
|
2018-09-12 20:20:19 +00:00
|
|
|
if (attachments.size() > 0) {
|
|
|
|
outState.putParcelableArrayList(STATE_MEDIA_PREVIEWS, attachments);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String uuid = savedInstanceState.getString(STATE_CONVERSATION_UUID);
|
2022-08-08 19:08:28 +00:00
|
|
|
ArrayList<Attachment> attachments =
|
|
|
|
savedInstanceState.getParcelableArrayList(STATE_MEDIA_PREVIEWS);
|
2018-09-11 07:56:29 +00:00
|
|
|
pendingLastMessageUuid.push(savedInstanceState.getString(STATE_LAST_MESSAGE_UUID, null));
|
|
|
|
if (uuid != null) {
|
|
|
|
QuickLoader.set(uuid);
|
|
|
|
this.pendingConversationsUuid.push(uuid);
|
2018-09-12 20:20:19 +00:00
|
|
|
if (attachments != null && attachments.size() > 0) {
|
|
|
|
this.pendingMediaPreviews.push(attachments);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
String takePhotoUri = savedInstanceState.getString(STATE_PHOTO_URI);
|
|
|
|
if (takePhotoUri != null) {
|
|
|
|
pendingTakePhotoUri.push(Uri.parse(takePhotoUri));
|
|
|
|
}
|
|
|
|
pendingScrollState.push(savedInstanceState.getParcelable(STATE_SCROLL_POSITION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
if (this.reInitRequiredOnStart && this.conversation != null) {
|
|
|
|
final Bundle extras = pendingExtras.pop();
|
|
|
|
reInit(this.conversation, extras != null);
|
|
|
|
if (extras != null) {
|
|
|
|
processExtras(extras);
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
} else if (conversation == null
|
|
|
|
&& activity != null
|
|
|
|
&& activity.xmppConnectionService != null) {
|
2018-09-11 07:56:29 +00:00
|
|
|
final String uuid = pendingConversationsUuid.pop();
|
2022-08-08 19:08:28 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"ConversationFragment.onStart() - activity was bound but no conversation loaded. uuid="
|
|
|
|
+ uuid);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (uuid != null) {
|
|
|
|
findAndReInitByUuidOrArchive(uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
messageListAdapter.unregisterListenerInAudioPlayer();
|
|
|
|
if (activity == null || !activity.isChangingConfigurations()) {
|
|
|
|
hideSoftKeyboard(activity);
|
|
|
|
messageListAdapter.stopAudioPlayer();
|
|
|
|
}
|
|
|
|
if (this.conversation != null) {
|
|
|
|
final String msg = this.binding.textinput.getText().toString();
|
2018-09-16 13:26:33 +00:00
|
|
|
storeNextMessage(msg);
|
2018-09-11 07:56:29 +00:00
|
|
|
updateChatState(this.conversation, msg);
|
|
|
|
this.activity.xmppConnectionService.getNotificationService().setOpenConversation(null);
|
|
|
|
}
|
|
|
|
this.reInitRequiredOnStart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateChatState(final Conversation conversation, final String msg) {
|
2020-01-18 11:08:03 +00:00
|
|
|
ChatState state = msg.length() == 0 ? Config.DEFAULT_CHAT_STATE : ChatState.PAUSED;
|
2018-09-11 07:56:29 +00:00
|
|
|
Account.State status = conversation.getAccount().getStatus();
|
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(state)) {
|
|
|
|
activity.xmppConnectionService.sendChatState(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveMessageDraftStopAudioPlayer() {
|
|
|
|
final Conversation previousConversation = this.conversation;
|
|
|
|
if (this.activity == null || this.binding == null || previousConversation == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.saveMessageDraftStopAudioPlayer()");
|
|
|
|
final String msg = this.binding.textinput.getText().toString();
|
2018-09-16 13:26:33 +00:00
|
|
|
storeNextMessage(msg);
|
2018-09-11 07:56:29 +00:00
|
|
|
updateChatState(this.conversation, msg);
|
|
|
|
messageListAdapter.stopAudioPlayer();
|
2018-09-13 16:48:21 +00:00
|
|
|
mediaPreviewAdapter.clearPreviews();
|
|
|
|
toggleInputMethod();
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 19:31:54 +00:00
|
|
|
public void reInit(final Conversation conversation, final Bundle extras) {
|
2018-09-11 07:56:29 +00:00
|
|
|
QuickLoader.set(conversation.getUuid());
|
2020-08-05 19:31:54 +00:00
|
|
|
final boolean changedConversation = this.conversation != conversation;
|
|
|
|
if (changedConversation) {
|
|
|
|
this.saveMessageDraftStopAudioPlayer();
|
|
|
|
}
|
2018-09-16 08:09:22 +00:00
|
|
|
this.clearPending();
|
2018-09-11 07:56:29 +00:00
|
|
|
if (this.reInit(conversation, extras != null)) {
|
|
|
|
if (extras != null) {
|
|
|
|
processExtras(extras);
|
|
|
|
}
|
|
|
|
this.reInitRequiredOnStart = false;
|
|
|
|
} else {
|
|
|
|
this.reInitRequiredOnStart = true;
|
|
|
|
pendingExtras.push(extras);
|
|
|
|
}
|
|
|
|
resetUnreadMessagesCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reInit(Conversation conversation) {
|
|
|
|
reInit(conversation, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean reInit(final Conversation conversation, final boolean hasExtras) {
|
|
|
|
if (conversation == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.conversation = conversation;
|
2022-08-08 19:08:28 +00:00
|
|
|
// once we set the conversation all is good and it will automatically do the right thing in
|
|
|
|
// onStart()
|
2018-09-11 07:56:29 +00:00
|
|
|
if (this.activity == null || this.binding == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!activity.xmppConnectionService.isConversationStillOpen(this.conversation)) {
|
|
|
|
activity.onConversationArchived(this.conversation);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
stopScrolling();
|
2021-01-23 08:25:34 +00:00
|
|
|
Log.d(Config.LOGTAG, "reInit(hasExtras=" + hasExtras + ")");
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
if (this.conversation.isRead() && hasExtras) {
|
|
|
|
Log.d(Config.LOGTAG, "trimming conversation");
|
|
|
|
this.conversation.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupIme();
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean scrolledToBottomAndNoPending =
|
|
|
|
this.scrolledToBottom() && pendingScrollState.peek() == null;
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.textSendButton.setContentDescription(
|
|
|
|
activity.getString(R.string.send_message_to_x, conversation.getName()));
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.setKeyboardListener(null);
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean participating =
|
|
|
|
conversation.getMode() == Conversational.MODE_SINGLE
|
|
|
|
|| conversation.getMucOptions().participating();
|
2018-09-11 07:56:29 +00:00
|
|
|
if (participating) {
|
2023-02-01 16:51:32 +00:00
|
|
|
this.binding.textinput.setText(this.conversation.getNextMessage());
|
|
|
|
this.binding.textinput.setSelection(this.binding.textinput.length());
|
|
|
|
} else {
|
|
|
|
this.binding.textinput.setText(MessageUtils.EMPTY_STRING);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
this.binding.textinput.setKeyboardListener(this);
|
|
|
|
messageListAdapter.updatePreferences();
|
|
|
|
refresh(false);
|
2020-12-01 19:31:30 +00:00
|
|
|
activity.invalidateOptionsMenu();
|
2018-09-11 07:56:29 +00:00
|
|
|
this.conversation.messagesLoaded.set(true);
|
2021-01-23 08:25:34 +00:00
|
|
|
Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + scrolledToBottomAndNoPending);
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
if (hasExtras || scrolledToBottomAndNoPending) {
|
|
|
|
resetUnreadMessagesCount();
|
|
|
|
synchronized (this.messageList) {
|
|
|
|
Log.d(Config.LOGTAG, "jump to first unread message");
|
|
|
|
final Message first = conversation.getFirstUnreadMessage();
|
|
|
|
final int bottom = Math.max(0, this.messageList.size() - 1);
|
|
|
|
final int pos;
|
|
|
|
final boolean jumpToBottom;
|
|
|
|
if (first == null) {
|
|
|
|
pos = bottom;
|
|
|
|
jumpToBottom = true;
|
|
|
|
} else {
|
|
|
|
int i = getIndexOf(first.getUuid(), this.messageList);
|
|
|
|
pos = i < 0 ? bottom : i;
|
|
|
|
jumpToBottom = false;
|
|
|
|
}
|
|
|
|
setSelection(pos, jumpToBottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.binding.messagesView.post(this::fireReadEvent);
|
2022-08-08 19:08:28 +00:00
|
|
|
// TODO if we only do this when this fragment is running on main it won't *bing* in tablet
|
|
|
|
// layout which might be unnecessary since we can *see* it
|
|
|
|
activity.xmppConnectionService
|
|
|
|
.getNotificationService()
|
|
|
|
.setOpenConversation(this.conversation);
|
2018-09-11 07:56:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetUnreadMessagesCount() {
|
|
|
|
lastMessageUuid = null;
|
|
|
|
hideUnreadMessagesCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideUnreadMessagesCount() {
|
|
|
|
if (this.binding == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.binding.scrollToBottomButton.setEnabled(false);
|
2018-10-04 14:46:35 +00:00
|
|
|
this.binding.scrollToBottomButton.hide();
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.unreadCountCustomView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSelection(int pos, boolean jumpToBottom) {
|
|
|
|
ListViewUtils.setSelection(this.binding.messagesView, pos, jumpToBottom);
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.messagesView.post(
|
|
|
|
() -> ListViewUtils.setSelection(this.binding.messagesView, pos, jumpToBottom));
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.messagesView.post(this::fireReadEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean scrolledToBottom() {
|
|
|
|
return this.binding != null && scrolledToBottom(this.binding.messagesView);
|
|
|
|
}
|
|
|
|
|
2020-06-21 14:28:57 +00:00
|
|
|
private void processExtras(final Bundle extras) {
|
2018-09-11 07:56:29 +00:00
|
|
|
final String downloadUuid = extras.getString(ConversationsActivity.EXTRA_DOWNLOAD_UUID);
|
2018-09-18 15:03:08 +00:00
|
|
|
final String text = extras.getString(Intent.EXTRA_TEXT);
|
2018-09-11 07:56:29 +00:00
|
|
|
final String nick = extras.getString(ConversationsActivity.EXTRA_NICK);
|
2022-08-08 19:08:28 +00:00
|
|
|
final String postInitAction =
|
|
|
|
extras.getString(ConversationsActivity.EXTRA_POST_INIT_ACTION);
|
2018-09-11 07:56:29 +00:00
|
|
|
final boolean asQuote = extras.getBoolean(ConversationsActivity.EXTRA_AS_QUOTE);
|
|
|
|
final boolean pm = extras.getBoolean(ConversationsActivity.EXTRA_IS_PRIVATE_MESSAGE, false);
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean doNotAppend =
|
|
|
|
extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false);
|
2021-11-07 10:35:00 +00:00
|
|
|
final String type = extras.getString(ConversationsActivity.EXTRA_TYPE);
|
2018-09-12 15:21:32 +00:00
|
|
|
final List<Uri> uris = extractUris(extras);
|
|
|
|
if (uris != null && uris.size() > 0) {
|
2019-05-28 20:32:42 +00:00
|
|
|
if (uris.size() == 1 && "geo".equals(uris.get(0).getScheme())) {
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), uris.get(0), Attachment.Type.LOCATION));
|
2019-05-28 20:32:42 +00:00
|
|
|
} else {
|
|
|
|
final List<Uri> cleanedUris = cleanUris(new ArrayList<>(uris));
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), cleanedUris, type));
|
2019-05-28 20:32:42 +00:00
|
|
|
}
|
2018-09-12 15:21:32 +00:00
|
|
|
toggleInputMethod();
|
|
|
|
return;
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
if (nick != null) {
|
|
|
|
if (pm) {
|
|
|
|
Jid jid = conversation.getJid();
|
|
|
|
try {
|
|
|
|
Jid next = Jid.of(jid.getLocal(), jid.getDomain(), nick);
|
|
|
|
privateMessageWith(next);
|
|
|
|
} catch (final IllegalArgumentException ignored) {
|
2022-08-08 19:08:28 +00:00
|
|
|
// do nothing
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
final MucOptions mucOptions = conversation.getMucOptions();
|
|
|
|
if (mucOptions.participating() || conversation.getNextCounterpart() != null) {
|
|
|
|
highlightInConference(nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-28 20:32:42 +00:00
|
|
|
if (text != null && GeoHelper.GEO_URI.matcher(text).matches()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(
|
|
|
|
Attachment.of(getActivity(), Uri.parse(text), Attachment.Type.LOCATION));
|
2019-05-28 20:32:42 +00:00
|
|
|
toggleInputMethod();
|
|
|
|
return;
|
|
|
|
} else if (text != null && asQuote) {
|
2018-09-11 07:56:29 +00:00
|
|
|
quoteText(text);
|
|
|
|
} else {
|
2018-10-19 13:39:31 +00:00
|
|
|
appendText(text, doNotAppend);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-30 08:30:57 +00:00
|
|
|
if (ConversationsActivity.POST_ACTION_RECORD_VOICE.equals(postInitAction)) {
|
2020-06-21 14:28:57 +00:00
|
|
|
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE, false);
|
2020-05-30 08:30:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
final Message message =
|
|
|
|
downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid);
|
2018-09-11 07:56:29 +00:00
|
|
|
if (message != null) {
|
|
|
|
startDownloadable(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 14:28:57 +00:00
|
|
|
private List<Uri> extractUris(final Bundle extras) {
|
2018-09-12 15:21:32 +00:00
|
|
|
final List<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
|
|
|
|
if (uris != null) {
|
|
|
|
return uris;
|
|
|
|
}
|
|
|
|
final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
|
|
|
if (uri != null) {
|
|
|
|
return Collections.singletonList(uri);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 14:28:57 +00:00
|
|
|
private List<Uri> cleanUris(final List<Uri> uris) {
|
2022-02-23 11:16:49 +00:00
|
|
|
final Iterator<Uri> iterator = uris.iterator();
|
2018-10-24 18:00:06 +00:00
|
|
|
while (iterator.hasNext()) {
|
2018-10-04 15:17:18 +00:00
|
|
|
final Uri uri = iterator.next();
|
2022-02-23 11:16:49 +00:00
|
|
|
if (FileBackend.weOwnFile(uri)) {
|
2018-10-04 15:17:18 +00:00
|
|
|
iterator.remove();
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
R.string.security_violation_not_attaching_file,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-10-04 15:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return uris;
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
private boolean showBlockSubmenu(View view) {
|
|
|
|
final Jid jid = conversation.getJid();
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean showReject =
|
|
|
|
!conversation.isWithStranger()
|
|
|
|
&& conversation
|
|
|
|
.getContact()
|
|
|
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
|
2018-11-18 09:34:14 +00:00
|
|
|
PopupMenu popupMenu = new PopupMenu(getActivity(), view);
|
|
|
|
popupMenu.inflate(R.menu.block);
|
|
|
|
popupMenu.getMenu().findItem(R.id.block_contact).setVisible(jid.getLocal() != null);
|
|
|
|
popupMenu.getMenu().findItem(R.id.reject).setVisible(showReject);
|
2022-08-08 19:08:28 +00:00
|
|
|
popupMenu.setOnMenuItemClickListener(
|
|
|
|
menuItem -> {
|
|
|
|
Blockable blockable;
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case R.id.reject:
|
|
|
|
activity.xmppConnectionService.stopPresenceUpdatesTo(
|
|
|
|
conversation.getContact());
|
|
|
|
updateSnackBar(conversation);
|
|
|
|
return true;
|
|
|
|
case R.id.block_domain:
|
|
|
|
blockable =
|
|
|
|
conversation
|
|
|
|
.getAccount()
|
|
|
|
.getRoster()
|
|
|
|
.getContact(jid.getDomain());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blockable = conversation;
|
|
|
|
}
|
|
|
|
BlockContactDialog.show(activity, blockable);
|
2018-11-18 09:34:14 +00:00
|
|
|
return true;
|
2022-08-08 19:08:28 +00:00
|
|
|
});
|
2018-11-18 09:34:14 +00:00
|
|
|
popupMenu.show();
|
2018-09-11 07:56:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSnackBar(final Conversation conversation) {
|
|
|
|
final Account account = conversation.getAccount();
|
|
|
|
final XmppConnection connection = account.getXmppConnection();
|
|
|
|
final int mode = conversation.getMode();
|
|
|
|
final Contact contact = mode == Conversation.MODE_SINGLE ? conversation.getContact() : null;
|
|
|
|
if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (account.getStatus() == Account.State.DISABLED) {
|
2022-08-08 19:08:28 +00:00
|
|
|
showSnackbar(
|
|
|
|
R.string.this_account_is_disabled,
|
|
|
|
R.string.enable,
|
|
|
|
this.mEnableAccountListener);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else if (conversation.isBlocked()) {
|
|
|
|
showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
|
2022-08-08 19:08:28 +00:00
|
|
|
} else if (contact != null
|
|
|
|
&& !contact.showInRoster()
|
|
|
|
&& contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
|
|
showSnackbar(
|
|
|
|
R.string.contact_added_you,
|
|
|
|
R.string.add_back,
|
|
|
|
this.mAddBackClickListener,
|
|
|
|
this.mLongPressBlockListener);
|
|
|
|
} else if (contact != null
|
|
|
|
&& contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
|
|
showSnackbar(
|
|
|
|
R.string.contact_asks_for_presence_subscription,
|
|
|
|
R.string.allow,
|
|
|
|
this.mAllowPresenceSubscription,
|
|
|
|
this.mLongPressBlockListener);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else if (mode == Conversation.MODE_MULTI
|
|
|
|
&& !conversation.getMucOptions().online()
|
|
|
|
&& account.getStatus() == Account.State.ONLINE) {
|
|
|
|
switch (conversation.getMucOptions().getError()) {
|
|
|
|
case NICK_IN_USE:
|
|
|
|
showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
|
|
|
|
break;
|
|
|
|
case NO_RESPONSE:
|
|
|
|
showSnackbar(R.string.joining_conference, 0, null);
|
|
|
|
break;
|
|
|
|
case SERVER_NOT_FOUND:
|
|
|
|
if (conversation.receivedMessagesCount() > 0) {
|
|
|
|
showSnackbar(R.string.remote_server_not_found, R.string.try_again, joinMuc);
|
|
|
|
} else {
|
|
|
|
showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc);
|
|
|
|
}
|
|
|
|
break;
|
2018-10-08 08:31:11 +00:00
|
|
|
case REMOTE_SERVER_TIMEOUT:
|
|
|
|
if (conversation.receivedMessagesCount() > 0) {
|
|
|
|
showSnackbar(R.string.remote_server_timeout, R.string.try_again, joinMuc);
|
|
|
|
} else {
|
|
|
|
showSnackbar(R.string.remote_server_timeout, R.string.leave, leaveMuc);
|
|
|
|
}
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
case PASSWORD_REQUIRED:
|
2022-08-08 19:08:28 +00:00
|
|
|
showSnackbar(
|
|
|
|
R.string.conference_requires_password,
|
|
|
|
R.string.enter_password,
|
|
|
|
enterPassword);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case BANNED:
|
|
|
|
showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
|
|
|
|
break;
|
|
|
|
case MEMBERS_ONLY:
|
|
|
|
showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
|
|
|
|
break;
|
|
|
|
case RESOURCE_CONSTRAINT:
|
2022-08-08 19:08:28 +00:00
|
|
|
showSnackbar(
|
|
|
|
R.string.conference_resource_constraint, R.string.try_again, joinMuc);
|
2018-09-11 07:56:29 +00:00
|
|
|
break;
|
|
|
|
case KICKED:
|
|
|
|
showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
|
|
|
|
break;
|
2022-08-25 15:12:39 +00:00
|
|
|
case TECHNICAL_PROBLEMS:
|
|
|
|
showSnackbar(R.string.conference_technical_problems, R.string.try_again, joinMuc);
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
case UNKNOWN:
|
|
|
|
showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc);
|
|
|
|
break;
|
|
|
|
case INVALID_NICK:
|
|
|
|
showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc);
|
|
|
|
case SHUTDOWN:
|
|
|
|
showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc);
|
|
|
|
break;
|
|
|
|
case DESTROYED:
|
|
|
|
showSnackbar(R.string.conference_destroyed, R.string.leave, leaveMuc);
|
|
|
|
break;
|
2018-12-09 17:25:11 +00:00
|
|
|
case NON_ANONYMOUS:
|
2022-08-08 19:08:28 +00:00
|
|
|
showSnackbar(
|
|
|
|
R.string.group_chat_will_make_your_jabber_id_public,
|
|
|
|
R.string.join,
|
|
|
|
acceptJoin);
|
2018-12-09 17:25:11 +00:00
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
default:
|
|
|
|
hideSnackbar();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (account.hasPendingPgpIntent(conversation)) {
|
|
|
|
showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
|
|
|
|
} else if (connection != null
|
|
|
|
&& connection.getFeatures().blocking()
|
|
|
|
&& conversation.countMessages() != 0
|
|
|
|
&& !conversation.isBlocked()
|
|
|
|
&& conversation.isWithStranger()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
showSnackbar(
|
|
|
|
R.string.received_message_from_stranger, R.string.block, mBlockClickListener);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
|
|
|
hideSnackbar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refresh() {
|
|
|
|
if (this.binding == null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Log.d(
|
|
|
|
Config.LOGTAG,
|
|
|
|
"ConversationFragment.refresh() skipped updated because view binding was null");
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-08 19:08:28 +00:00
|
|
|
if (this.conversation != null
|
|
|
|
&& this.activity != null
|
|
|
|
&& this.activity.xmppConnectionService != null) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (!activity.xmppConnectionService.isConversationStillOpen(this.conversation)) {
|
|
|
|
activity.onConversationArchived(this.conversation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refresh(boolean notifyConversationRead) {
|
|
|
|
synchronized (this.messageList) {
|
|
|
|
if (this.conversation != null) {
|
|
|
|
conversation.populateWithMessages(this.messageList);
|
|
|
|
updateSnackBar(conversation);
|
|
|
|
updateStatusMessages();
|
|
|
|
if (conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid) != 0) {
|
|
|
|
binding.unreadCountCustomView.setVisibility(View.VISIBLE);
|
2022-08-08 19:08:28 +00:00
|
|
|
binding.unreadCountCustomView.setUnreadCount(
|
|
|
|
conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid));
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
this.messageListAdapter.notifyDataSetChanged();
|
|
|
|
updateChatMsgHint();
|
|
|
|
if (notifyConversationRead && activity != null) {
|
|
|
|
binding.messagesView.post(this::fireReadEvent);
|
|
|
|
}
|
|
|
|
updateSendButton();
|
|
|
|
updateEditablity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void messageSent() {
|
|
|
|
mSendingPgpMessage.set(false);
|
|
|
|
this.binding.textinput.setText("");
|
|
|
|
if (conversation.setCorrectingMessage(null)) {
|
|
|
|
this.binding.textinput.append(conversation.getDraftMessage());
|
|
|
|
conversation.setDraftMessage(null);
|
|
|
|
}
|
2018-09-16 13:26:33 +00:00
|
|
|
storeNextMessage();
|
2018-09-11 07:56:29 +00:00
|
|
|
updateChatMsgHint();
|
|
|
|
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean prefScrollToBottom =
|
|
|
|
p.getBoolean(
|
|
|
|
"scroll_to_bottom",
|
|
|
|
activity.getResources().getBoolean(R.bool.scroll_to_bottom));
|
2018-09-11 07:56:29 +00:00
|
|
|
if (prefScrollToBottom || scrolledToBottom()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
new Handler()
|
|
|
|
.post(
|
|
|
|
() -> {
|
|
|
|
int size = messageList.size();
|
|
|
|
this.binding.messagesView.setSelection(size - 1);
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 13:26:33 +00:00
|
|
|
private boolean storeNextMessage() {
|
|
|
|
return storeNextMessage(this.binding.textinput.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean storeNextMessage(String msg) {
|
2022-08-08 19:08:28 +00:00
|
|
|
final boolean participating =
|
|
|
|
conversation.getMode() == Conversational.MODE_SINGLE
|
|
|
|
|| conversation.getMucOptions().participating();
|
|
|
|
if (this.conversation.getStatus() != Conversation.STATUS_ARCHIVED
|
|
|
|
&& participating
|
|
|
|
&& this.conversation.setNextMessage(msg)) {
|
2018-09-16 13:26:33 +00:00
|
|
|
this.activity.xmppConnectionService.updateConversation(this.conversation);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
public void doneSendingPgpMessage() {
|
|
|
|
mSendingPgpMessage.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMaxHttpUploadSize(Conversation conversation) {
|
|
|
|
final XmppConnection connection = conversation.getAccount().getXmppConnection();
|
|
|
|
return connection == null ? -1 : connection.getFeatures().getMaxHttpUploadSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEditablity() {
|
2022-08-08 19:08:28 +00:00
|
|
|
boolean canWrite =
|
|
|
|
this.conversation.getMode() == Conversation.MODE_SINGLE
|
|
|
|
|| this.conversation.getMucOptions().participating()
|
|
|
|
|| this.conversation.getNextCounterpart() != null;
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.setFocusable(canWrite);
|
|
|
|
this.binding.textinput.setFocusableInTouchMode(canWrite);
|
|
|
|
this.binding.textSendButton.setEnabled(canWrite);
|
|
|
|
this.binding.textinput.setCursorVisible(canWrite);
|
|
|
|
this.binding.textinput.setEnabled(canWrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateSendButton() {
|
2022-08-08 19:08:28 +00:00
|
|
|
boolean hasAttachments =
|
|
|
|
mediaPreviewAdapter != null && mediaPreviewAdapter.hasAttachments();
|
2018-09-11 07:56:29 +00:00
|
|
|
final Conversation c = this.conversation;
|
|
|
|
final Presence.Status status;
|
2022-08-08 19:08:28 +00:00
|
|
|
final String text =
|
|
|
|
this.binding.textinput == null ? "" : this.binding.textinput.getText().toString();
|
2018-09-11 07:56:29 +00:00
|
|
|
final SendButtonAction action;
|
|
|
|
if (hasAttachments) {
|
|
|
|
action = SendButtonAction.TEXT;
|
|
|
|
} else {
|
|
|
|
action = SendButtonTool.getAction(getActivity(), c, text);
|
|
|
|
}
|
2019-11-08 11:23:06 +00:00
|
|
|
if (c.getAccount().getStatus() == Account.State.ONLINE) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (activity != null
|
|
|
|
&& activity.xmppConnectionService != null
|
|
|
|
&& activity.xmppConnectionService.getMessageArchiveService().isCatchingUp(c)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
status = Presence.Status.OFFLINE;
|
|
|
|
} else if (c.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
status = c.getContact().getShownStatus();
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
status =
|
|
|
|
c.getMucOptions().online()
|
|
|
|
? Presence.Status.ONLINE
|
|
|
|
: Presence.Status.OFFLINE;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status = Presence.Status.OFFLINE;
|
|
|
|
}
|
|
|
|
this.binding.textSendButton.setTag(action);
|
2019-07-01 08:17:29 +00:00
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity != null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding.textSendButton.setImageResource(
|
|
|
|
SendButtonTool.getSendButtonImageResource(activity, action, status));
|
2019-07-01 08:17:29 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateStatusMessages() {
|
2019-04-27 13:24:37 +00:00
|
|
|
DateSeparator.addAll(this.messageList);
|
|
|
|
if (showLoadMoreMessages(conversation)) {
|
|
|
|
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
|
|
|
|
}
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
ChatState state = conversation.getIncomingChatState();
|
|
|
|
if (state == ChatState.COMPOSING) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.messageList.add(
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation,
|
|
|
|
getString(R.string.contact_is_typing, conversation.getName())));
|
2019-04-27 13:24:37 +00:00
|
|
|
} else if (state == ChatState.PAUSED) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.messageList.add(
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation,
|
|
|
|
getString(
|
|
|
|
R.string.contact_has_stopped_typing,
|
|
|
|
conversation.getName())));
|
2019-04-27 13:24:37 +00:00
|
|
|
} else {
|
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
|
|
final Message message = this.messageList.get(i);
|
|
|
|
if (message.getType() != Message.TYPE_STATUS) {
|
|
|
|
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (message.getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
2022-08-08 19:08:28 +00:00
|
|
|
this.messageList.add(
|
|
|
|
i + 1,
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation,
|
|
|
|
getString(
|
|
|
|
R.string.contact_has_read_up_to_this_point,
|
|
|
|
conversation.getName())));
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 13:24:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
final MucOptions mucOptions = conversation.getMucOptions();
|
|
|
|
final List<MucOptions.User> allUsers = mucOptions.getUsers();
|
|
|
|
final Set<ReadByMarker> addedMarkers = new HashSet<>();
|
|
|
|
ChatState state = ChatState.COMPOSING;
|
2022-08-08 19:08:28 +00:00
|
|
|
List<MucOptions.User> users =
|
|
|
|
conversation.getMucOptions().getUsersWithChatState(state, 5);
|
2019-04-27 13:24:37 +00:00
|
|
|
if (users.size() == 0) {
|
|
|
|
state = ChatState.PAUSED;
|
|
|
|
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
|
|
|
}
|
|
|
|
if (mucOptions.isPrivateAndNonAnonymous()) {
|
|
|
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
2022-08-08 19:08:28 +00:00
|
|
|
final Set<ReadByMarker> markersForMessage =
|
|
|
|
messageList.get(i).getReadByMarkers();
|
2019-04-27 13:24:37 +00:00
|
|
|
final List<MucOptions.User> shownMarkers = new ArrayList<>();
|
|
|
|
for (ReadByMarker marker : markersForMessage) {
|
|
|
|
if (!ReadByMarker.contains(marker, addedMarkers)) {
|
2022-08-08 19:08:28 +00:00
|
|
|
addedMarkers.add(
|
|
|
|
marker); // may be put outside this condition. set should do
|
|
|
|
// dedup anyway
|
2019-04-27 13:24:37 +00:00
|
|
|
MucOptions.User user = mucOptions.findUser(marker);
|
|
|
|
if (user != null && !users.contains(user)) {
|
|
|
|
shownMarkers.add(user);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-27 13:24:37 +00:00
|
|
|
}
|
|
|
|
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
|
|
|
|
final Message statusMessage;
|
|
|
|
final int size = shownMarkers.size();
|
|
|
|
if (size > 1) {
|
|
|
|
final String body;
|
|
|
|
if (size <= 4) {
|
2022-08-08 19:08:28 +00:00
|
|
|
body =
|
|
|
|
getString(
|
|
|
|
R.string.contacts_have_read_up_to_this_point,
|
|
|
|
UIHelper.concatNames(shownMarkers));
|
|
|
|
} else if (ReadByMarker.allUsersRepresented(
|
|
|
|
allUsers, markersForMessage, markerForSender)) {
|
2019-04-27 13:24:37 +00:00
|
|
|
body = getString(R.string.everyone_has_read_up_to_this_point);
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
body =
|
|
|
|
getString(
|
|
|
|
R.string.contacts_and_n_more_have_read_up_to_this_point,
|
|
|
|
UIHelper.concatNames(shownMarkers, 3),
|
|
|
|
size - 3);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2019-04-27 13:24:37 +00:00
|
|
|
statusMessage = Message.createStatusMessage(conversation, body);
|
|
|
|
statusMessage.setCounterparts(shownMarkers);
|
|
|
|
} else if (size == 1) {
|
2022-08-08 19:08:28 +00:00
|
|
|
statusMessage =
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation,
|
|
|
|
getString(
|
|
|
|
R.string.contact_has_read_up_to_this_point,
|
|
|
|
UIHelper.getDisplayName(shownMarkers.get(0))));
|
2019-04-27 13:24:37 +00:00
|
|
|
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
|
|
|
|
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
|
2018-09-11 07:56:29 +00:00
|
|
|
} else {
|
2019-04-27 13:24:37 +00:00
|
|
|
statusMessage = null;
|
|
|
|
}
|
|
|
|
if (statusMessage != null) {
|
|
|
|
this.messageList.add(i + 1, statusMessage);
|
|
|
|
}
|
|
|
|
addedMarkers.add(markerForSender);
|
|
|
|
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
|
|
|
|
break;
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 13:24:37 +00:00
|
|
|
if (users.size() > 0) {
|
|
|
|
Message statusMessage;
|
|
|
|
if (users.size() == 1) {
|
|
|
|
MucOptions.User user = users.get(0);
|
2022-08-08 19:08:28 +00:00
|
|
|
int id =
|
|
|
|
state == ChatState.COMPOSING
|
|
|
|
? R.string.contact_is_typing
|
|
|
|
: R.string.contact_has_stopped_typing;
|
|
|
|
statusMessage =
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation, getString(id, UIHelper.getDisplayName(user)));
|
2019-04-27 13:24:37 +00:00
|
|
|
statusMessage.setTrueCounterpart(user.getRealJid());
|
|
|
|
statusMessage.setCounterpart(user.getFullJid());
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
int id =
|
|
|
|
state == ChatState.COMPOSING
|
|
|
|
? R.string.contacts_are_typing
|
|
|
|
: R.string.contacts_have_stopped_typing;
|
|
|
|
statusMessage =
|
|
|
|
Message.createStatusMessage(
|
|
|
|
conversation, getString(id, UIHelper.concatNames(users)));
|
2019-04-27 13:24:37 +00:00
|
|
|
statusMessage.setCounterparts(users);
|
|
|
|
}
|
|
|
|
this.messageList.add(statusMessage);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void stopScrolling() {
|
|
|
|
long now = SystemClock.uptimeMillis();
|
|
|
|
MotionEvent cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
|
|
|
|
binding.messagesView.dispatchTouchEvent(cancel);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean showLoadMoreMessages(final Conversation c) {
|
|
|
|
if (activity == null || activity.xmppConnectionService == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final boolean mam = hasMamSupport(c) && !c.getContact().isBlocked();
|
2022-08-08 19:08:28 +00:00
|
|
|
final MessageArchiveService service =
|
|
|
|
activity.xmppConnectionService.getMessageArchiveService();
|
|
|
|
return mam
|
|
|
|
&& (c.getLastClearHistory().getTimestamp() != 0
|
|
|
|
|| (c.countMessages() == 0
|
|
|
|
&& c.messagesLoaded.get()
|
|
|
|
&& c.hasMessagesLeftOnServer()
|
|
|
|
&& !service.queryInProgress(c)));
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasMamSupport(final Conversation c) {
|
|
|
|
if (c.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
final XmppConnection connection = c.getAccount().getXmppConnection();
|
|
|
|
return connection != null && connection.getFeatures().mam();
|
|
|
|
} else {
|
|
|
|
return c.getMucOptions().mamSupport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
protected void showSnackbar(
|
|
|
|
final int message, final int action, final OnClickListener clickListener) {
|
2018-09-11 07:56:29 +00:00
|
|
|
showSnackbar(message, action, clickListener, null);
|
|
|
|
}
|
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
protected void showSnackbar(
|
|
|
|
final int message,
|
|
|
|
final int action,
|
|
|
|
final OnClickListener clickListener,
|
|
|
|
final View.OnLongClickListener longClickListener) {
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.snackbar.setVisibility(View.VISIBLE);
|
|
|
|
this.binding.snackbar.setOnClickListener(null);
|
|
|
|
this.binding.snackbarMessage.setText(message);
|
|
|
|
this.binding.snackbarMessage.setOnClickListener(null);
|
|
|
|
this.binding.snackbarAction.setVisibility(clickListener == null ? View.GONE : View.VISIBLE);
|
|
|
|
if (action != 0) {
|
|
|
|
this.binding.snackbarAction.setText(action);
|
|
|
|
}
|
|
|
|
this.binding.snackbarAction.setOnClickListener(clickListener);
|
|
|
|
this.binding.snackbarAction.setOnLongClickListener(longClickListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void hideSnackbar() {
|
|
|
|
this.binding.snackbar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void sendMessage(Message message) {
|
|
|
|
activity.xmppConnectionService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void sendPgpMessage(final Message message) {
|
|
|
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
|
|
|
final Contact contact = message.getConversation().getContact();
|
|
|
|
if (!activity.hasPgp()) {
|
|
|
|
activity.showInstallPgpDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (conversation.getAccount().getPgpSignature() == null) {
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.announcePgp(
|
|
|
|
conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
|
2018-09-11 07:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mSendingPgpMessage.compareAndSet(false, true)) {
|
|
|
|
Log.d(Config.LOGTAG, "sending pgp message already in progress");
|
|
|
|
}
|
|
|
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
if (contact.getPgpKeyId() != 0) {
|
2022-08-08 19:08:28 +00:00
|
|
|
xmppService
|
|
|
|
.getPgpEngine()
|
|
|
|
.hasKey(
|
|
|
|
contact,
|
|
|
|
new UiCallback<Contact>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void userInputRequired(
|
|
|
|
PendingIntent pi, Contact contact) {
|
|
|
|
startPendingIntent(pi, REQUEST_ENCRYPT_MESSAGE);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void success(Contact contact) {
|
|
|
|
encryptTextMessage(message);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void error(int error, Contact contact) {
|
|
|
|
activity.runOnUiThread(
|
|
|
|
() ->
|
|
|
|
Toast.makeText(
|
|
|
|
activity,
|
|
|
|
R.string
|
|
|
|
.unable_to_connect_to_keychain,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show());
|
|
|
|
mSendingPgpMessage.set(false);
|
|
|
|
}
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
showNoPGPKeyDialog(
|
|
|
|
false,
|
|
|
|
(dialog, which) -> {
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.updateConversation(conversation);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (conversation.getMucOptions().pgpKeysInUse()) {
|
|
|
|
if (!conversation.getMucOptions().everybodyHasKeys()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast warning =
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(), R.string.missing_public_keys, Toast.LENGTH_LONG);
|
2018-09-11 07:56:29 +00:00
|
|
|
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
warning.show();
|
|
|
|
}
|
|
|
|
encryptTextMessage(message);
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
showNoPGPKeyDialog(
|
|
|
|
true,
|
|
|
|
(dialog, which) -> {
|
|
|
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
|
|
|
xmppService.updateConversation(conversation);
|
|
|
|
xmppService.sendMessage(message);
|
|
|
|
messageSent();
|
|
|
|
});
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void encryptTextMessage(Message message) {
|
2022-08-08 19:08:28 +00:00
|
|
|
activity.xmppConnectionService
|
|
|
|
.getPgpEngine()
|
|
|
|
.encrypt(
|
|
|
|
message,
|
|
|
|
new UiCallback<Message>() {
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void userInputRequired(PendingIntent pi, Message message) {
|
|
|
|
startPendingIntent(pi, REQUEST_SEND_MESSAGE);
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void success(Message message) {
|
|
|
|
// TODO the following two call can be made before the callback
|
|
|
|
getActivity().runOnUiThread(() -> messageSent());
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
|
2022-08-08 19:08:28 +00:00
|
|
|
@Override
|
|
|
|
public void error(final int error, Message message) {
|
|
|
|
getActivity()
|
|
|
|
.runOnUiThread(
|
|
|
|
() -> {
|
|
|
|
doneSendingPgpMessage();
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
error == 0
|
|
|
|
? R.string
|
|
|
|
.unable_to_connect_to_keychain
|
|
|
|
: error,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
|
|
|
});
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showNoPGPKeyDialog(boolean plural, DialogInterface.OnClickListener listener) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
|
|
|
if (plural) {
|
|
|
|
builder.setTitle(getString(R.string.no_pgp_keys));
|
|
|
|
builder.setMessage(getText(R.string.contacts_have_no_pgp_keys));
|
|
|
|
} else {
|
|
|
|
builder.setTitle(getString(R.string.no_pgp_key));
|
|
|
|
builder.setMessage(getText(R.string.contact_has_no_pgp_key));
|
|
|
|
}
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
builder.setPositiveButton(getString(R.string.send_unencrypted), listener);
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2018-10-19 13:39:31 +00:00
|
|
|
public void appendText(String text, final boolean doNotAppend) {
|
2018-09-11 07:56:29 +00:00
|
|
|
if (text == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-19 13:39:31 +00:00
|
|
|
final Editable editable = this.binding.textinput.getText();
|
2018-10-24 18:00:06 +00:00
|
|
|
String previous = editable == null ? "" : editable.toString();
|
2018-10-19 13:39:31 +00:00
|
|
|
if (doNotAppend && !TextUtils.isEmpty(previous)) {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.already_drafting_message, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
2018-10-19 13:39:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
if (UIHelper.isLastLineQuote(previous)) {
|
|
|
|
text = '\n' + text;
|
2022-08-08 19:08:28 +00:00
|
|
|
} else if (previous.length() != 0
|
|
|
|
&& !Character.isWhitespace(previous.charAt(previous.length() - 1))) {
|
2018-09-11 07:56:29 +00:00
|
|
|
text = " " + text;
|
|
|
|
}
|
|
|
|
this.binding.textinput.append(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-12 06:28:09 +00:00
|
|
|
public boolean onEnterPressed(final boolean isCtrlPressed) {
|
|
|
|
if (isCtrlPressed || enterIsSend()) {
|
2018-09-11 07:56:29 +00:00
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-12 06:28:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean enterIsSend() {
|
|
|
|
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
return p.getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send));
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 07:45:27 +00:00
|
|
|
public boolean onArrowUpCtrlPressed() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final Message lastEditableMessage =
|
|
|
|
conversation == null ? null : conversation.getLastEditableMessage();
|
2020-07-12 07:45:27 +00:00
|
|
|
if (lastEditableMessage != null) {
|
|
|
|
correctMessage(lastEditableMessage);
|
|
|
|
return true;
|
2020-07-26 15:03:51 +00:00
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(getActivity(), R.string.could_not_correct_message, Toast.LENGTH_LONG)
|
|
|
|
.show();
|
2020-07-26 15:03:51 +00:00
|
|
|
return false;
|
2020-07-12 07:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 07:56:29 +00:00
|
|
|
@Override
|
|
|
|
public void onTypingStarted() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final XmppConnectionService service =
|
|
|
|
activity == null ? null : activity.xmppConnectionService;
|
2018-09-11 07:56:29 +00:00
|
|
|
if (service == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-26 15:03:51 +00:00
|
|
|
final Account.State status = conversation.getAccount().getStatus();
|
2022-08-08 19:08:28 +00:00
|
|
|
if (status == Account.State.ONLINE
|
|
|
|
&& conversation.setOutgoingChatState(ChatState.COMPOSING)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
service.sendChatState(conversation);
|
|
|
|
}
|
2019-04-25 10:27:38 +00:00
|
|
|
runOnUiThread(this::updateSendButton);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTypingStopped() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final XmppConnectionService service =
|
|
|
|
activity == null ? null : activity.xmppConnectionService;
|
2018-09-11 07:56:29 +00:00
|
|
|
if (service == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-26 15:03:51 +00:00
|
|
|
final Account.State status = conversation.getAccount().getStatus();
|
2018-09-11 07:56:29 +00:00
|
|
|
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.PAUSED)) {
|
|
|
|
service.sendChatState(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextDeleted() {
|
2022-08-08 19:08:28 +00:00
|
|
|
final XmppConnectionService service =
|
|
|
|
activity == null ? null : activity.xmppConnectionService;
|
2018-09-11 07:56:29 +00:00
|
|
|
if (service == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-26 15:03:51 +00:00
|
|
|
final Account.State status = conversation.getAccount().getStatus();
|
2022-08-08 19:08:28 +00:00
|
|
|
if (status == Account.State.ONLINE
|
|
|
|
&& conversation.setOutgoingChatState(Config.DEFAULT_CHAT_STATE)) {
|
2018-09-11 07:56:29 +00:00
|
|
|
service.sendChatState(conversation);
|
|
|
|
}
|
2018-09-16 13:26:33 +00:00
|
|
|
if (storeNextMessage()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
runOnUiThread(
|
|
|
|
() -> {
|
|
|
|
if (activity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity.onConversationsListItemUpdated();
|
|
|
|
});
|
2018-09-16 13:26:33 +00:00
|
|
|
}
|
2019-04-25 10:27:38 +00:00
|
|
|
runOnUiThread(this::updateSendButton);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged() {
|
|
|
|
if (conversation != null && conversation.getCorrectingMessage() != null) {
|
2019-04-25 10:27:38 +00:00
|
|
|
runOnUiThread(this::updateSendButton);
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTabPressed(boolean repeated) {
|
|
|
|
if (conversation == null || conversation.getMode() == Conversation.MODE_SINGLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (repeated) {
|
|
|
|
completionIndex++;
|
|
|
|
} else {
|
|
|
|
lastCompletionLength = 0;
|
|
|
|
completionIndex = 0;
|
|
|
|
final String content = this.binding.textinput.getText().toString();
|
|
|
|
lastCompletionCursor = this.binding.textinput.getSelectionEnd();
|
2022-08-08 19:08:28 +00:00
|
|
|
int start =
|
|
|
|
lastCompletionCursor > 0
|
|
|
|
? content.lastIndexOf(" ", lastCompletionCursor - 1) + 1
|
|
|
|
: 0;
|
2018-09-11 07:56:29 +00:00
|
|
|
firstWord = start == 0;
|
|
|
|
incomplete = content.substring(start, lastCompletionCursor);
|
|
|
|
}
|
|
|
|
List<String> completions = new ArrayList<>();
|
|
|
|
for (MucOptions.User user : conversation.getMucOptions().getUsers()) {
|
|
|
|
String name = user.getName();
|
|
|
|
if (name != null && name.startsWith(incomplete)) {
|
|
|
|
completions.add(name + (firstWord ? ": " : " "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(completions);
|
|
|
|
if (completions.size() > completionIndex) {
|
|
|
|
String completion = completions.get(completionIndex).substring(incomplete.length());
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding
|
|
|
|
.textinput
|
|
|
|
.getEditableText()
|
|
|
|
.delete(lastCompletionCursor, lastCompletionCursor + lastCompletionLength);
|
2018-09-11 07:56:29 +00:00
|
|
|
this.binding.textinput.getEditableText().insert(lastCompletionCursor, completion);
|
|
|
|
lastCompletionLength = completion.length();
|
|
|
|
} else {
|
|
|
|
completionIndex = -1;
|
2022-08-08 19:08:28 +00:00
|
|
|
this.binding
|
|
|
|
.textinput
|
|
|
|
.getEditableText()
|
|
|
|
.delete(lastCompletionCursor, lastCompletionCursor + lastCompletionLength);
|
2018-09-11 07:56:29 +00:00
|
|
|
lastCompletionLength = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startPendingIntent(PendingIntent pendingIntent, int requestCode) {
|
|
|
|
try {
|
2022-08-08 19:08:28 +00:00
|
|
|
getActivity()
|
|
|
|
.startIntentSenderForResult(
|
|
|
|
pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
|
2018-09-11 07:56:29 +00:00
|
|
|
} catch (final SendIntentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackendConnected() {
|
|
|
|
Log.d(Config.LOGTAG, "ConversationFragment.onBackendConnected()");
|
|
|
|
String uuid = pendingConversationsUuid.pop();
|
|
|
|
if (uuid != null) {
|
|
|
|
if (!findAndReInitByUuidOrArchive(uuid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!activity.xmppConnectionService.isConversationStillOpen(conversation)) {
|
|
|
|
clearPending();
|
|
|
|
activity.onConversationArchived(conversation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ActivityResult activityResult = postponedActivityResult.pop();
|
|
|
|
if (activityResult != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
}
|
|
|
|
clearPending();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean findAndReInitByUuidOrArchive(@NonNull final String uuid) {
|
|
|
|
Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
|
|
|
|
if (conversation == null) {
|
|
|
|
clearPending();
|
|
|
|
activity.onConversationArchived(null);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
reInit(conversation);
|
|
|
|
ScrollState scrollState = pendingScrollState.pop();
|
|
|
|
String lastMessageUuid = pendingLastMessageUuid.pop();
|
2018-09-12 20:20:19 +00:00
|
|
|
List<Attachment> attachments = pendingMediaPreviews.pop();
|
2018-09-11 07:56:29 +00:00
|
|
|
if (scrollState != null) {
|
|
|
|
setScrollPosition(scrollState, lastMessageUuid);
|
|
|
|
}
|
2018-09-12 20:20:19 +00:00
|
|
|
if (attachments != null && attachments.size() > 0) {
|
2018-09-21 10:27:58 +00:00
|
|
|
Log.d(Config.LOGTAG, "had attachments on restore");
|
2018-09-12 20:20:19 +00:00
|
|
|
mediaPreviewAdapter.addMediaPreviews(attachments);
|
|
|
|
toggleInputMethod();
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clearPending() {
|
2018-09-16 08:09:22 +00:00
|
|
|
if (postponedActivityResult.clear()) {
|
2018-09-11 07:56:29 +00:00
|
|
|
Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left");
|
2020-06-17 15:56:19 +00:00
|
|
|
if (pendingTakePhotoUri.clear()) {
|
|
|
|
Log.e(Config.LOGTAG, "cleared pending photo uri");
|
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
2018-09-16 08:09:22 +00:00
|
|
|
if (pendingScrollState.clear()) {
|
2018-09-21 10:27:58 +00:00
|
|
|
Log.e(Config.LOGTAG, "cleared scroll state");
|
2018-09-16 08:09:22 +00:00
|
|
|
}
|
2019-01-02 08:36:22 +00:00
|
|
|
if (pendingConversationsUuid.clear()) {
|
2020-04-04 09:31:53 +00:00
|
|
|
Log.e(Config.LOGTAG, "cleared pending conversations uuid");
|
2019-01-02 08:36:22 +00:00
|
|
|
}
|
|
|
|
if (pendingMediaPreviews.clear()) {
|
2020-04-04 09:31:53 +00:00
|
|
|
Log.e(Config.LOGTAG, "cleared pending media previews");
|
2019-01-02 08:36:22 +00:00
|
|
|
}
|
2018-09-11 07:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Conversation getConversation() {
|
|
|
|
return conversation;
|
|
|
|
}
|
2018-12-04 11:23:14 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactPictureLongClicked(View v, final Message message) {
|
2019-01-27 10:38:20 +00:00
|
|
|
final String fingerprint;
|
2022-08-08 19:08:28 +00:00
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
2019-01-27 10:38:20 +00:00
|
|
|
fingerprint = "pgp";
|
|
|
|
} else {
|
|
|
|
fingerprint = message.getFingerprint();
|
|
|
|
}
|
|
|
|
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
|
|
|
|
final Contact contact = message.getContact();
|
2022-08-08 19:08:28 +00:00
|
|
|
if (message.getStatus() <= Message.STATUS_RECEIVED
|
|
|
|
&& (contact == null || !contact.isSelf())) {
|
2018-12-04 11:23:14 +00:00
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
|
|
|
final Jid cp = message.getCounterpart();
|
|
|
|
if (cp == null || cp.isBareJid()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-27 10:38:20 +00:00
|
|
|
final Jid tcp = message.getTrueCounterpart();
|
2022-08-08 19:08:28 +00:00
|
|
|
final User userByRealJid =
|
|
|
|
tcp != null
|
|
|
|
? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp)
|
|
|
|
: null;
|
|
|
|
final User user =
|
|
|
|
userByRealJid != null
|
|
|
|
? userByRealJid
|
|
|
|
: conversation.getMucOptions().findUserByFullJid(cp);
|
2018-12-04 11:23:14 +00:00
|
|
|
popupMenu.inflate(R.menu.muc_details_context);
|
|
|
|
final Menu menu = popupMenu.getMenu();
|
2022-08-08 19:08:28 +00:00
|
|
|
MucDetailsContextMenuHelper.configureMucDetailsContextMenu(
|
|
|
|
activity, menu, conversation, user);
|
|
|
|
popupMenu.setOnMenuItemClickListener(
|
|
|
|
menuItem ->
|
|
|
|
MucDetailsContextMenuHelper.onContextItemSelected(
|
|
|
|
menuItem, user, activity, fingerprint));
|
2018-12-04 11:23:14 +00:00
|
|
|
} else {
|
|
|
|
popupMenu.inflate(R.menu.one_on_one_context);
|
2022-08-08 19:08:28 +00:00
|
|
|
popupMenu.setOnMenuItemClickListener(
|
|
|
|
item -> {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_contact_details:
|
|
|
|
activity.switchToContactDetails(
|
|
|
|
message.getContact(), fingerprint);
|
|
|
|
break;
|
|
|
|
case R.id.action_show_qr_code:
|
|
|
|
activity.showQrCode(
|
|
|
|
"xmpp:"
|
|
|
|
+ message.getContact()
|
|
|
|
.getJid()
|
|
|
|
.asBareJid()
|
|
|
|
.toEscapedString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-12-04 11:23:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-27 10:38:20 +00:00
|
|
|
popupMenu.inflate(R.menu.account_context);
|
|
|
|
final Menu menu = popupMenu.getMenu();
|
2022-08-08 19:08:28 +00:00
|
|
|
menu.findItem(R.id.action_manage_accounts)
|
|
|
|
.setVisible(QuickConversationsService.isConversations());
|
|
|
|
popupMenu.setOnMenuItemClickListener(
|
|
|
|
item -> {
|
|
|
|
final XmppActivity activity = this.activity;
|
|
|
|
if (activity == null) {
|
|
|
|
Log.e(Config.LOGTAG, "Unable to perform action. no context provided");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_show_qr_code:
|
|
|
|
activity.showQrCode(conversation.getAccount().getShareableUri());
|
|
|
|
break;
|
|
|
|
case R.id.action_account_details:
|
|
|
|
activity.switchToAccount(
|
|
|
|
message.getConversation().getAccount(), fingerprint);
|
|
|
|
break;
|
|
|
|
case R.id.action_manage_accounts:
|
|
|
|
AccountUtils.launchManageAccounts(activity);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-12-04 11:23:14 +00:00
|
|
|
}
|
2019-01-27 10:38:20 +00:00
|
|
|
popupMenu.show();
|
2018-12-04 11:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactPictureClicked(Message message) {
|
|
|
|
String fingerprint;
|
2022-08-08 19:08:28 +00:00
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
|
|
|
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
2018-12-04 11:23:14 +00:00
|
|
|
fingerprint = "pgp";
|
|
|
|
} else {
|
|
|
|
fingerprint = message.getFingerprint();
|
|
|
|
}
|
|
|
|
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
|
|
|
|
if (received) {
|
2022-08-08 19:08:28 +00:00
|
|
|
if (message.getConversation() instanceof Conversation
|
|
|
|
&& message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
2018-12-04 11:23:14 +00:00
|
|
|
Jid tcp = message.getTrueCounterpart();
|
|
|
|
Jid user = message.getCounterpart();
|
|
|
|
if (user != null && !user.isBareJid()) {
|
2022-08-08 19:08:28 +00:00
|
|
|
final MucOptions mucOptions =
|
|
|
|
((Conversation) message.getConversation()).getMucOptions();
|
|
|
|
if (mucOptions.participating()
|
|
|
|
|| ((Conversation) message.getConversation()).getNextCounterpart()
|
|
|
|
!= null) {
|
|
|
|
if (!mucOptions.isUserInRoom(user)
|
|
|
|
&& mucOptions.findUserByRealJid(
|
|
|
|
tcp == null ? null : tcp.asBareJid())
|
|
|
|
== null) {
|
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
activity.getString(
|
|
|
|
R.string.user_has_left_conference,
|
|
|
|
user.getResource()),
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-12-04 11:23:14 +00:00
|
|
|
}
|
|
|
|
highlightInConference(user.getResource());
|
|
|
|
} else {
|
2022-08-08 19:08:28 +00:00
|
|
|
Toast.makeText(
|
|
|
|
getActivity(),
|
|
|
|
R.string.you_are_not_participating,
|
|
|
|
Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
2018-12-04 11:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (!message.getContact().isSelf()) {
|
|
|
|
activity.switchToContactDetails(message.getContact(), fingerprint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
|
|
|
|
}
|
2021-09-21 09:55:37 +00:00
|
|
|
|
|
|
|
private Activity requireActivity() {
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity == null) {
|
|
|
|
throw new IllegalStateException("Activity not attached");
|
|
|
|
}
|
|
|
|
return activity;
|
|
|
|
}
|
2021-02-08 15:03:30 +00:00
|
|
|
}
|