Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/org/thoughtcrime/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ protected void onNewIntent(Intent intent) {
return;
}

if (intent.getIntExtra(CHAT_ID_EXTRA, DcChat.DC_CHAT_NO_CHAT) == DcChat.DC_CHAT_NO_CHAT) {
Log.w(TAG, "onNewIntent: ignoring intent with invalid chat ID");
return;
}

if (!Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent()) {
processComposeControls(ACTION_SAVE_DRAFT);
attachmentManager.clear(glideRequests, false);
Expand Down Expand Up @@ -1116,8 +1121,11 @@ private void initializeResources() {
initializeBackground();
}
chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, -1);
if (chatId == DcChat.DC_CHAT_NO_CHAT)
throw new IllegalStateException("can't display a conversation for no chat.");
if (chatId == DcChat.DC_CHAT_NO_CHAT) {
Log.e(TAG, "initializeResources: invalid chat ID " + chatId + ", finishing activity");
finish();
return;
}
dcChat = DcHelper.getContext(context).getChat(chatId);
recipient = new Recipient(this, dcChat);
glideRequests = GlideApp.with(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ private void handleReplyMessagePrivately(final DcMsg msg) {
if (getActivity() != null) {
DcContext dcContext = DcHelper.getContext(getActivity());
int privateChatId = dcContext.createChatByContactId(msg.getFromId());
if (privateChatId == 0) {
Log.w(TAG, "createChatByContactId returned 0, cannot reply privately");
return;
}
DcMsg replyMsg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT);
replyMsg.setQuote(msg);
dcContext.setDraft(privateChatId, replyMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void handleResolvedMedia(Intent intent) {
accId = dcContext.getAccountId();
}
Intent composeIntent;
if (accId != -1 && chatId != -1) {
if (accId != -1 && chatId > 0) {
composeIntent = getBaseShareIntent(ConversationActivity.class);
composeIntent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
composeIntent.putExtra(ConversationActivity.ACCOUNT_ID_EXTRA, accId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
setResult(RESULT_OK, intent);
} else {
int chatId = dcContext.createChatByContactId(contactId);
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
startActivity(intent);
if (chatId != 0) {
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
startActivity(intent);
}
}
finish();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ private void showFingerprintOrQrSuccess(
R.string.start_chat,
(dialogInterface, i) -> {
int chatId = dcContext.createChatByContactId(qrParsed.getId());
if (chatId == 0) {
Log.w(TAG, "createChatByContactId returned 0, ignoring");
return;
}
Intent intent = new Intent(activity, ConversationActivity.class);
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
if (qrParsed.getText1Meaning() == DcLot.DC_TEXT1_DRAFT) {
Expand Down