introduced type private_file_message to handle attachments in PMs. fixes #3372

This commit is contained in:
Daniel Gultsch 2019-04-27 11:46:43 +02:00
parent b55d4bc62f
commit b2ea91909b
14 changed files with 123 additions and 71 deletions

View File

@ -1326,7 +1326,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
final boolean success; final boolean success;
if (message.getType() == Message.TYPE_PRIVATE) { if (message.isPrivateMessage()) {
success = buildHeader(axolotlMessage, message.getTrueCounterpart()); success = buildHeader(axolotlMessage, message.getTrueCounterpart());
} else { } else {
success = buildHeader(axolotlMessage, (Conversation) message.getConversation()); success = buildHeader(axolotlMessage, (Conversation) message.getConversation());

View File

@ -486,7 +486,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
final Message message = messages.get(i); final Message message = messages.get(i);
if (message.getStatus() <= Message.STATUS_RECEIVED if (message.getStatus() <= Message.STATUS_RECEIVED
&& (message.markable || isPrivateAndNonAnonymousMuc) && (message.markable || isPrivateAndNonAnonymousMuc)
&& message.getType() != Message.TYPE_PRIVATE) { && !message.isPrivateMessage()) {
return message; return message;
} }
} }
@ -748,7 +748,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
synchronized (this.messages) { synchronized (this.messages) {
for (int i = this.messages.size() - 1; i >= 0; --i) { for (int i = this.messages.size() - 1; i >= 0; --i) {
final Message message = this.messages.get(i); final Message message = this.messages.get(i);
if (message.getType() == Message.TYPE_PRIVATE) { if (message.isPrivateMessage()) {
continue; //it's unsafe to use private messages as anchor. They could be coming from user archive continue; //it's unsafe to use private messages as anchor. They could be coming from user archive
} }
if (message.getStatus() == Message.STATUS_RECEIVED || message.isCarbon() || message.getServerMsgId() != null) { if (message.getStatus() == Message.STATUS_RECEIVED || message.isCarbon() || message.getServerMsgId() != null) {

View File

@ -57,6 +57,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
public static final int TYPE_FILE = 2; public static final int TYPE_FILE = 2;
public static final int TYPE_STATUS = 3; public static final int TYPE_STATUS = 3;
public static final int TYPE_PRIVATE = 4; public static final int TYPE_PRIVATE = 4;
public static final int TYPE_PRIVATE_FILE = 5;
public static final String CONVERSATION = "conversationUuid"; public static final String CONVERSATION = "conversationUuid";
public static final String COUNTERPART = "counterpart"; public static final String COUNTERPART = "counterpart";
@ -495,7 +496,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
} }
boolean similar(Message message) { boolean similar(Message message) {
if (type != TYPE_PRIVATE && this.serverMsgId != null && message.getServerMsgId() != null) { if (!isPrivateMessage() && this.serverMsgId != null && message.getServerMsgId() != null) {
return this.serverMsgId.equals(message.getServerMsgId()) || Edited.wasPreviouslyEditedServerMsgId(edits, message.getServerMsgId()); return this.serverMsgId.equals(message.getServerMsgId()) || Edited.wasPreviouslyEditedServerMsgId(edits, message.getServerMsgId());
} else if (Edited.wasPreviouslyEditedServerMsgId(edits, message.getServerMsgId())) { } else if (Edited.wasPreviouslyEditedServerMsgId(edits, message.getServerMsgId())) {
return true; return true;
@ -837,8 +838,12 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
this.mPreviousMessage = null; this.mPreviousMessage = null;
} }
public boolean isPrivateMessage() {
return type == TYPE_PRIVATE || type == TYPE_PRIVATE_FILE;
}
public boolean isFileOrImage() { public boolean isFileOrImage() {
return type == TYPE_FILE || type == TYPE_IMAGE; return type == TYPE_FILE || type == TYPE_IMAGE || type == TYPE_PRIVATE_FILE;
} }
public boolean hasFileOnRemoteHost() { public boolean hasFileOnRemoteHost() {
@ -915,4 +920,31 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
} }
return encryption; return encryption;
} }
public static boolean configurePrivateMessage(final Message message) {
return configurePrivateMessage(message, false);
}
public static boolean configurePrivateFileMessage(final Message message) {
return configurePrivateMessage(message, true);
}
private static boolean configurePrivateMessage(final Message message, final boolean isFile) {
final Conversation conversation;
if (message.conversation instanceof Conversation) {
conversation = (Conversation) message.conversation;
} else {
return false;
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
final Jid nextCounterpart = conversation.getNextCounterpart();
if (nextCounterpart != null) {
message.setCounterpart(nextCounterpart);
message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart));
message.setType(isFile ? Message.TYPE_PRIVATE_FILE : Message.TYPE_PRIVATE);
return true;
}
}
return false;
}
} }

