mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
code cleanup / unification
This commit is contained in:
parent
b9477edb53
commit
41834b5e24
@ -645,25 +645,24 @@ public class XmppConnectionService extends Service {
|
||||
Account account = message.getConversation().getAccount();
|
||||
Conversation conv = message.getConversation();
|
||||
MessagePacket packet = null;
|
||||
boolean saveInDb = false;
|
||||
boolean addToConversation = false;
|
||||
boolean saveInDb = true;
|
||||
boolean send = false;
|
||||
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||
if (message.getType() == Message.TYPE_IMAGE) {
|
||||
if (message.getPresence() !=null ) {
|
||||
if (message.getPresence() != null) {
|
||||
mJingleConnectionManager.createNewConnection(message);
|
||||
} else {
|
||||
message.setStatus(Message.STATUS_WAITING);
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
}
|
||||
} else {
|
||||
if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
||||
if (!conv.hasValidOtrSession()&&(message.getPresence() != null)) {
|
||||
if (!conv.hasValidOtrSession()
|
||||
&& (message.getPresence() != null)) {
|
||||
// starting otr session. messages will be send later
|
||||
conv.startOtrSession(getApplicationContext(),
|
||||
message.getPresence(), true);
|
||||
} else if (conv.hasValidOtrSession() && conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||
} else if (conv.hasValidOtrSession()
|
||||
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||
// otr session aleary exists, creating message packet
|
||||
// accordingly
|
||||
packet = prepareMessagePacket(account, message,
|
||||
@ -673,8 +672,6 @@ public class XmppConnectionService extends Service {
|
||||
} else if (message.getPresence() == null) {
|
||||
message.setStatus(Message.STATUS_WAITING);
|
||||
}
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||
message.getConversation().endOtrIfNeeded();
|
||||
packet = prepareMessagePacket(account, message, null);
|
||||
@ -683,8 +680,6 @@ public class XmppConnectionService extends Service {
|
||||
message.getEncryptedBody());
|
||||
message.setStatus(Message.STATUS_SEND);
|
||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
send = true;
|
||||
} else {
|
||||
message.getConversation().endOtrIfNeeded();
|
||||
@ -694,37 +689,28 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
packet = prepareMessagePacket(account, message, null);
|
||||
send = true;
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message.setStatus(Message.STATUS_WAITING);
|
||||
if (message.getType() == Message.TYPE_IMAGE) {
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
} else {
|
||||
if (message.getType() == Message.TYPE_TEXT) {
|
||||
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||
String pgpBody = message.getEncryptedBody();
|
||||
String decryptedBody = message.getBody();
|
||||
message.setBody(pgpBody);
|
||||
databaseBackend.createMessage(message);
|
||||
saveInDb = false;
|
||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||
message.setBody(decryptedBody);
|
||||
addToConversation = true;
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
||||
if (conv.hasValidOtrSession()) {
|
||||
message.setPresence(conv.getOtrSession().getSessionID()
|
||||
.getUserID());
|
||||
} else if (!conv.hasValidOtrSession() && message.getPresence() != null) {
|
||||
} else if (!conv.hasValidOtrSession()
|
||||
&& message.getPresence() != null) {
|
||||
conv.startOtrSession(getApplicationContext(),
|
||||
message.getPresence(), false);
|
||||
}
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
} else {
|
||||
saveInDb = true;
|
||||
addToConversation = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -732,12 +718,10 @@ public class XmppConnectionService extends Service {
|
||||
if (saveInDb) {
|
||||
databaseBackend.createMessage(message);
|
||||
}
|
||||
if (addToConversation) {
|
||||
conv.getMessages().add(message);
|
||||
if (convChangedListener != null) {
|
||||
convChangedListener.onConversationListChanged();
|
||||
}
|
||||
}
|
||||
if ((send) && (packet != null)) {
|
||||
account.getXmppConnection().sendMessagePacket(packet);
|
||||
}
|
||||
@ -796,7 +780,8 @@ public class XmppConnectionService extends Service {
|
||||
markMessage(message, Message.STATUS_SEND);
|
||||
}
|
||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||
Presences presences = message.getConversation().getContact().getPresences();
|
||||
Presences presences = message.getConversation().getContact()
|
||||
.getPresences();
|
||||
if ((message.getPresence() != null)
|
||||
&& (presences.has(message.getPresence()))) {
|
||||
markMessage(message, Message.STATUS_OFFERED);
|
||||
@ -931,9 +916,11 @@ public class XmppConnectionService extends Service {
|
||||
return this.conversations;
|
||||
}
|
||||
|
||||
public List<Message> getMoreMessages(Conversation conversation,long timestamp) {
|
||||
List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp);
|
||||
for(Message message : messages) {
|
||||
public List<Message> getMoreMessages(Conversation conversation,
|
||||
long timestamp) {
|
||||
List<Message> messages = databaseBackend.getMessages(conversation, 50,
|
||||
timestamp);
|
||||
for (Message message : messages) {
|
||||
message.setConversation(conversation);
|
||||
}
|
||||
return messages;
|
||||
|
@ -822,12 +822,7 @@ public class ConversationActivity extends XmppActivity {
|
||||
|
||||
@Override
|
||||
public void success(Message message) {
|
||||
message.getConversation().getMessages().add(message);
|
||||
xmppConnectionService.databaseBackend
|
||||
.createMessage(message);
|
||||
xmppConnectionService.sendMessage(message);
|
||||
xmppConnectionService.updateUi(
|
||||
message.getConversation(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user