moved most of the message/presence generation into seperate classes
This commit is contained in:
parent
789383e5cb
commit
99935dd630
|
@ -4,8 +4,6 @@ import java.security.interfaces.DSAPublicKey;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
|
||||||
|
|
||||||
import net.java.otr4j.OtrException;
|
import net.java.otr4j.OtrException;
|
||||||
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
||||||
import net.java.otr4j.crypto.OtrCryptoException;
|
import net.java.otr4j.crypto.OtrCryptoException;
|
||||||
|
@ -118,13 +116,10 @@ public class Conversation extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markRead(XmppConnectionService service) {
|
public String popLatestMarkableMessageId() {
|
||||||
markRead();
|
String id = this.latestMarkableMessageId;
|
||||||
if (service.confirmMessages() && this.latestMarkableMessageId != null) {
|
|
||||||
service.sendConfirmMessage(getAccount(), getContactJid(),
|
|
||||||
this.latestMarkableMessageId);
|
|
||||||
this.latestMarkableMessageId = null;
|
this.latestMarkableMessageId = null;
|
||||||
}
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getLatestMessage() {
|
public Message getLatestMessage() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class MessageGenerator {
|
||||||
delay.setAttribute("stamp", mDateFormat.format(date));
|
delay.setAttribute("stamp", mDateFormat.format(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateOtrChat(Message message) throws OtrException {
|
public MessagePacket generateOtrChat(Message message) {
|
||||||
return generateOtrChat(message, false);
|
return generateOtrChat(message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,4 +106,26 @@ public class MessageGenerator {
|
||||||
packet.setType(MessagePacket.TYPE_ERROR);
|
packet.setType(MessagePacket.TYPE_ERROR);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessagePacket confirm(Account account, String to, String id) {
|
||||||
|
MessagePacket packet = new MessagePacket();
|
||||||
|
packet.setType(MessagePacket.TYPE_NORMAL);
|
||||||
|
packet.setTo(to);
|
||||||
|
packet.setFrom(account.getFullJid());
|
||||||
|
Element received = packet.addChild("displayed",
|
||||||
|
"urn:xmpp:chat-markers:0");
|
||||||
|
received.setAttribute("id", id);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagePacket conversationSubject(Conversation conversation,String subject) {
|
||||||
|
MessagePacket packet = new MessagePacket();
|
||||||
|
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
||||||
|
packet.setTo(conversation.getContactJid().split("/")[0]);
|
||||||
|
Element subjectChild = new Element("subject");
|
||||||
|
subjectChild.setContent(subject);
|
||||||
|
packet.addChild(subjectChild);
|
||||||
|
packet.setFrom(conversation.getAccount().getJid());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
51
src/eu/siacs/conversations/generator/PresenceGenerator.java
Normal file
51
src/eu/siacs/conversations/generator/PresenceGenerator.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package eu.siacs.conversations.generator;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
import eu.siacs.conversations.entities.Contact;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
|
||||||
|
public class PresenceGenerator {
|
||||||
|
|
||||||
|
public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("type", "subscribe");
|
||||||
|
packet.setAttribute("to", contact.getJid());
|
||||||
|
packet.setAttribute("from", contact.getAccount().getJid());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("type", "unsubscribe");
|
||||||
|
packet.setAttribute("to", contact.getJid());
|
||||||
|
packet.setAttribute("from", contact.getAccount().getJid());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresencePacket stopPresenceUpdatesTo(Contact contact) {
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("type", "unsubscribed");
|
||||||
|
packet.setAttribute("to", contact.getJid());
|
||||||
|
packet.setAttribute("from", contact.getAccount().getJid());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresencePacket sendPresenceUpdatesTo(Contact contact) {
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("type", "subscribed");
|
||||||
|
packet.setAttribute("to", contact.getJid());
|
||||||
|
packet.setAttribute("from", contact.getAccount().getJid());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresencePacket sendPresence(Account account) {
|
||||||
|
PresencePacket packet = new PresencePacket();
|
||||||
|
packet.setAttribute("from", account.getFullJid());
|
||||||
|
String sig = account.getPgpSignature();
|
||||||
|
if (sig != null) {
|
||||||
|
packet.addChild("status").setContent("online");
|
||||||
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
||||||
|
}
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
|
import eu.siacs.conversations.generator.PresenceGenerator;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
|
import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
|
||||||
|
@ -13,8 +14,11 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
public class PresenceParser extends AbstractParser implements
|
public class PresenceParser extends AbstractParser implements
|
||||||
OnPresencePacketReceived {
|
OnPresencePacketReceived {
|
||||||
|
|
||||||
|
private PresenceGenerator mPresenceGenerator;
|
||||||
|
|
||||||
public PresenceParser(XmppConnectionService service) {
|
public PresenceParser(XmppConnectionService service) {
|
||||||
super(service);
|
super(service);
|
||||||
|
mPresenceGenerator = service.getPresenceGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseConferencePresence(PresencePacket packet, Account account) {
|
public void parseConferencePresence(PresencePacket packet, Account account) {
|
||||||
|
@ -91,11 +95,10 @@ public class PresenceParser extends AbstractParser implements
|
||||||
.onContactStatusChanged(contact, false);
|
.onContactStatusChanged(contact, false);
|
||||||
} else if (type.equals("subscribe")) {
|
} else if (type.equals("subscribe")) {
|
||||||
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||||
mXmppConnectionService.sendPresenceUpdatesTo(contact);
|
mXmppConnectionService.sendPresencePacket(account, mPresenceGenerator.stopPresenceUpdatesTo(contact));
|
||||||
if ((contact.getOption(Contact.Options.ASKING))
|
if ((contact.getOption(Contact.Options.ASKING))
|
||||||
&& (!contact.getOption(Contact.Options.TO))) {
|
&& (!contact.getOption(Contact.Options.TO))) {
|
||||||
mXmppConnectionService
|
mXmppConnectionService.sendPresencePacket(account,mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
||||||
.requestPresenceUpdatesFrom(contact);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
|
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
|
||||||
|
|
|
@ -26,6 +26,7 @@ import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
import eu.siacs.conversations.generator.MessageGenerator;
|
import eu.siacs.conversations.generator.MessageGenerator;
|
||||||
|
import eu.siacs.conversations.generator.PresenceGenerator;
|
||||||
import eu.siacs.conversations.parser.MessageParser;
|
import eu.siacs.conversations.parser.MessageParser;
|
||||||
import eu.siacs.conversations.parser.PresenceParser;
|
import eu.siacs.conversations.parser.PresenceParser;
|
||||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||||
|
@ -92,6 +93,7 @@ public class XmppConnectionService extends Service {
|
||||||
private MessageParser mMessageParser = new MessageParser(this);
|
private MessageParser mMessageParser = new MessageParser(this);
|
||||||
private PresenceParser mPresenceParser = new PresenceParser(this);
|
private PresenceParser mPresenceParser = new PresenceParser(this);
|
||||||
private MessageGenerator mMessageGenerator = new MessageGenerator();
|
private MessageGenerator mMessageGenerator = new MessageGenerator();
|
||||||
|
private PresenceGenerator mPresenceGenerator = new PresenceGenerator();
|
||||||
|
|
||||||
private List<Account> accounts;
|
private List<Account> accounts;
|
||||||
private List<Conversation> conversations = null;
|
private List<Conversation> conversations = null;
|
||||||
|
@ -542,7 +544,7 @@ public class XmppConnectionService extends Service {
|
||||||
account.getRoster().clearPresences();
|
account.getRoster().clearPresences();
|
||||||
account.clearPresences(); // self presences
|
account.clearPresences(); // self presences
|
||||||
fetchRosterFromServer(account);
|
fetchRosterFromServer(account);
|
||||||
sendPresence(account);
|
sendPresencePacket(account, mPresenceGenerator.sendPresence(account));
|
||||||
connectMultiModeConversations(account);
|
connectMultiModeConversations(account);
|
||||||
if (convChangedListener != null) {
|
if (convChangedListener != null) {
|
||||||
convChangedListener.onConversationListChanged();
|
convChangedListener.onConversationListChanged();
|
||||||
|
@ -591,14 +593,10 @@ public class XmppConnectionService extends Service {
|
||||||
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||||
message.setPresence(conv.getOtrSession().getSessionID()
|
message.setPresence(conv.getOtrSession().getSessionID()
|
||||||
.getUserID());
|
.getUserID());
|
||||||
try {
|
|
||||||
packet = mMessageGenerator.generateOtrChat(message);
|
packet = mMessageGenerator.generateOtrChat(message);
|
||||||
send = true;
|
send = true;
|
||||||
message.setStatus(Message.STATUS_SEND);
|
message.setStatus(Message.STATUS_SEND);
|
||||||
} catch (OtrException e) {
|
|
||||||
Log.e(LOGTAG, "error generating otr packet");
|
|
||||||
packet = null;
|
|
||||||
}
|
|
||||||
} else if (message.getPresence() == null) {
|
} else if (message.getPresence() == null) {
|
||||||
message.setStatus(Message.STATUS_WAITING);
|
message.setStatus(Message.STATUS_WAITING);
|
||||||
}
|
}
|
||||||
|
@ -647,7 +645,7 @@ public class XmppConnectionService extends Service {
|
||||||
convChangedListener.onConversationListChanged();
|
convChangedListener.onConversationListChanged();
|
||||||
}
|
}
|
||||||
if ((send) && (packet != null)) {
|
if ((send) && (packet != null)) {
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
sendMessagePacket(account, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -715,7 +713,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
sendMessagePacket(account,packet);
|
||||||
markMessage(message, Message.STATUS_SEND);
|
markMessage(message, Message.STATUS_SEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -996,7 +994,7 @@ public class XmppConnectionService extends Service {
|
||||||
mDateFormat.format(date));
|
mDateFormat.format(date));
|
||||||
}
|
}
|
||||||
packet.addChild(x);
|
packet.addChild(x);
|
||||||
account.getXmppConnection().sendPresencePacket(packet);
|
sendPresencePacket(account, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnRenameListener renameListener = null;
|
private OnRenameListener renameListener = null;
|
||||||
|
@ -1035,8 +1033,7 @@ public class XmppConnectionService extends Service {
|
||||||
packet.addChild("status").setContent("online");
|
packet.addChild("status").setContent("online");
|
||||||
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
||||||
}
|
}
|
||||||
|
sendPresencePacket(account,packet);
|
||||||
account.getXmppConnection().sendPresencePacket(packet, null);
|
|
||||||
} else {
|
} else {
|
||||||
String jid = conversation.getContactJid().split("/")[0] + "/"
|
String jid = conversation.getContactJid().split("/")[0] + "/"
|
||||||
+ nick;
|
+ nick;
|
||||||
|
@ -1055,8 +1052,7 @@ public class XmppConnectionService extends Service {
|
||||||
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
||||||
packet.setAttribute("type", "unavailable");
|
packet.setAttribute("type", "unavailable");
|
||||||
Log.d(LOGTAG, "send leaving muc " + packet);
|
Log.d(LOGTAG, "send leaving muc " + packet);
|
||||||
conversation.getAccount().getXmppConnection()
|
sendPresencePacket(conversation.getAccount(),packet);
|
||||||
.sendPresencePacket(packet);
|
|
||||||
conversation.getMucOptions().setOffline();
|
conversation.getMucOptions().setOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1129,8 +1125,7 @@ public class XmppConnectionService extends Service {
|
||||||
if (outPacket != null) {
|
if (outPacket != null) {
|
||||||
msg.setStatus(Message.STATUS_SEND);
|
msg.setStatus(Message.STATUS_SEND);
|
||||||
databaseBackend.updateMessage(msg);
|
databaseBackend.updateMessage(msg);
|
||||||
account.getXmppConnection()
|
sendMessagePacket(account,outPacket);
|
||||||
.sendMessagePacket(outPacket);
|
|
||||||
}
|
}
|
||||||
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
||||||
mJingleConnectionManager.createNewConnection(msg);
|
mJingleConnectionManager.createNewConnection(msg);
|
||||||
|
@ -1157,7 +1152,7 @@ public class XmppConnectionService extends Service {
|
||||||
packet.setBody(otrSession
|
packet.setBody(otrSession
|
||||||
.transformSending(CryptoHelper.FILETRANSFER
|
.transformSending(CryptoHelper.FILETRANSFER
|
||||||
+ CryptoHelper.bytesToHex(symmetricKey)));
|
+ CryptoHelper.bytesToHex(symmetricKey)));
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
sendMessagePacket(account,packet);
|
||||||
conversation.setSymmetricKey(symmetricKey);
|
conversation.setSymmetricKey(symmetricKey);
|
||||||
return true;
|
return true;
|
||||||
} catch (OtrException e) {
|
} catch (OtrException e) {
|
||||||
|
@ -1176,12 +1171,12 @@ public class XmppConnectionService extends Service {
|
||||||
iq.query("jabber:iq:roster").addChild(contact.asElement());
|
iq.query("jabber:iq:roster").addChild(contact.asElement());
|
||||||
account.getXmppConnection().sendIqPacket(iq, null);
|
account.getXmppConnection().sendIqPacket(iq, null);
|
||||||
if (contact.getOption(Contact.Options.ASKING)) {
|
if (contact.getOption(Contact.Options.ASKING)) {
|
||||||
requestPresenceUpdatesFrom(contact);
|
sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
||||||
}
|
}
|
||||||
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
|
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
|
||||||
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
||||||
Log.d("xmppService", "contact had pending subscription");
|
Log.d("xmppService", "contact had pending subscription");
|
||||||
sendPresenceUpdatesTo(contact);
|
sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,49 +1195,6 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestPresenceUpdatesFrom(Contact contact) {
|
|
||||||
PresencePacket packet = new PresencePacket();
|
|
||||||
packet.setAttribute("type", "subscribe");
|
|
||||||
packet.setAttribute("to", contact.getJid());
|
|
||||||
packet.setAttribute("from", contact.getAccount().getJid());
|
|
||||||
contact.getAccount().getXmppConnection().sendPresencePacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopPresenceUpdatesFrom(Contact contact) {
|
|
||||||
PresencePacket packet = new PresencePacket();
|
|
||||||
packet.setAttribute("type", "unsubscribe");
|
|
||||||
packet.setAttribute("to", contact.getJid());
|
|
||||||
packet.setAttribute("from", contact.getAccount().getJid());
|
|
||||||
contact.getAccount().getXmppConnection().sendPresencePacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopPresenceUpdatesTo(Contact contact) {
|
|
||||||
PresencePacket packet = new PresencePacket();
|
|
||||||
packet.setAttribute("type", "unsubscribed");
|
|
||||||
packet.setAttribute("to", contact.getJid());
|
|
||||||
packet.setAttribute("from", contact.getAccount().getJid());
|
|
||||||
contact.getAccount().getXmppConnection().sendPresencePacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPresenceUpdatesTo(Contact contact) {
|
|
||||||
PresencePacket packet = new PresencePacket();
|
|
||||||
packet.setAttribute("type", "subscribed");
|
|
||||||
packet.setAttribute("to", contact.getJid());
|
|
||||||
packet.setAttribute("from", contact.getAccount().getJid());
|
|
||||||
contact.getAccount().getXmppConnection().sendPresencePacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPresence(Account account) {
|
|
||||||
PresencePacket packet = new PresencePacket();
|
|
||||||
packet.setAttribute("from", account.getFullJid());
|
|
||||||
String sig = account.getPgpSignature();
|
|
||||||
if (sig != null) {
|
|
||||||
packet.addChild("status").setContent("online");
|
|
||||||
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
|
||||||
}
|
|
||||||
account.getXmppConnection().sendPresencePacket(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateConversation(Conversation conversation) {
|
public void updateConversation(Conversation conversation) {
|
||||||
this.databaseBackend.updateConversation(conversation);
|
this.databaseBackend.updateConversation(conversation);
|
||||||
}
|
}
|
||||||
|
@ -1271,21 +1223,6 @@ public class XmppConnectionService extends Service {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendConversationSubject(Conversation conversation,
|
|
||||||
String subject) {
|
|
||||||
MessagePacket packet = new MessagePacket();
|
|
||||||
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
|
||||||
packet.setTo(conversation.getContactJid().split("/")[0]);
|
|
||||||
Element subjectChild = new Element("subject");
|
|
||||||
subjectChild.setContent(subject);
|
|
||||||
packet.addChild(subjectChild);
|
|
||||||
packet.setFrom(conversation.getAccount().getJid());
|
|
||||||
Account account = conversation.getAccount();
|
|
||||||
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void inviteToConference(Conversation conversation,
|
public void inviteToConference(Conversation conversation,
|
||||||
List<Contact> contacts) {
|
List<Contact> contacts) {
|
||||||
for (Contact contact : contacts) {
|
for (Contact contact : contacts) {
|
||||||
|
@ -1299,8 +1236,7 @@ public class XmppConnectionService extends Service {
|
||||||
x.addChild(invite);
|
x.addChild(invite);
|
||||||
packet.addChild(x);
|
packet.addChild(x);
|
||||||
Log.d(LOGTAG, packet.toString());
|
Log.d(LOGTAG, packet.toString());
|
||||||
conversation.getAccount().getXmppConnection()
|
sendMessagePacket(conversation.getAccount(),packet);
|
||||||
.sendMessagePacket(packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1363,18 +1299,13 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markRead(Conversation conversation) {
|
public void markRead(Conversation conversation) {
|
||||||
conversation.markRead(this);
|
conversation.markRead();
|
||||||
|
String id = conversation.popLatestMarkableMessageId();
|
||||||
|
if (confirmMessages() && id != null) {
|
||||||
|
Account account = conversation.getAccount();
|
||||||
|
String to = conversation.getContactJid();
|
||||||
|
this.sendMessagePacket(conversation.getAccount(), mMessageGenerator.confirm(account, to, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendConfirmMessage(Account account, String to, String id) {
|
|
||||||
MessagePacket receivedPacket = new MessagePacket();
|
|
||||||
receivedPacket.setType(MessagePacket.TYPE_NORMAL);
|
|
||||||
receivedPacket.setTo(to);
|
|
||||||
receivedPacket.setFrom(account.getFullJid());
|
|
||||||
Element received = receivedPacket.addChild("displayed",
|
|
||||||
"urn:xmpp:chat-markers:0");
|
|
||||||
received.setAttribute("id", id);
|
|
||||||
account.getXmppConnection().sendMessagePacket(receivedPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecureRandom getRNG() {
|
public SecureRandom getRNG() {
|
||||||
|
@ -1389,7 +1320,7 @@ public class XmppConnectionService extends Service {
|
||||||
if (account.getStatus() == Account.STATUS_ONLINE) {
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||||
MessagePacket error = this.mMessageGenerator
|
MessagePacket error = this.mMessageGenerator
|
||||||
.generateNotAcceptable(packet);
|
.generateNotAcceptable(packet);
|
||||||
account.getXmppConnection().sendMessagePacket(error);
|
sendMessagePacket(account,error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1434,4 +1365,20 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
return mucServers;
|
return mucServers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessagePacket(Account account, MessagePacket packet) {
|
||||||
|
account.getXmppConnection().sendMessagePacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPresencePacket(Account account, PresencePacket packet) {
|
||||||
|
account.getXmppConnection().sendPresencePacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageGenerator getMessageGenerator() {
|
||||||
|
return this.mMessageGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PresenceGenerator getPresenceGenerator() {
|
||||||
|
return this.mPresenceGenerator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,9 @@ import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
|
||||||
public class ContactDetailsActivity extends XmppActivity {
|
public class ContactDetailsActivity extends XmppActivity {
|
||||||
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
||||||
|
@ -293,6 +295,8 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
XmppConnectionService xcs = activity.xmppConnectionService;
|
||||||
|
PresencePacket packet = null;
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
if (contact!=null) {
|
if (contact!=null) {
|
||||||
boolean online = contact.getAccount().getStatus() == Account.STATUS_ONLINE;
|
boolean online = contact.getAccount().getStatus() == Account.STATUS_ONLINE;
|
||||||
|
@ -301,7 +305,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.resetOption(Contact.Options.FROM);
|
contact.resetOption(Contact.Options.FROM);
|
||||||
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
activity.xmppConnectionService.stopPresenceUpdatesTo(contact);
|
packet = xcs.getPresenceGenerator().stopPresenceUpdatesTo(contact);
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
@ -317,7 +321,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
if (send.isChecked()) {
|
if (send.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
||||||
xmppConnectionService.sendPresenceUpdatesTo(contact);
|
packet = xcs.getPresenceGenerator().sendPresenceUpdatesTo(contact);
|
||||||
} else {
|
} else {
|
||||||
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
}
|
}
|
||||||
|
@ -330,7 +334,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
if (!receive.isChecked()) {
|
if (!receive.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.resetOption(Contact.Options.TO);
|
contact.resetOption(Contact.Options.TO);
|
||||||
activity.xmppConnectionService.stopPresenceUpdatesFrom(contact);
|
packet = xcs.getPresenceGenerator().stopPresenceUpdatesFrom(contact);
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
@ -339,8 +343,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
if (!receive.isChecked()) {
|
if (!receive.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.resetOption(Contact.Options.ASKING);
|
contact.resetOption(Contact.Options.ASKING);
|
||||||
activity.xmppConnectionService
|
packet = xcs.getPresenceGenerator().stopPresenceUpdatesFrom(contact);
|
||||||
.stopPresenceUpdatesFrom(contact);
|
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
@ -348,8 +351,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
if (receive.isChecked()) {
|
if (receive.isChecked()) {
|
||||||
if (online) {
|
if (online) {
|
||||||
contact.setOption(Contact.Options.ASKING);
|
contact.setOption(Contact.Options.ASKING);
|
||||||
activity.xmppConnectionService
|
packet = xcs.getPresenceGenerator().requestPresenceUpdatesFrom(contact);
|
||||||
.requestPresenceUpdatesFrom(contact);
|
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
@ -357,6 +359,9 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
if (online) {
|
if (online) {
|
||||||
|
if (packet!=null) {
|
||||||
|
xcs.sendPresencePacket(contact.getAccount(), packet);
|
||||||
|
}
|
||||||
Toast.makeText(getApplicationContext(), getString(R.string.subscription_updated), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getString(R.string.subscription_updated), Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(), getString(R.string.subscription_not_updated_offline), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getString(R.string.subscription_not_updated_offline), Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -11,9 +11,9 @@ import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.MucOptions.User;
|
import eu.siacs.conversations.entities.MucOptions.User;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
import eu.siacs.conversations.utils.UIHelper;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.IntentSender.SendIntentException;
|
import android.content.IntentSender.SendIntentException;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -62,7 +62,8 @@ public class MucDetailsActivity extends XmppActivity {
|
||||||
String subject = mSubject.getText().toString();
|
String subject = mSubject.getText().toString();
|
||||||
MucOptions options = conversation.getMucOptions();
|
MucOptions options = conversation.getMucOptions();
|
||||||
if (!subject.equals(options.getSubject())) {
|
if (!subject.equals(options.getSubject())) {
|
||||||
xmppConnectionService.sendConversationSubject(conversation,subject);
|
MessagePacket packet = xmppConnectionService.getMessageGenerator().conversationSubject(conversation, subject);
|
||||||
|
xmppConnectionService.sendMessagePacket(conversation.getAccount(), packet);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,9 @@ public abstract class XmppActivity extends Activity {
|
||||||
public void success(Account account) {
|
public void success(Account account) {
|
||||||
xmppConnectionService.databaseBackend
|
xmppConnectionService.databaseBackend
|
||||||
.updateAccount(account);
|
.updateAccount(account);
|
||||||
xmppConnectionService.sendPresence(account);
|
xmppConnectionService.sendPresencePacket(account,
|
||||||
|
xmppConnectionService.getPresenceGenerator()
|
||||||
|
.sendPresence(account));
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
conversation
|
conversation
|
||||||
.setNextEncryption(Message.ENCRYPTION_PGP);
|
.setNextEncryption(Message.ENCRYPTION_PGP);
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -793,20 +792,10 @@ public class XmppConnection implements Runnable {
|
||||||
this.sendPacket(packet, null);
|
this.sendPacket(packet, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessagePacket(MessagePacket packet,
|
|
||||||
OnMessagePacketReceived callback) {
|
|
||||||
this.sendPacket(packet, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPresencePacket(PresencePacket packet) {
|
public void sendPresencePacket(PresencePacket packet) {
|
||||||
this.sendPacket(packet, null);
|
this.sendPacket(packet, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPresencePacket(PresencePacket packet,
|
|
||||||
OnPresencePacketReceived callback) {
|
|
||||||
this.sendPacket(packet, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void sendPacket(final AbstractStanza packet,
|
private synchronized void sendPacket(final AbstractStanza packet,
|
||||||
PacketReceived callback) {
|
PacketReceived callback) {
|
||||||
// TODO dont increment stanza count if packet = request packet or ack;
|
// TODO dont increment stanza count if packet = request packet or ack;
|
||||||
|
|
Loading…
Reference in a new issue