XmppConnectionService.markMessage moved to MessageUtil

XmppConnectionService.attachLocationToConversation moved to ConversationUtil
This commit is contained in:
steckbrief 2016-05-09 20:41:58 +02:00
parent b789ace386
commit 10e607ac51
13 changed files with 132 additions and 108 deletions

View file

@ -33,12 +33,18 @@ import de.thedevstack.conversationsplus.ui.UiCallback;
public class PgpEngine { public class PgpEngine {
private OpenPgpApi api; private OpenPgpApi api;
private XmppConnectionService mXmppConnectionService; private XmppConnectionService mXmppConnectionService;
private static PgpEngine INSTANCE;
public PgpEngine(OpenPgpApi api, XmppConnectionService service) { public PgpEngine(OpenPgpApi api, XmppConnectionService service) {
this.api = api; this.api = api;
this.mXmppConnectionService = service; this.mXmppConnectionService = service;
INSTANCE = this;
} }
public static PgpEngine getInstance() {
return INSTANCE;
}
public void decrypt(final Message message, final UiCallback<Message> callback) { public void decrypt(final Message message, final UiCallback<Message> callback) {
Intent params = new Intent(); Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);

View file

@ -41,6 +41,7 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.parser.IqParser; import de.thedevstack.conversationsplus.parser.IqParser;
import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.SerialSingleThreadExecutor; import de.thedevstack.conversationsplus.utils.SerialSingleThreadExecutor;
import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.OnAdvancedStreamFeaturesLoaded; import de.thedevstack.conversationsplus.xmpp.OnAdvancedStreamFeaturesLoaded;
@ -946,7 +947,7 @@ public class AxolotlServiceImpl implements OnAdvancedStreamFeaturesLoaded, Axolo
public void run() { public void run() {
XmppAxolotlMessage axolotlMessage = encrypt(message); XmppAxolotlMessage axolotlMessage = encrypt(message);
if (axolotlMessage == null) { if (axolotlMessage == null) {
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); MessageUtil.markMessage(message, Message.STATUS_SEND_FAILED);
//mXmppConnectionService.updateConversationUi(); //mXmppConnectionService.updateConversationUi();
} else { } else {
Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Generated message, caching: " + message.getUuid()); Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(account) + "Generated message, caching: " + message.getUuid());

View file

@ -91,7 +91,7 @@ public class HttpUploadConnection implements Transferable {
private void fail() { private void fail() {
mHttpConnectionManager.finishUploadConnection(this); mHttpConnectionManager.finishUploadConnection(this);
message.setTransferable(null); message.setTransferable(null);
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); MessageUtil.markMessage(message, Message.STATUS_SEND_FAILED);
StreamUtil.close(mFileInputStream); StreamUtil.close(mFileInputStream);
} }
@ -145,7 +145,7 @@ public class HttpUploadConnection implements Transferable {
} }
}); });
message.setTransferable(this); message.setTransferable(this);
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND); MessageUtil.markMessage(message, Message.STATUS_UNSEND);
} }
private class FileUploader implements Runnable { private class FileUploader implements Runnable {

View file

@ -3,6 +3,7 @@ package de.thedevstack.conversationsplus.parser;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint; import de.thedevstack.conversationsplus.xmpp.httpuploadim.HttpUploadHint;
import de.tzur.conversations.Settings; import de.tzur.conversations.Settings;
@ -343,12 +344,12 @@ public class MessageParser extends AbstractParser implements
if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) { if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
status = Message.STATUS_SEND_RECEIVED; status = Message.STATUS_SEND_RECEIVED;
isCarbon = true; //not really carbon but received from another resource isCarbon = true; //not really carbon but received from another resource
if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) { if (MessageUtil.markMessage(conversation, remoteMsgId, status)) {
return; return;
} else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) { } else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) {
Message message = conversation.findSentMessageWithBody(packet.getBody()); Message message = conversation.findSentMessageWithBody(packet.getBody());
if (message != null) { if (message != null) {
mXmppConnectionService.markMessage(message, status); MessageUtil.markMessage(message, status);
return; return;
} }
} }
@ -535,7 +536,7 @@ public class MessageParser extends AbstractParser implements
while (message != null while (message != null
&& message.getStatus() == Message.STATUS_SEND_RECEIVED && message.getStatus() == Message.STATUS_SEND_RECEIVED
&& message.getTimeSent() < displayedMessage.getTimeSent()) { && message.getTimeSent() < displayedMessage.getTimeSent()) {
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED); MessageUtil.markMessage(message, Message.STATUS_SEND_DISPLAYED);
message = message.prev(); message = message.prev();
} }
} }