View File

@ -1,7 +1,5 @@
package eu.siacs.conversations.generator; package eu.siacs.conversations.generator;
import android.util.Log;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,7 +11,6 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.P1S3UrlStreamHandler; import eu.siacs.conversations.http.P1S3UrlStreamHandler;
@ -43,7 +40,7 @@ public class MessageGenerator extends AbstractGenerator {
if (this.mXmppConnectionService.indicateReceived() && !isWithSelf) { if (this.mXmppConnectionService.indicateReceived() && !isWithSelf) {
packet.addChild("request", "urn:xmpp:receipts"); packet.addChild("request", "urn:xmpp:receipts");
} }
} else if (message.getType() == Message.TYPE_PRIVATE) { //TODO files and images might be private as well } else if (message.isPrivateMessage()) {
packet.setTo(message.getCounterpart()); packet.setTo(message.getCounterpart());
packet.setType(MessagePacket.TYPE_CHAT); packet.setType(MessagePacket.TYPE_CHAT);
packet.addChild("x", "http://jabber.org/protocol/muc#user"); packet.addChild("x", "http://jabber.org/protocol/muc#user");
@ -54,7 +51,7 @@ public class MessageGenerator extends AbstractGenerator {
packet.setTo(message.getCounterpart().asBareJid()); packet.setTo(message.getCounterpart().asBareJid());
packet.setType(MessagePacket.TYPE_GROUPCHAT); packet.setType(MessagePacket.TYPE_GROUPCHAT);
} }
if (conversation.isSingleOrPrivateAndNonAnonymous() && message.getType() != Message.TYPE_PRIVATE) { if (conversation.isSingleOrPrivateAndNonAnonymous() && !message.isPrivateMessage()) {
packet.addChild("markable", "urn:xmpp:chat-markers:0"); packet.addChild("markable", "urn:xmpp:chat-markers:0");
} }
packet.setFrom(account.getJid()); packet.setFrom(account.getJid());

View File

