aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java23
-rw-r--r--src/main/java/de/pixart/messenger/http/HttpUploadConnection.java17
-rw-r--r--src/main/java/de/pixart/messenger/parser/AbstractParser.java14
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java16
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java7
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java16
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java15
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java12
-rw-r--r--src/main/res/menu/message_context.xml4
-rw-r--r--src/main/res/values/strings.xml2
10 files changed, 98 insertions, 28 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 5ec1abd65..7bd61c5b9 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -58,6 +58,7 @@ public class Message extends AbstractEntity {
public static final String RELATIVE_FILE_PATH = "relativeFilePath";
public static final String FINGERPRINT = "axolotl_fingerprint";
public static final String READ = "read";
+ public static final String ERROR_MESSAGE = "errorMsg";
public static final String ME_COMMAND = "/me ";
@@ -83,6 +84,7 @@ public class Message extends AbstractEntity {
private Message mNextMessage = null;
private Message mPreviousMessage = null;
private String axolotlFingerprint = null;
+ private String errorMessage = null;
private Message() {
@@ -109,7 +111,8 @@ public class Message extends AbstractEntity {
null,
true,
null,
- false);
+ false,
+ null);
this.conversation = conversation;
}
@@ -118,7 +121,7 @@ public class Message extends AbstractEntity {
final int encryption, final int status, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath,
final String serverMsgId, final String fingerprint, final boolean read,
- final String edited, final boolean oob) {
+ final String edited, final boolean oob, final String errorMessage) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -136,6 +139,7 @@ public class Message extends AbstractEntity {
this.read = read;
this.edited = edited;
this.oob = oob;
+ this.errorMessage = errorMessage;
}
public static Message fromCursor(Cursor cursor) {
@@ -177,7 +181,8 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
cursor.getInt(cursor.getColumnIndex(READ)) > 0,
cursor.getString(cursor.getColumnIndex(EDITED)),
- cursor.getInt(cursor.getColumnIndex(OOB)) > 0);
+ cursor.getInt(cursor.getColumnIndex(OOB)) > 0,
+ cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)));
}
public static Message createStatusMessage(Conversation conversation, String body) {
@@ -224,6 +229,7 @@ public class Message extends AbstractEntity {
values.put(READ, read ? 1 : 0);
values.put(EDITED, edited);
values.put(OOB, oob ? 1 : 0);
+ values.put(ERROR_MESSAGE,errorMessage);
return values;
}
@@ -271,6 +277,17 @@ public class Message extends AbstractEntity {
this.body = body;
}
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public boolean setErrorMessage(String message) {
+ boolean changed = (message != null && !message.equals(errorMessage))
+ || (message == null && errorMessage != null);
+ this.errorMessage = message;
+ return changed;
+ }
+
public long getTimeSent() {
return timeSent;
}
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
index d12dde80e..95f840d67 100644
--- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
+++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java
@@ -20,6 +20,7 @@ import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.DownloadableFile;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.Transferable;
+import de.pixart.messenger.parser.IqParser;
import de.pixart.messenger.persistance.FileBackend;
import de.pixart.messenger.services.AbstractConnectionManager;
import de.pixart.messenger.services.XmppConnectionService;
@@ -86,10 +87,10 @@ public class HttpUploadConnection implements Transferable {
this.canceled = true;
}
- private void fail() {
+ private void fail(String errorMessage) {
mHttpConnectionManager.finishUploadConnection(this);
message.setTransferable(null);
- mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
+ mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, errorMessage);
FileBackend.close(mFileInputStream);
}
@@ -111,7 +112,7 @@ public class HttpUploadConnection implements Transferable {
pair = AbstractConnectionManager.createInputStream(file, true);
} catch (FileNotFoundException e) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not find file to upload - "+e.getMessage());
- fail();
+ fail(e.getMessage());
return;
}
if (pair != null) {
@@ -139,7 +140,7 @@ public class HttpUploadConnection implements Transferable {
}
}
Log.d(Config.LOGTAG,account.getJid().toString()+": invalid response to slot request "+packet);
- fail();
+ fail(IqParser.extractErrorMessage(packet));
}
});
message.setTransferable(this);
@@ -208,12 +209,12 @@ public class HttpUploadConnection implements Transferable {
@Override
public void error(int errorCode, Message object) {
Log.d(Config.LOGTAG,"pgp encryption failed");
- fail();
+ fail("pgp encryption failed");
}
@Override
public void userInputRequried(PendingIntent pi, Message object) {
- fail();
+ fail("pgp encryption failed");
}
});
} else {
@@ -221,12 +222,12 @@ public class HttpUploadConnection implements Transferable {
}
} else {
Log.d(Config.LOGTAG,"http upload failed because response code was "+code);
- fail();
+ fail("http upload failed because response code was "+code);
}
} catch (IOException e) {
e.printStackTrace();
Log.d(Config.LOGTAG,"http upload failed "+e.getMessage());
- fail();
+ fail(e.getMessage());
} finally {
FileBackend.close(mFileInputStream);
FileBackend.close(os);
diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
index 937327261..f67a00a76 100644
--- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java
+++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
@@ -92,4 +92,18 @@ public abstract class AbstractParser {
user.setRole(role);
return user;
}
+
+ public static String extractErrorMessage(Element packet) {
+ final Element error = packet.findChild("error");
+ if (error != null && error.getChildren().size() > 0) {
+ final String text = error.findChildContent("text");
+ if (text != null && !text.trim().isEmpty()) {
+ return text;
+ } else {
+ return error.getChildren().get(0).getName().replace("-"," ");
+ }
+ } else {
+ return null;
+ }
+ }
}
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 4b6428514..d03638f85 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -266,19 +266,15 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (packet.getType() == MessagePacket.TYPE_ERROR) {
Jid from = packet.getFrom();
if (from != null) {
- Element error = packet.findChild("error");
- String text = error == null ? null : error.findChildContent("text");
- if (text != null) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + text);
- } else if (error != null) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + error);
- }
Message message = mXmppConnectionService.markMessage(account,
from.toBareJid(),
packet.getId(),
- Message.STATUS_SEND_FAILED);
- if (message != null && message.getEncryption() == Message.ENCRYPTION_OTR) {
- message.getConversation().endOtrIfNeeded();
+ Message.STATUS_SEND_FAILED,
+ extractErrorMessage(packet));
+ if (message != null) {
+ if (message.getEncryption() == Message.ENCRYPTION_OTR) {
+ message.getConversation().endOtrIfNeeded();
+ }
}
}
return true;
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index cf771bead..63f6bb783 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -53,7 +53,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
public static final String DATABASE_NAME = "history";
- public static final int DATABASE_VERSION = 28;
+ public static final int DATABASE_VERSION = 29;
private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@@ -180,6 +180,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Message.EDITED + " TEXT, "
+ Message.READ + " NUMBER DEFAULT 1, "
+ Message.OOB + " INTEGER, "
+ + Message.ERROR_MESSAGE + " TEXT,"
+ Message.REMOTE_MSG_ID + " TEXT, FOREIGN KEY("
+ Message.CONVERSATION + ") REFERENCES "
+ Conversation.TABLENAME + "(" + Conversation.UUID
@@ -332,6 +333,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (oldVersion < 28 && newVersion >= 28) {
canonicalizeJids(db);
}
+
+ if (oldVersion < 29 && newVersion >= 29) {
+ db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.ERROR_MESSAGE + " TEXT");
+ }
}
private void canonicalizeJids(SQLiteDatabase db) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index d586bdd3f..993a6499e 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -3085,14 +3085,18 @@ public class XmppConnectionService extends Service {
}
public Message markMessage(final Account account, final Jid recipient, final String uuid, final int status) {
- if (uuid == null) {
+ return markMessage(account, recipient, uuid, status, null);
+ }
+
+ public Message markMessage(final Account account, final Jid recipient, final String uuid, final int status, String errorMessage) {
+ if (uuid == null) {
return null;
}
for (Conversation conversation : getConversations()) {
if (conversation.getJid().toBareJid().equals(recipient) && conversation.getAccount() == account) {
final Message message = conversation.findSentMessageWithUuidOrRemoteId(uuid);
if (message != null) {
- markMessage(message, status);
+ markMessage(message, status, errorMessage);
}
return message;
}
@@ -3115,11 +3119,17 @@ public class XmppConnectionService extends Service {
}
public void markMessage(Message message, int status) {
+ markMessage(message, status, null);
+ }
+
+ public void markMessage(Message message, int status, String errorMessage) {
if (status == Message.STATUS_SEND_FAILED
&& (message.getStatus() == Message.STATUS_SEND_RECEIVED || message
- .getStatus() == Message.STATUS_SEND_DISPLAYED)) {
+ .getStatus() == Message.STATUS_SEND_DISPLAYED)
+ && errorMessage == null) {
return;
}
+ message.setErrorMessage(errorMessage);
message.setStatus(status);
databaseBackend.updateMessage(message);
updateConversationUi();
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 540a2f952..82702a3c1 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -558,6 +558,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
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);
if (!treatAsFile
&& !GeoHelper.isGeoUri(m.getBody())
&& m.treatAsDownloadable() != Message.Decision.MUST) {
@@ -602,6 +603,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
}
}
+ if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
+ showErrorMessage.setVisible(true);
+ }
}
}
@@ -638,11 +642,22 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.delete_file:
deleteFile(selectedMessage);
return true;
+ case R.id.show_error_message:
+ showErrorMessage(selectedMessage);
+ return true;
default:
return super.onContextItemSelected(item);
}
}
+ private void showErrorMessage(final Message message) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ builder.setTitle(R.string.error_message);
+ builder.setMessage(message.getErrorMessage());
+ builder.setPositiveButton(R.string.ok,null);
+ builder.create().show();
+ }
+
private void shareWith(Message message) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
index 0c8eec2bb..6db0b9787 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java
@@ -27,6 +27,7 @@ import de.pixart.messenger.entities.Presence;
import de.pixart.messenger.entities.ServiceDiscoveryResult;
import de.pixart.messenger.entities.Transferable;
import de.pixart.messenger.entities.TransferablePlaceholder;
+import de.pixart.messenger.parser.IqParser;
import de.pixart.messenger.persistance.FileBackend;
import de.pixart.messenger.services.AbstractConnectionManager;
import de.pixart.messenger.services.XmppConnectionService;
@@ -90,7 +91,7 @@ public class JingleConnection implements Transferable {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.RESULT) {
- fail();
+ fail(IqParser.extractErrorMessage(packet));
}
}
};
@@ -492,7 +493,7 @@ public class JingleConnection implements Transferable {
mJingleStatus = JINGLE_STATUS_INITIATED;
mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
} else {
- fail();
+ fail(IqParser.extractErrorMessage(packet));
}
}
});
@@ -850,6 +851,10 @@ public class JingleConnection implements Transferable {
}
private void fail() {
+ fail(null);
+ }
+
+ private void fail(String errorMessage) {
this.mJingleStatus = JINGLE_STATUS_FAILED;
this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) {
@@ -866,7 +871,8 @@ public class JingleConnection implements Transferable {
this.mXmppConnectionService.updateConversationUi();
} else {
this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_SEND_FAILED);
+ Message.STATUS_SEND_FAILED,
+ errorMessage);
this.message.setTransferable(null);
}
}
diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml
index a17c8c459..7f95d712a 100644
--- a/src/main/res/menu/message_context.xml
+++ b/src/main/res/menu/message_context.xml
@@ -26,6 +26,10 @@
android:title="@string/copy_original_url"
android:visible="false"/>
<item
+ android:id="@+id/show_error_message"
+ android:title="@string/show_error_message"
+ android:visible="false"/>
+ <item
android:id="@+id/send_again"
android:title="@string/send_again"
android:visible="false"/>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 0d4589cb2..97eca53a4 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -716,4 +716,6 @@
<string name="missing_omemo_keys">Missing OMEMO keys</string>
<string name="error_publish_avatar_offline">You need to be connected to publish your avatar.</string>
<string name="select_text">Select text</string>
+ <string name="show_error_message">Show error message</string>
+ <string name="error_message">Error Message</string>
</resources>