View file

@ -217,7 +217,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (conversation.getAccount() == account) { if (conversation.getAccount() == account) {
Message message = conversation.findUnsentMessageWithUuid(uuid); Message message = conversation.findUnsentMessageWithUuid(uuid);
if (message != null) { if (message != null) {
markMessage(message, Message.STATUS_SEND); MessageUtil.markMessage(message, Message.STATUS_SEND);
} }
} }
} }
@ -360,64 +360,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
public void attachLocationToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
int encryption = conversation.getNextEncryption();
if (encryption == Message.ENCRYPTION_PGP) {
encryption = Message.ENCRYPTION_DECRYPTED;
}
Message message = new Message(conversation, uri.toString(), encryption);
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
}
if (encryption == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
}
}
public void attachFileToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
final Message message;
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE);
String path = FileUtils.getPath(uri);
if (path != null) {
message.setRelativeFilePath(path);
MessageUtil.updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
}
} else {
ConversationsPlusApplication.executeFileAdding(new Runnable() {
@Override
public void run() {
try {
FileBackend.copyFileToPrivateStorage(message, uri);
MessageUtil.updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
}
} catch (FileCopyException e) {
callback.error(e.getResId(), message);
}
}
});
}
}
public Conversation find(Bookmark bookmark) { public Conversation find(Bookmark bookmark) {
return find(bookmark.getAccount(), bookmark.getJid()); return find(bookmark.getAccount(), bookmark.getJid());
} }
@ -828,7 +770,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
new Conversation.OnMessageFound() { new Conversation.OnMessageFound() {
@Override @Override
public void onMessageFound(Message message) { public void onMessageFound(Message message) {
markMessage(message, Message.STATUS_SEND_FAILED); MessageUtil.markMessage(message, Message.STATUS_SEND_FAILED);
} }
}); });
} }
@ -940,9 +882,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (resend) { if (resend) {
if (packet != null && addToConversation) { if (packet != null && addToConversation) {
if (account.getXmppConnection().getFeatures().sm() || conversation.getMode() == Conversation.MODE_MULTI) { if (account.getXmppConnection().getFeatures().sm() || conversation.getMode() == Conversation.MODE_MULTI) {
markMessage(message, Message.STATUS_UNSEND); MessageUtil.markMessage(message, Message.STATUS_UNSEND);
} else { } else {
markMessage(message, Message.STATUS_SEND); MessageUtil.markMessage(message, Message.STATUS_SEND);
} }
} }
} else { } else {
@ -1158,7 +1100,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
final int s = message.getStatus(); final int s = message.getStatus();
if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) { if (s == Message.STATUS_WAITING || s == Message.STATUS_OFFERED || s == Message.STATUS_UNSEND) {
markMessage(message, Message.STATUS_SEND_FAILED); MessageUtil.markMessage(message, Message.STATUS_SEND_FAILED);
} }
} }
} }
@ -2344,7 +2286,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override @Override
public void onMessageFound(Message message) { public void onMessageFound(Message message) {
markMessage(message, Message.STATUS_WAITING); MessageUtil.markMessage(message, Message.STATUS_WAITING);
} }
}); });
} }
@ -2359,7 +2301,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (conversation.getJid().toBareJid().equals(recipient) && conversation.getAccount() == account) { if (conversation.getJid().toBareJid().equals(recipient) && conversation.getAccount() == account) {
final Message message = conversation.findSentMessageWithUuidOrRemoteId(uuid); final Message message = conversation.findSentMessageWithUuidOrRemoteId(uuid);
if (message != null) { if (message != null) {
markMessage(message, status); MessageUtil.markMessage(message, status);
} }
return message; return message;
} }
@ -2367,24 +2309,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return null; return null;
} }
public boolean markMessage(Conversation conversation, String uuid, int status) {
if (uuid == null) {
return false;
} else {
Message message = conversation.findSentMessageWithUuid(uuid);
if (message != null) {
markMessage(message, status);
return true;
} else {
return false;
}
}
}
public void markMessage(Message message, int status) {
MessageUtil.markMessage(message, status);
}
public int unreadCount() { public int unreadCount() {
int count = 0; int count = 0;
for (Conversation conversation : getConversations()) { for (Conversation conversation : getConversations()) {
@ -2682,7 +2606,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void resendFailedMessages(final Message message) { public void resendFailedMessages(final Message message) {
if (message.getStatus() == Message.STATUS_SEND_FAILED) { if (message.getStatus() == Message.STATUS_SEND_FAILED) {
message.setTime(System.currentTimeMillis()); message.setTime(System.currentTimeMillis());
markMessage(message, Message.STATUS_WAITING); MessageUtil.markMessage(message, Message.STATUS_WAITING);
this.resendMessage(message, false); this.resendMessage(message, false);
} }
} }

View file

@ -47,6 +47,7 @@ import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog; import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener; import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
import de.thedevstack.conversationsplus.utils.ConversationUtil;
import de.timroes.android.listview.EnhancedListView; import de.timroes.android.listview.EnhancedListView;
import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.R;
@ -1420,7 +1421,7 @@ public class ConversationActivity extends XmppActivity
if (conversation == null) { if (conversation == null) {
return; return;
} }
xmppConnectionService.attachLocationToConversation(conversation,uri, new UiCallback<Message>() { ConversationUtil.attachLocationToConversation(conversation,uri, new UiCallback<Message>() {
@Override @Override
public void success(Message message) { public void success(Message message) {
@ -1445,7 +1446,7 @@ public class ConversationActivity extends XmppActivity
} }
final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
prepareFileToast.show(); prepareFileToast.show();
xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() { ConversationUtil.attachFileToConversation(conversation, uri, new UiCallback<Message>() {
@Override @Override
public void success(Message message) { public void success(Message message) {
hidePrepareFileToast(prepareFileToast); hidePrepareFileToast(prepareFileToast);

View file

@ -69,6 +69,7 @@ import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictu
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureLongClicked; import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener; import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener;
import de.thedevstack.conversationsplus.utils.GeoHelper; import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.UIHelper; import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState; import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@ -693,7 +694,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (transferable != null) { if (transferable != null) {
transferable.cancel(); transferable.cancel();
} else { } else {
activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); MessageUtil.markMessage(message, Message.STATUS_SEND_FAILED);
} }
} }

View file

@ -31,6 +31,7 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.persistance.FileBackend; import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter; import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
import de.thedevstack.conversationsplus.utils.ConversationUtil;
import de.thedevstack.conversationsplus.utils.FileUtils; import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@ -300,9 +301,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
@Override @Override
public void onPresenceSelected() { public void onPresenceSelected() {
replaceToast(getString(R.string.preparing_file)); replaceToast(getString(R.string.preparing_file));
ShareWithActivity.this.xmppConnectionService ConversationUtil.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback);
.attachFileToConversation(conversation, share.uris.get(0),
attachFileCallback);
switchToConversation(conversation, null, true); switchToConversation(conversation, null, true);
finish(); finish();
} }

View file

@ -13,6 +13,7 @@ import java.io.InputStream;
import de.thedevstack.android.logcat.Logging; import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.crypto.PgpEngine;
import de.thedevstack.conversationsplus.enums.UserDecision; import de.thedevstack.conversationsplus.enums.UserDecision;
import de.thedevstack.conversationsplus.exceptions.UiException; import de.thedevstack.conversationsplus.exceptions.UiException;
import de.thedevstack.conversationsplus.utils.FileUtils; import de.thedevstack.conversationsplus.utils.FileUtils;
@ -29,7 +30,7 @@ import de.thedevstack.conversationsplus.ui.XmppActivity;
import de.thedevstack.conversationsplus.utils.StreamUtil; import de.thedevstack.conversationsplus.utils.StreamUtil;
/** /**
* Created by tzur on 31.10.2015. * Listener to let the user decide whether to resize a picture before sending or not.
*/ */
public class ResizePictureUserDecisionListener implements UserDecisionListener { public class ResizePictureUserDecisionListener implements UserDecisionListener {
protected Uri uri; protected Uri uri;
@ -156,7 +157,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
String filePath = FileUtils.getPath(uri); String filePath = FileUtils.getPath(uri);
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight); MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback); PgpEngine.getInstance().encrypt(message, callback);
} else { } else {
callback.success(message); callback.success(message);
} }
@ -195,7 +196,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
int imageHeight = resizedAndRotatedImage.getHeight(); int imageHeight = resizedAndRotatedImage.getHeight();
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight); MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback); PgpEngine.getInstance().encrypt(message, callback);
} else { } else {
callback.success(message); callback.success(message);
} }

View file

@ -0,0 +1,75 @@
package de.thedevstack.conversationsplus.utils;
import android.net.Uri;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.crypto.PgpEngine;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.exceptions.FileCopyException;
import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.ui.UiCallback;
/**
* Utility class to work with conversations.
*/
public class ConversationUtil {
public static void attachLocationToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
int encryption = conversation.getNextEncryption();
if (encryption == Message.ENCRYPTION_PGP) {
encryption = Message.ENCRYPTION_DECRYPTED;
}
Message message = new Message(conversation, uri.toString(), encryption);
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
}
if (encryption == Message.ENCRYPTION_DECRYPTED) {
PgpEngine.getInstance().encrypt(message, callback);
} else {
callback.success(message);
}
}
public static void attachFileToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
final Message message;
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE);
String path = FileUtils.getPath(uri);
if (path != null) {
message.setRelativeFilePath(path);
MessageUtil.updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
PgpEngine.getInstance().encrypt(message, callback);
} else {
callback.success(message);
}
} else {
ConversationsPlusApplication.executeFileAdding(new Runnable() {
@Override
public void run() {
try {
FileBackend.copyFileToPrivateStorage(message, uri);
MessageUtil.updateFileParams(message);
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
PgpEngine.getInstance().encrypt(message, callback);
} else {
callback.success(message);
}
} catch (FileCopyException e) {
callback.error(e.getResId(), message);
}
}
});
}
}
}