@ -442,7 +442,8 @@ public class HttpDownloadConnection implements Transferable {
} }
private void updateImageBounds() { private void updateImageBounds() {
message.setType(Message.TYPE_FILE); final boolean privateMessage = message.isPrivateMessage();
message.setType(privateMessage ? Message.TYPE_PRIVATE_FILE : Message.TYPE_FILE);
final URL url; final URL url;
final String ref = mUrl.getRef(); final String ref = mUrl.getRef();
if (method == Method.P1_S3) { if (method == Method.P1_S3) {

View File

@ -216,7 +216,9 @@ public class HttpUploadConnection implements Transferable {
mXmppConnectionService.getFileBackend().updateFileParams(message, get); mXmppConnectionService.getFileBackend().updateFileParams(message, get);
mXmppConnectionService.getFileBackend().updateMediaScanner(file); mXmppConnectionService.getFileBackend().updateMediaScanner(file);
finish(); finish();
if (!message.isPrivateMessage()) {
message.setCounterpart(message.getConversation().getJid().asBareJid()); message.setCounterpart(message.getConversation().getJid().asBareJid());
}
mXmppConnectionService.resendMessage(message, delayed); mXmppConnectionService.resendMessage(message, delayed);
} else { } else {
Log.d(Config.LOGTAG,"http upload failed because response code was "+code); Log.d(Config.LOGTAG,"http upload failed because response code was "+code);

View File

@ -551,7 +551,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.updateMessage(replacedMessage, uuid); mXmppConnectionService.updateMessage(replacedMessage, uuid);
if (mXmppConnectionService.confirmMessages() if (mXmppConnectionService.confirmMessages()
&& replacedMessage.getStatus() == Message.STATUS_RECEIVED && replacedMessage.getStatus() == Message.STATUS_RECEIVED
&& (replacedMessage.trusted() || replacedMessage.getType() == Message.TYPE_PRIVATE) && (replacedMessage.trusted() || replacedMessage.isPrivateMessage()) //TODO do we really want to send receipts for all PMs?
&& remoteMsgId != null && remoteMsgId != null
&& !selfAddressed && !selfAddressed
&& !isTypeGroupChat) { && !isTypeGroupChat) {
@ -577,7 +577,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
boolean checkForDuplicates = (isTypeGroupChat && packet.hasChild("delay", "urn:xmpp:delay")) boolean checkForDuplicates = (isTypeGroupChat && packet.hasChild("delay", "urn:xmpp:delay"))
|| message.getType() == Message.TYPE_PRIVATE || message.isPrivateMessage()
|| message.getServerMsgId() != null || message.getServerMsgId() != null
|| (query == null && mXmppConnectionService.getMessageArchiveService().isCatchupInProgress(conversation)); || (query == null && mXmppConnectionService.getMessageArchiveService().isCatchupInProgress(conversation));
if (checkForDuplicates) { if (checkForDuplicates) {
@ -637,7 +637,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (mXmppConnectionService.confirmMessages() if (mXmppConnectionService.confirmMessages()
&& message.getStatus() == Message.STATUS_RECEIVED && message.getStatus() == Message.STATUS_RECEIVED
&& (message.trusted() || message.getType() == Message.TYPE_PRIVATE) && (message.trusted() || message.isPrivateMessage())
&& remoteMsgId != null && remoteMsgId != null
&& !selfAddressed && !selfAddressed
&& !isTypeGroupChat) { && !isTypeGroupChat) {

View File

@ -812,14 +812,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (internal) { if (internal) {
final String name = file.getName(); final String name = file.getName();
if (name.endsWith(".pgp")) { if (name.endsWith(".pgp")) {
selection = "(" + Message.RELATIVE_FILE_PATH + " IN(?,?) OR (" + Message.RELATIVE_FILE_PATH + "=? and encryption in(1,4))) and type in (1,2)"; selection = "(" + Message.RELATIVE_FILE_PATH + " IN(?,?) OR (" + Message.RELATIVE_FILE_PATH + "=? and encryption in(1,4))) and type in (1,2,5)";
selectionArgs = new String[]{file.getAbsolutePath(), name, name.substring(0, name.length() - 4)}; selectionArgs = new String[]{file.getAbsolutePath(), name, name.substring(0, name.length() - 4)};
} else { } else {
selection = Message.RELATIVE_FILE_PATH + " IN(?,?) and type in (1,2)"; selection = Message.RELATIVE_FILE_PATH + " IN(?,?) and type in (1,2,5)";
selectionArgs = new String[]{file.getAbsolutePath(), name}; selectionArgs = new String[]{file.getAbsolutePath(), name};
} }
} else { } else {
selection = Message.RELATIVE_FILE_PATH + "=? and type in (1,2)"; selection = Message.RELATIVE_FILE_PATH + "=? and type in (1,2,5)";
selectionArgs = new String[]{file.getAbsolutePath()}; selectionArgs = new String[]{file.getAbsolutePath()};
} }
final List<String> uuids = new ArrayList<>(); final List<String> uuids = new ArrayList<>();
@ -862,7 +862,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePathInfo> getFilePathInfo() { public List<FilePathInfo> getFilePathInfo() {
final SQLiteDatabase db = this.getReadableDatabase(); final SQLiteDatabase db = this.getReadableDatabase();
final Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID, Message.RELATIVE_FILE_PATH, Message.DELETED}, "type in (1,2) and "+Message.RELATIVE_FILE_PATH+" is not null", null, null, null, null); final Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID, Message.RELATIVE_FILE_PATH, Message.DELETED}, "type in (1,2,5) and "+Message.RELATIVE_FILE_PATH+" is not null", null, null, null, null);
final List<FilePathInfo> list = new ArrayList<>(); final List<FilePathInfo> list = new ArrayList<>();
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
list.add(new FilePathInfo(cursor.getString(0), cursor.getString(1), cursor.getInt(2) > 0)); list.add(new FilePathInfo(cursor.getString(0), cursor.getString(1), cursor.getInt(2) > 0));
@ -875,7 +875,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) { public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
final String SQL = "select uuid,relativeFilePath from messages where type in (1,2) and deleted=0 and "+Message.RELATIVE_FILE_PATH+" is not null and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc"; final String SQL = "select uuid,relativeFilePath from messages where type in (1,2,5) and deleted=0 and "+Message.RELATIVE_FILE_PATH+" is not null and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc";
final String[] args = {account, jid.toEscapedString(), jid.toEscapedString() + "/%"}; final String[] args = {account, jid.toEscapedString(), jid.toEscapedString() + "/%"};
Cursor cursor = db.rawQuery(SQL + (limit > 0 ? " limit " + String.valueOf(limit) : ""), args); Cursor cursor = db.rawQuery(SQL + (limit > 0 ? " limit " + String.valueOf(limit) : ""), args);
List<FilePath> filesPaths = new ArrayList<>(); List<FilePath> filesPaths = new ArrayList<>();

View File

@ -1178,6 +1178,7 @@ public class FileBackend {
public void updateFileParams(Message message, URL url) { public void updateFileParams(Message message, URL url) {
DownloadableFile file = getFile(message); DownloadableFile file = getFile(message);
final String mime = file.getMimeType(); final String mime = file.getMimeType();
final boolean privateMessage = message.isPrivateMessage();
final boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/")); final boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
final boolean video = mime != null && mime.startsWith("video/"); final boolean video = mime != null && mime.startsWith("video/");
final boolean audio = mime != null && mime.startsWith("audio/"); final boolean audio = mime != null && mime.startsWith("audio/");
@ -1201,7 +1202,7 @@ public class FileBackend {
} }
message.setBody(body.toString()); message.setBody(body.toString());
message.setDeleted(false); message.setDeleted(false);
message.setType(image ? Message.TYPE_IMAGE : Message.TYPE_FILE); message.setType(privateMessage ? Message.TYPE_PRIVATE_FILE : (image ? Message.TYPE_IMAGE : Message.TYPE_FILE));
} }

View File

@ -868,7 +868,7 @@ public class NotificationService {
return false; return false;
} }
final Matcher m = highlight.matcher(message.getBody()); final Matcher m = highlight.matcher(message.getBody());
return (m.find() || message.getType() == Message.TYPE_PRIVATE); return (m.find() || message.isPrivateMessage());
} else { } else {
return false; return false;
} }

View File

@ -487,9 +487,7 @@ public class XmppConnectionService extends Service {
encryption = Message.ENCRYPTION_DECRYPTED; encryption = Message.ENCRYPTION_DECRYPTED;
} }
Message message = new Message(conversation, uri.toString(), encryption); Message message = new Message(conversation, uri.toString(), encryption);
if (conversation.getNextCounterpart() != null) { Message.configurePrivateMessage(message);
message.setCounterpart(conversation.getNextCounterpart());
}
if (encryption == Message.ENCRYPTION_DECRYPTED) { if (encryption == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback); getPgpEngine().encrypt(message, callback);
} else { } else {
@ -505,8 +503,12 @@ public class XmppConnectionService extends Service {
} else { } else {
message = new Message(conversation, "", conversation.getNextEncryption()); message = new Message(conversation, "", conversation.getNextEncryption());
} }
if (!Message.configurePrivateFileMessage(message)) {
message.setCounterpart(conversation.getNextCounterpart()); message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE); message.setType(Message.TYPE_FILE);
}
Log.d(Config.LOGTAG,"attachFile: type="+message.getType());
Log.d(Config.LOGTAG,"counterpart="+message.getCounterpart());
final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, type, message, callback); final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, type, message, callback);
if (runnable.isVideoMessage()) { if (runnable.isVideoMessage()) {
mVideoCompressionExecutor.execute(runnable); mVideoCompressionExecutor.execute(runnable);
@ -533,8 +535,11 @@ public class XmppConnectionService extends Service {
} else { } else {
message = new Message(conversation, "", conversation.getNextEncryption()); message = new Message(conversation, "", conversation.getNextEncryption());
} }
if (!Message.configurePrivateFileMessage(message)) {
message.setCounterpart(conversation.getNextCounterpart()); message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE); message.setType(Message.TYPE_IMAGE);
}
Log.d(Config.LOGTAG,"attachImage: type="+message.getType());
mFileAddingExecutor.execute(() -> { mFileAddingExecutor.execute(() -> {
try { try {
getFileBackend().copyImageToPrivateStorage(message, uri); getFileBackend().copyImageToPrivateStorage(message, uri);
@ -1431,7 +1436,7 @@ public class XmppConnectionService extends Service {
} }
boolean mucMessage = conversation.getMode() == Conversation.MODE_MULTI && message.getType() != Message.TYPE_PRIVATE; boolean mucMessage = conversation.getMode() == Conversation.MODE_MULTI && !message.isPrivateMessage();
if (mucMessage) { if (mucMessage) {
message.setCounterpart(conversation.getMucOptions().getSelf().getFullJid()); message.setCounterpart(conversation.getMucOptions().getSelf().getFullJid());
} }
@ -1466,6 +1471,7 @@ public class XmppConnectionService extends Service {
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState())); packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
} }
} }
Log.d(Config.LOGTAG,packet.toString());
sendMessagePacket(account, packet); sendMessagePacket(account, packet);
} }
} }

