2017-09-30 08:45:45 -07:00
|
|
|
/*
|
2015-01-15 13:35:35 -08:00
|
|
|
* Copyright (C) 2015 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2018-09-27 11:34:43 -07:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2015-01-15 13:35:35 -08:00
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
2015-11-05 17:47:29 +01:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2015-01-15 13:35:35 -08:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
2015-03-04 16:37:48 -08:00
|
|
|
import android.view.MenuItem;
|
2015-01-15 13:35:35 -08:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2020-09-11 17:27:57 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
import org.thoughtcrime.securesms.MessageDetailsRecipientAdapter.RecipientDeliveryStatus;
|
2015-11-05 17:47:29 +01:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
2019-07-24 12:30:23 +10:00
|
|
|
import org.thoughtcrime.securesms.conversation.ConversationItem;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-09-30 08:45:45 -07:00
|
|
|
import org.thoughtcrime.securesms.database.GroupReceiptDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.loaders.MessageDetailsLoader;
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2019-07-24 12:30:23 +10:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2020-05-12 11:46:11 +10:00
|
|
|
import org.thoughtcrime.securesms.loki.database.LokiMessageDatabase;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2018-10-11 16:45:22 -07:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2015-01-15 13:35:35 -08:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils;
|
2015-03-10 20:40:55 +01:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2016-08-15 20:23:56 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
2015-11-05 17:47:29 +01:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2018-06-26 10:27:44 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2020-09-17 11:39:34 +10:00
|
|
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChat;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
import java.sql.Date;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
2017-08-01 08:56:00 -07:00
|
|
|
import java.util.List;
|
2015-03-19 13:08:48 -07:00
|
|
|
import java.util.Locale;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-03-08 11:37:18 -07:00
|
|
|
/**
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
2017-08-01 08:56:00 -07:00
|
|
|
public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity implements LoaderCallbacks<Cursor>, RecipientModifiedListener {
|
2015-01-15 13:35:35 -08:00
|
|
|
private final static String TAG = MessageDetailsActivity.class.getSimpleName();
|
|
|
|
|
2015-11-05 17:47:29 +01:00
|
|
|
public final static String MESSAGE_ID_EXTRA = "message_id";
|
2015-08-15 14:00:08 +02:00
|
|
|
public final static String THREAD_ID_EXTRA = "thread_id";
|
2015-11-05 17:47:29 +01:00
|
|
|
public final static String IS_PUSH_GROUP_EXTRA = "is_push_group";
|
|
|
|
public final static String TYPE_EXTRA = "type";
|
2017-08-01 08:56:00 -07:00
|
|
|
public final static String ADDRESS_EXTRA = "address";
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
private GlideRequests glideRequests;
|
2015-08-15 14:00:08 +02:00
|
|
|
private long threadId;
|
2015-02-26 18:31:22 -08:00
|
|
|
private boolean isPushGroup;
|
2015-01-15 13:35:35 -08:00
|
|
|
private ConversationItem conversationItem;
|
|
|
|
private ViewGroup itemParent;
|
2015-02-27 11:07:20 -08:00
|
|
|
private View metadataContainer;
|
2016-08-15 20:23:56 -07:00
|
|
|
private View expiresContainer;
|
2015-02-27 11:07:20 -08:00
|
|
|
private TextView errorText;
|
2018-10-11 16:45:22 -07:00
|
|
|
private View resendButton;
|
2015-01-15 13:35:35 -08:00
|
|
|
private TextView sentDate;
|
|
|
|
private TextView receivedDate;
|
2016-08-15 20:23:56 -07:00
|
|
|
private TextView expiresInText;
|
2015-01-15 13:35:35 -08:00
|
|
|
private View receivedContainer;
|
|
|
|
private TextView transport;
|
|
|
|
private TextView toFrom;
|
2020-09-17 11:39:34 +10:00
|
|
|
private View separator;
|
2015-01-15 13:35:35 -08:00
|
|
|
private ListView recipientsList;
|
|
|
|
private LayoutInflater inflater;
|
|
|
|
|
2015-03-10 20:40:55 +01:00
|
|
|
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private boolean running;
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
@Override
|
2014-12-15 12:25:55 -08:00
|
|
|
protected void onPreCreate() {
|
2015-03-10 20:40:55 +01:00
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 12:25:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
public void onCreate(Bundle bundle, boolean ready) {
|
2020-01-15 16:13:28 +11:00
|
|
|
super.onCreate(bundle, ready);
|
2015-01-15 13:35:35 -08:00
|
|
|
setContentView(R.layout.message_details_activity);
|
2016-08-15 20:23:56 -07:00
|
|
|
running = true;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
|
|
|
initializeResources();
|
2015-11-05 17:47:29 +01:00
|
|
|
initializeActionBar();
|
2015-01-15 13:35:35 -08:00
|
|
|
getSupportLoaderManager().initLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
2015-03-10 20:40:55 +01:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicLanguage.onResume(this);
|
2018-02-01 19:22:48 -08:00
|
|
|
|
|
|
|
assert getSupportActionBar() != null;
|
2020-01-15 16:13:28 +11:00
|
|
|
getSupportActionBar().setTitle("Message Details");
|
2015-08-15 14:00:08 +02:00
|
|
|
|
2020-06-26 16:18:19 +10:00
|
|
|
ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(threadId);
|
2015-08-15 14:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2020-06-26 16:18:19 +10:00
|
|
|
ApplicationContext.getInstance(this).messageNotifier.setVisibleThread(-1L);
|
2015-03-10 20:40:55 +01:00
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
|
2015-11-05 17:47:29 +01:00
|
|
|
private void initializeActionBar() {
|
2018-02-01 19:22:48 -08:00
|
|
|
assert getSupportActionBar() != null;
|
2015-11-05 17:47:29 +01:00
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
Recipient recipient = Recipient.from(this, getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.addListener(this);
|
2015-11-05 17:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setActionBarColor(MaterialColor color) {
|
2018-02-01 19:22:48 -08:00
|
|
|
assert getSupportActionBar() != null;
|
2015-11-05 17:47:29 +01:00
|
|
|
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-09-30 08:45:45 -07:00
|
|
|
Util.runOnMain(() -> setActionBarColor(recipient.getColor()));
|
2015-11-05 17:47:29 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
private void initializeResources() {
|
|
|
|
inflater = LayoutInflater.from(this);
|
|
|
|
View header = inflater.inflate(R.layout.message_details_header, recipientsList, false);
|
|
|
|
|
2015-08-15 14:00:08 +02:00
|
|
|
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
2015-02-26 18:31:22 -08:00
|
|
|
isPushGroup = getIntent().getBooleanExtra(IS_PUSH_GROUP_EXTRA, false);
|
2017-10-16 13:11:42 -07:00
|
|
|
glideRequests = GlideApp.with(this);
|
2018-01-24 19:17:44 -08:00
|
|
|
itemParent = header.findViewById(R.id.item_container);
|
|
|
|
recipientsList = findViewById(R.id.recipients_list);
|
|
|
|
metadataContainer = header.findViewById(R.id.metadata_container);
|
|
|
|
errorText = header.findViewById(R.id.error_text);
|
2018-10-11 16:45:22 -07:00
|
|
|
resendButton = header.findViewById(R.id.resend_button);
|
2018-01-24 19:17:44 -08:00
|
|
|
sentDate = header.findViewById(R.id.sent_time);
|
|
|
|
receivedContainer = header.findViewById(R.id.received_container);
|
|
|
|
receivedDate = header.findViewById(R.id.received_time);
|
|
|
|
transport = header.findViewById(R.id.transport);
|
|
|
|
toFrom = header.findViewById(R.id.tofrom);
|
2020-09-17 11:39:34 +10:00
|
|
|
separator = header.findViewById(R.id.separator);
|
2018-01-24 19:17:44 -08:00
|
|
|
expiresContainer = header.findViewById(R.id.expires_container);
|
|
|
|
expiresInText = header.findViewById(R.id.expires_in);
|
2015-01-15 13:35:35 -08:00
|
|
|
recipientsList.setHeaderDividersEnabled(false);
|
|
|
|
recipientsList.addHeaderView(header, null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateTransport(MessageRecord messageRecord) {
|
|
|
|
final String transportText;
|
|
|
|
if (messageRecord.isOutgoing() && messageRecord.isFailed()) {
|
|
|
|
transportText = "-";
|
|
|
|
} else if (messageRecord.isPending()) {
|
|
|
|
transportText = getString(R.string.ConversationFragment_pending);
|
|
|
|
} else if (messageRecord.isPush()) {
|
|
|
|
transportText = getString(R.string.ConversationFragment_push);
|
|
|
|
} else if (messageRecord.isMms()) {
|
|
|
|
transportText = getString(R.string.ConversationFragment_mms);
|
|
|
|
} else {
|
|
|
|
transportText = getString(R.string.ConversationFragment_sms);
|
|
|
|
}
|
|
|
|
|
|
|
|
transport.setText(transportText);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateTime(MessageRecord messageRecord) {
|
2018-09-27 11:34:43 -07:00
|
|
|
sentDate.setOnLongClickListener(null);
|
|
|
|
receivedDate.setOnLongClickListener(null);
|
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
if (messageRecord.isPending() || messageRecord.isFailed()) {
|
|
|
|
sentDate.setText("-");
|
|
|
|
receivedContainer.setVisibility(View.GONE);
|
|
|
|
} else {
|
2015-03-19 13:08:48 -07:00
|
|
|
Locale dateLocale = dynamicLanguage.getCurrentLocale();
|
|
|
|
SimpleDateFormat dateFormatter = DateUtils.getDetailedDateFormatter(this, dateLocale);
|
2015-01-15 13:35:35 -08:00
|
|
|
sentDate.setText(dateFormatter.format(new Date(messageRecord.getDateSent())));
|
2018-09-27 11:34:43 -07:00
|
|
|
sentDate.setOnLongClickListener(v -> {
|
|
|
|
copyToClipboard(String.valueOf(messageRecord.getDateSent()));
|
|
|
|
return true;
|
|
|
|
});
|
2015-01-15 13:35:35 -08:00
|
|
|
|
|
|
|
if (messageRecord.getDateReceived() != messageRecord.getDateSent() && !messageRecord.isOutgoing()) {
|
|
|
|
receivedDate.setText(dateFormatter.format(new Date(messageRecord.getDateReceived())));
|
2018-09-27 11:34:43 -07:00
|
|
|
receivedDate.setOnLongClickListener(v -> {
|
|
|
|
copyToClipboard(String.valueOf(messageRecord.getDateReceived()));
|
|
|
|
return true;
|
|
|
|
});
|
2015-01-15 13:35:35 -08:00
|
|
|
receivedContainer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
receivedContainer.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void updateExpirationTime(final MessageRecord messageRecord) {
|
|
|
|
if (messageRecord.getExpiresIn() <= 0 || messageRecord.getExpireStarted() <= 0) {
|
|
|
|
expiresContainer.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
expiresContainer.setVisibility(View.VISIBLE);
|
2017-10-04 14:56:31 -07:00
|
|
|
Util.runOnMain(new Runnable() {
|
2016-08-15 20:23:56 -07:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
long elapsed = System.currentTimeMillis() - messageRecord.getExpireStarted();
|
|
|
|
long remaining = messageRecord.getExpiresIn() - elapsed;
|
|
|
|
|
|
|
|
String duration = ExpirationUtil.getExpirationDisplayValue(MessageDetailsActivity.this, Math.max((int)(remaining / 1000), 1));
|
|
|
|
expiresInText.setText(duration);
|
|
|
|
|
|
|
|
if (running) {
|
2017-10-04 14:56:31 -07:00
|
|
|
Util.runOnMainDelayed(this, 500);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
private void updateRecipients(MessageRecord messageRecord, Recipient recipient, List<RecipientDeliveryStatus> recipients) {
|
2015-01-15 13:35:35 -08:00
|
|
|
final int toFromRes;
|
|
|
|
if (messageRecord.isMms() && !messageRecord.isPush() && !messageRecord.isOutgoing()) {
|
|
|
|
toFromRes = R.string.message_details_header__with;
|
|
|
|
} else if (messageRecord.isOutgoing()) {
|
|
|
|
toFromRes = R.string.message_details_header__to;
|
|
|
|
} else {
|
|
|
|
toFromRes = R.string.message_details_header__from;
|
|
|
|
}
|
|
|
|
toFrom.setText(toFromRes);
|
2020-09-17 11:39:34 +10:00
|
|
|
long threadID = messageRecord.getThreadId();
|
|
|
|
PublicChat openGroup = DatabaseFactory.getLokiThreadDatabase(this).getPublicChat(threadID);
|
|
|
|
if (openGroup != null && messageRecord.isOutgoing()) {
|
|
|
|
toFrom.setVisibility(View.GONE);
|
|
|
|
separator.setVisibility(View.GONE);
|
|
|
|
}
|
2019-02-01 09:06:59 -08:00
|
|
|
conversationItem.bind(messageRecord, Optional.absent(), Optional.absent(), glideRequests, dynamicLanguage.getCurrentLocale(), new HashSet<>(), recipient, null, false);
|
2018-01-24 19:17:44 -08:00
|
|
|
recipientsList.setAdapter(new MessageDetailsRecipientAdapter(this, glideRequests, messageRecord, recipients, isPushGroup));
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void inflateMessageViewIfAbsent(MessageRecord messageRecord) {
|
|
|
|
if (conversationItem == null) {
|
|
|
|
if (messageRecord.isGroupAction()) {
|
2015-09-16 17:31:24 -07:00
|
|
|
conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_update, itemParent, false);
|
2015-01-15 13:35:35 -08:00
|
|
|
} else if (messageRecord.isOutgoing()) {
|
|
|
|
conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_sent, itemParent, false);
|
|
|
|
} else {
|
|
|
|
conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_received, itemParent, false);
|
|
|
|
}
|
|
|
|
itemParent.addView(conversationItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private @Nullable MessageRecord getMessageRecord(Context context, Cursor cursor, String type) {
|
2015-01-15 13:35:35 -08:00
|
|
|
switch (type) {
|
|
|
|
case MmsSmsDatabase.SMS_TRANSPORT:
|
2018-01-24 19:17:44 -08:00
|
|
|
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
|
|
|
SmsDatabase.Reader reader = smsDatabase.readerFor(cursor);
|
2015-01-15 13:35:35 -08:00
|
|
|
return reader.getNext();
|
|
|
|
case MmsSmsDatabase.MMS_TRANSPORT:
|
|
|
|
MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
|
2018-01-24 19:17:44 -08:00
|
|
|
MmsDatabase.Reader mmsReader = mmsDatabase.readerFor(cursor);
|
2015-01-15 13:35:35 -08:00
|
|
|
return mmsReader.getNext();
|
|
|
|
default:
|
|
|
|
throw new AssertionError("no valid message type specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 11:34:43 -07:00
|
|
|
private void copyToClipboard(@NonNull String text) {
|
|
|
|
((ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("text", text));
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
|
|
|
|
@Override
|
2018-05-22 02:13:10 -07:00
|
|
|
public @NonNull Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
2015-01-15 13:35:35 -08:00
|
|
|
return new MessageDetailsLoader(this, getIntent().getStringExtra(TYPE_EXTRA),
|
|
|
|
getIntent().getLongExtra(MESSAGE_ID_EXTRA, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-22 02:13:10 -07:00
|
|
|
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
|
2016-08-15 20:23:56 -07:00
|
|
|
MessageRecord messageRecord = getMessageRecord(this, cursor, getIntent().getStringExtra(TYPE_EXTRA));
|
|
|
|
|
|
|
|
if (messageRecord == null) {
|
|
|
|
finish();
|
|
|
|
} else {
|
2017-10-23 13:03:32 -07:00
|
|
|
new MessageRecipientAsyncTask(this, messageRecord).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-22 02:13:10 -07:00
|
|
|
public void onLoaderReset(@NonNull Loader<Cursor> loader) {
|
2015-01-15 13:35:35 -08:00
|
|
|
recipientsList.setAdapter(null);
|
|
|
|
}
|
|
|
|
|
2015-03-04 16:37:48 -08:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home: finish(); return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2017-09-30 08:45:45 -07:00
|
|
|
private class MessageRecipientAsyncTask extends AsyncTask<Void,Void,List<RecipientDeliveryStatus>> {
|
|
|
|
|
|
|
|
private final WeakReference<Context> weakContext;
|
|
|
|
private final MessageRecord messageRecord;
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
MessageRecipientAsyncTask(@NonNull Context context, @NonNull MessageRecord messageRecord) {
|
2015-01-15 13:35:35 -08:00
|
|
|
this.weakContext = new WeakReference<>(context);
|
|
|
|
this.messageRecord = messageRecord;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Context getContext() {
|
|
|
|
return weakContext.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-09-30 08:45:45 -07:00
|
|
|
public List<RecipientDeliveryStatus> doInBackground(Void... voids) {
|
2015-01-15 13:35:35 -08:00
|
|
|
Context context = getContext();
|
2017-09-30 08:45:45 -07:00
|
|
|
|
2015-01-15 13:35:35 -08:00
|
|
|
if (context == null) {
|
|
|
|
Log.w(TAG, "associated context is destroyed, finishing early");
|
2015-07-09 22:02:12 +02:00
|
|
|
return null;
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
2017-09-30 08:45:45 -07:00
|
|
|
List<RecipientDeliveryStatus> recipients = new LinkedList<>();
|
2015-01-15 13:35:35 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (!messageRecord.getRecipient().isGroupRecipient()) {
|
2018-10-11 16:45:22 -07:00
|
|
|
recipients.add(new RecipientDeliveryStatus(messageRecord.getRecipient(), getStatusFor(messageRecord.getDeliveryReceiptCount(), messageRecord.getReadReceiptCount(), messageRecord.isPending()), messageRecord.isUnidentified(), -1));
|
2015-01-15 13:35:35 -08:00
|
|
|
} else {
|
2017-09-30 08:45:45 -07:00
|
|
|
List<GroupReceiptInfo> receiptInfoList = DatabaseFactory.getGroupReceiptDatabase(context).getGroupReceiptInfo(messageRecord.getId());
|
|
|
|
|
|
|
|
if (receiptInfoList.isEmpty()) {
|
|
|
|
List<Recipient> group = DatabaseFactory.getGroupDatabase(context).getGroupMembers(messageRecord.getRecipient().getAddress().toGroupString(), false);
|
|
|
|
|
|
|
|
for (Recipient recipient : group) {
|
2018-10-11 16:45:22 -07:00
|
|
|
recipients.add(new RecipientDeliveryStatus(recipient, RecipientDeliveryStatus.Status.UNKNOWN, false, -1));
|
2017-09-30 08:45:45 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (GroupReceiptInfo info : receiptInfoList) {
|
|
|
|
recipients.add(new RecipientDeliveryStatus(Recipient.from(context, info.getAddress(), true),
|
2018-10-11 16:45:22 -07:00
|
|
|
getStatusFor(info.getStatus(), messageRecord.isPending(), messageRecord.isFailed()),
|
|
|
|
info.isUnidentified(),
|
2017-09-30 08:45:45 -07:00
|
|
|
info.getTimestamp()));
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return recipients;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-09-30 08:45:45 -07:00
|
|
|
public void onPostExecute(List<RecipientDeliveryStatus> recipients) {
|
2015-01-15 13:35:35 -08:00
|
|
|
if (getContext() == null) {
|
|
|
|
Log.w(TAG, "AsyncTask finished with a destroyed context, leaving early.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inflateMessageViewIfAbsent(messageRecord);
|
2017-08-01 08:56:00 -07:00
|
|
|
updateRecipients(messageRecord, messageRecord.getRecipient(), recipients);
|
2018-10-11 16:45:22 -07:00
|
|
|
|
|
|
|
boolean isGroupNetworkFailure = messageRecord.isFailed() && !messageRecord.getNetworkFailures().isEmpty();
|
|
|
|
boolean isIndividualNetworkFailure = messageRecord.isFailed() && !isPushGroup && messageRecord.getIdentityKeyMismatches().isEmpty();
|
|
|
|
|
2020-03-05 14:07:42 +11:00
|
|
|
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(getContext());
|
|
|
|
String errorMessage = lokiMessageDatabase.getErrorMessage(messageRecord.id);
|
|
|
|
if (errorMessage != null) {
|
|
|
|
errorText.setText(errorMessage);
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
if (isGroupNetworkFailure || isIndividualNetworkFailure) {
|
2015-02-27 11:07:20 -08:00
|
|
|
errorText.setVisibility(View.VISIBLE);
|
2018-10-11 16:45:22 -07:00
|
|
|
resendButton.setVisibility(View.VISIBLE);
|
|
|
|
resendButton.setOnClickListener(this::onResendClicked);
|
|
|
|
metadataContainer.setVisibility(View.GONE);
|
|
|
|
} else if (messageRecord.isFailed()) {
|
|
|
|
errorText.setVisibility(View.VISIBLE);
|
|
|
|
resendButton.setVisibility(View.GONE);
|
|
|
|
resendButton.setOnClickListener(null);
|
2015-02-27 11:07:20 -08:00
|
|
|
metadataContainer.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
updateTransport(messageRecord);
|
|
|
|
updateTime(messageRecord);
|
2016-08-15 20:23:56 -07:00
|
|
|
updateExpirationTime(messageRecord);
|
2015-02-27 11:07:20 -08:00
|
|
|
errorText.setVisibility(View.GONE);
|
2018-10-11 16:45:22 -07:00
|
|
|
resendButton.setVisibility(View.GONE);
|
|
|
|
resendButton.setOnClickListener(null);
|
2015-02-27 11:07:20 -08:00
|
|
|
metadataContainer.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|
2017-09-30 08:45:45 -07:00
|
|
|
|
|
|
|
private RecipientDeliveryStatus.Status getStatusFor(int deliveryReceiptCount, int readReceiptCount, boolean pending) {
|
|
|
|
if (readReceiptCount > 0) return RecipientDeliveryStatus.Status.READ;
|
|
|
|
else if (deliveryReceiptCount > 0) return RecipientDeliveryStatus.Status.DELIVERED;
|
|
|
|
else if (!pending) return RecipientDeliveryStatus.Status.SENT;
|
|
|
|
else return RecipientDeliveryStatus.Status.PENDING;
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
private RecipientDeliveryStatus.Status getStatusFor(int groupStatus, boolean pending, boolean failed) {
|
2017-09-30 08:45:45 -07:00
|
|
|
if (groupStatus == GroupReceiptDatabase.STATUS_READ) return RecipientDeliveryStatus.Status.READ;
|
|
|
|
else if (groupStatus == GroupReceiptDatabase.STATUS_DELIVERED) return RecipientDeliveryStatus.Status.DELIVERED;
|
2018-10-11 16:45:22 -07:00
|
|
|
else if (groupStatus == GroupReceiptDatabase.STATUS_UNDELIVERED && failed) return RecipientDeliveryStatus.Status.UNKNOWN;
|
2017-09-30 08:45:45 -07:00
|
|
|
else if (groupStatus == GroupReceiptDatabase.STATUS_UNDELIVERED && !pending) return RecipientDeliveryStatus.Status.SENT;
|
|
|
|
else if (groupStatus == GroupReceiptDatabase.STATUS_UNDELIVERED) return RecipientDeliveryStatus.Status.PENDING;
|
|
|
|
else if (groupStatus == GroupReceiptDatabase.STATUS_UNKNOWN) return RecipientDeliveryStatus.Status.UNKNOWN;
|
|
|
|
throw new AssertionError();
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
private void onResendClicked(View v) {
|
|
|
|
MessageSender.resend(MessageDetailsActivity.this, messageRecord);
|
|
|
|
resendButton.setVisibility(View.GONE);
|
|
|
|
}
|
2015-03-08 11:37:18 -07:00
|
|
|
}
|
2015-01-15 13:35:35 -08:00
|
|
|
}
|