View file

@ -7,6 +7,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.persistance.DatabaseBackend; import de.thedevstack.conversationsplus.persistance.DatabaseBackend;
@ -17,6 +18,21 @@ import de.thedevstack.conversationsplus.persistance.FileBackend;
*/ */
public final class MessageUtil { public final class MessageUtil {
public static boolean markMessage(Conversation conversation, String uuid, int status) {
if (uuid == null) {
return false;
} else {
Message message = conversation.findSentMessageWithUuid(uuid);
if (message != null) {
markMessage(message, status);
return true;
} else {
return false;
}
}
}
public static void markMessage(Message message, int status) { public static void markMessage(Message message, int status) {
if (status == Message.STATUS_SEND_FAILED if (status == Message.STATUS_SEND_FAILED
&& (message.getStatus() == Message.STATUS_SEND_RECEIVED || message && (message.getStatus() == Message.STATUS_SEND_RECEIVED || message

View file

@ -103,7 +103,7 @@ public class JingleConnection implements Transferable {
sendSuccess(); sendSuccess();
MessageUtil.updateFileParams(message); MessageUtil.updateFileParams(message);
mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.markMessage(message,Message.STATUS_RECEIVED); MessageUtil.markMessage(message,Message.STATUS_RECEIVED);
if (acceptedAutomatically) { if (acceptedAutomatically) {
message.markUnread(); message.markUnread();
JingleConnection.this.mXmppConnectionService.getNotificationService().push(message); JingleConnection.this.mXmppConnectionService.getNotificationService().push(message);
@ -457,7 +457,7 @@ public class JingleConnection implements Transferable {
if (packet.getType() == IqPacket.TYPE.RESULT) { if (packet.getType() == IqPacket.TYPE.RESULT) {
Logging.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer"); Logging.d(Config.LOGTAG,account.getJid().toBareJid()+": other party received offer");
mJingleStatus = JINGLE_STATUS_INITIATED; mJingleStatus = JINGLE_STATUS_INITIATED;
mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); MessageUtil.markMessage(message, Message.STATUS_OFFERED);
} else { } else {
fail(); fail();
} }
@ -548,7 +548,7 @@ public class JingleConnection implements Transferable {
mergeCandidates(JingleCandidate.parse(content.socks5transport() mergeCandidates(JingleCandidate.parse(content.socks5transport()
.getChildren())); .getChildren()));
this.mJingleStatus = JINGLE_STATUS_ACCEPTED; this.mJingleStatus = JINGLE_STATUS_ACCEPTED;
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND); MessageUtil.markMessage(message, Message.STATUS_UNSEND);
this.connectNextCandidate(); this.connectNextCandidate();
return true; return true;
} }
@ -780,7 +780,7 @@ public class JingleConnection implements Transferable {
private void receiveSuccess() { private void receiveSuccess() {
this.mJingleStatus = JINGLE_STATUS_FINISHED; this.mJingleStatus = JINGLE_STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message,Message.STATUS_SEND_RECEIVED); MessageUtil.markMessage(this.message,Message.STATUS_SEND_RECEIVED);
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport != null && this.transport instanceof JingleInbandTransport) { if (this.transport != null && this.transport instanceof JingleInbandTransport) {
this.transport.disconnect(); this.transport.disconnect();
@ -803,8 +803,7 @@ public class JingleConnection implements Transferable {
} }
this.mXmppConnectionService.updateConversationUi(); this.mXmppConnectionService.updateConversationUi();
} else { } else {
this.mXmppConnectionService.markMessage(this.message, MessageUtil.markMessage(this.message, Message.STATUS_SEND_FAILED);
Message.STATUS_SEND_FAILED);
this.message.setTransferable(null); this.message.setTransferable(null);
} }
} }
@ -825,8 +824,7 @@ public class JingleConnection implements Transferable {
} }
this.mXmppConnectionService.updateConversationUi(); this.mXmppConnectionService.updateConversationUi();
} else { } else {
this.mXmppConnectionService.markMessage(this.message, MessageUtil.markMessage(this.message, Message.STATUS_SEND_FAILED);
Message.STATUS_SEND_FAILED);
this.message.setTransferable(null); this.message.setTransferable(null);
} }
} }

View file

@ -15,6 +15,7 @@ import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.Transferable; import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.services.AbstractConnectionManager; import de.thedevstack.conversationsplus.services.AbstractConnectionManager;
import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.Xmlns; import de.thedevstack.conversationsplus.utils.Xmlns;
import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived; import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived;
@ -65,7 +66,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
old.cancel(); old.cancel();
} }
JingleConnection connection = new JingleConnection(this); JingleConnection connection = new JingleConnection(this);
mXmppConnectionService.markMessage(message,Message.STATUS_WAITING); MessageUtil.markMessage(message,Message.STATUS_WAITING);
connection.init(message); connection.init(message);
this.connections.add(connection); this.connections.add(connection);
return connection; return connection;