View File

@ -728,14 +728,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final Message message; final Message message;
if (conversation.getCorrectingMessage() == null) { if (conversation.getCorrectingMessage() == null) {
message = new Message(conversation, body, conversation.getNextEncryption()); message = new Message(conversation, body, conversation.getNextEncryption());
if (conversation.getMode() == Conversation.MODE_MULTI) { Message.configurePrivateMessage(message);
final Jid nextCounterpart = conversation.getNextCounterpart();
if (nextCounterpart != null) {
message.setCounterpart(nextCounterpart);
message.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(nextCounterpart));
message.setType(Message.TYPE_PRIVATE);
}
}
} else { } else {
message = conversation.getCorrectingMessage(); message = conversation.getCorrectingMessage();
message.setBody(body); message.setBody(body);

View File

@ -32,6 +32,8 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.common.base.Strings;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -70,6 +72,7 @@ import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.StylingHelper; import eu.siacs.conversations.utils.StylingHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.mam.MamReference;
import rocks.xmpp.addr.Jid;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler { public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
@ -439,7 +442,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
body.setSpan(new DividerSpan(true), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); body.setSpan(new DividerSpan(true), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
boolean startsWithQuote = handleTextQuotes(body, darkBackground); boolean startsWithQuote = handleTextQuotes(body, darkBackground);
if (message.getType() != Message.TYPE_PRIVATE) { if (!message.isPrivateMessage()) {
if (hasMeCommand) { if (hasMeCommand) {
body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(), body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
@ -449,13 +452,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
if (message.getStatus() <= Message.STATUS_RECEIVED) { if (message.getStatus() <= Message.STATUS_RECEIVED) {
privateMarker = activity.getString(R.string.private_message); privateMarker = activity.getString(R.string.private_message);
} else { } else {
final String to; Jid cp = message.getCounterpart();
if (message.getCounterpart() != null) { privateMarker = activity.getString(R.string.private_message_to, Strings.nullToEmpty(cp == null ? null : cp.getResource()));
to = message.getCounterpart().getResource();
} else {
to = "";
}
privateMarker = activity.getString(R.string.private_message_to, to);
} }
body.insert(0, privateMarker); body.insert(0, privateMarker);
int privateMarkerIndex = privateMarker.length(); int privateMarkerIndex = privateMarker.length();
@ -506,27 +504,27 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
} }
private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(text); viewHolder.download_button.setText(text);
viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity, message)); viewHolder.download_button.setOnClickListener(v -> ConversationFragment.downloadFile(activity, message));
} }
private void displayOpenableMessage(ViewHolder viewHolder, final Message message) { private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message))); viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message)));
viewHolder.download_button.setOnClickListener(v -> openDownloadable(message)); viewHolder.download_button.setOnClickListener(v -> openDownloadable(message));
} }
private void displayLocationMessage(ViewHolder viewHolder, final Message message) { private void displayLocationMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setVisibility(View.VISIBLE);
viewHolder.download_button.setText(R.string.show_location); viewHolder.download_button.setText(R.string.show_location);
@ -534,8 +532,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) { private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.image.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.GONE);
final RelativeLayout audioPlayer = viewHolder.audioPlayer; final RelativeLayout audioPlayer = viewHolder.audioPlayer;
audioPlayer.setVisibility(View.VISIBLE); audioPlayer.setVisibility(View.VISIBLE);
@ -543,9 +541,9 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
this.audioPlayer.init(audioPlayer, message); this.audioPlayer.init(audioPlayer, message);
} }
private void displayImageMessage(ViewHolder viewHolder, final Message message) { private void displayImageMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, darkBackground);
viewHolder.download_button.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.VISIBLE); viewHolder.image.setVisibility(View.VISIBLE);
FileParams params = message.getFileParams(); FileParams params = message.getFileParams();
@ -572,6 +570,25 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.image.setOnClickListener(v -> openDownloadable(message)); viewHolder.image.setOnClickListener(v -> openDownloadable(message));
} }
private void toggleWhisperInfo(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
if (message.isPrivateMessage()) {
final String privateMarker;
if (message.getStatus() <= Message.STATUS_RECEIVED) {
privateMarker = activity.getString(R.string.private_message);
} else {
Jid cp = message.getCounterpart();
privateMarker = activity.getString(R.string.private_message_to, Strings.nullToEmpty(cp == null ? null : cp.getResource()));
}
final SpannableString body = new SpannableString(privateMarker);
body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
body.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
viewHolder.messageBody.setText(body);
viewHolder.messageBody.setVisibility(View.VISIBLE);
} else {
viewHolder.messageBody.setVisibility(View.GONE);
}
}
private void loadMoreMessages(Conversation conversation) { private void loadMoreMessages(Conversation conversation) {
conversation.setLastClearHistory(0, null); conversation.setLastClearHistory(0, null);
activity.xmppConnectionService.updateConversation(conversation); activity.xmppConnectionService.updateConversation(conversation);
@ -722,19 +739,19 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
final Transferable transferable = message.getTransferable(); final Transferable transferable = message.getTransferable();
if (message.isDeleted() || (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING)) { if (message.isDeleted() || (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING)) {
if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER) { if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER) {
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message))); displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)), darkBackground);
} else if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) { } else if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message))); displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)), darkBackground);
} else { } else {
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground); displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground);
} }
} else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
if (message.getFileParams().width > 0 && message.getFileParams().height > 0) { if (message.getFileParams().width > 0 && message.getFileParams().height > 0) {
displayImageMessage(viewHolder, message); displayImageMessage(viewHolder, message, darkBackground);
} else if (message.getFileParams().runtime > 0) { } else if (message.getFileParams().runtime > 0) {
displayAudioMessage(viewHolder, message, darkBackground); displayAudioMessage(viewHolder, message, darkBackground);
} else { } else {
displayOpenableMessage(viewHolder, message); displayOpenableMessage(viewHolder, message, darkBackground);
} }
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) { } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
if (account.isPgpDecryptionServiceConnected()) { if (account.isPgpDecryptionServiceConnected()) {
@ -756,7 +773,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
displayInfoMessage(viewHolder, activity.getString(R.string.omemo_decryption_failed), darkBackground); displayInfoMessage(viewHolder, activity.getString(R.string.omemo_decryption_failed), darkBackground);
} else { } else {
if (message.isGeoUri()) { if (message.isGeoUri()) {
displayLocationMessage(viewHolder, message); displayLocationMessage(viewHolder, message, darkBackground);
} else if (message.bodyIsOnlyEmojis() && message.getType() != Message.TYPE_PRIVATE) { } else if (message.bodyIsOnlyEmojis() && message.getType() != Message.TYPE_PRIVATE) {
displayEmojiMessage(viewHolder, message.getBody().trim(), darkBackground); displayEmojiMessage(viewHolder, message.getBody().trim(), darkBackground);
} else if (message.treatAsDownloadable()) { } else if (message.treatAsDownloadable()) {
@ -766,19 +783,22 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
displayDownloadableMessage(viewHolder, displayDownloadableMessage(viewHolder,
message, message,
activity.getString(R.string.check_x_filesize, activity.getString(R.string.check_x_filesize,
UIHelper.getFileDescriptionString(activity, message))); UIHelper.getFileDescriptionString(activity, message)),
darkBackground);
} else { } else {
displayDownloadableMessage(viewHolder, displayDownloadableMessage(viewHolder,
message, message,
activity.getString(R.string.check_x_filesize_on_host, activity.getString(R.string.check_x_filesize_on_host,
UIHelper.getFileDescriptionString(activity, message), UIHelper.getFileDescriptionString(activity, message),
url.getHost())); url.getHost()),
darkBackground);
} }
} catch (Exception e) { } catch (Exception e) {
displayDownloadableMessage(viewHolder, displayDownloadableMessage(viewHolder,
message, message,
activity.getString(R.string.check_x_filesize, activity.getString(R.string.check_x_filesize,
UIHelper.getFileDescriptionString(activity, message))); UIHelper.getFileDescriptionString(activity, message)),
darkBackground);
} }
} else { } else {
displayTextMessage(viewHolder, message, darkBackground, type); displayTextMessage(viewHolder, message, darkBackground, type);

View File

@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"> <merge xmlns:android="http://schemas.android.com/apk/res/android">
<eu.siacs.conversations.ui.widget.CopyTextView
android:id="@+id/message_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/>
<ImageView <ImageView
android:id="@+id/message_image" android:id="@+id/message_image"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -12,14 +20,6 @@
android:longClickable="true" android:longClickable="true"
android:scaleType="centerCrop"/> android:scaleType="centerCrop"/>
<eu.siacs.conversations.ui.widget.CopyTextView
android:id="@+id/message_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:longClickable="true"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/>
<Button <Button
android:id="@+id/download_button" android:id="@+id/download_button"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"