aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java60
-rw-r--r--src/main/java/eu/siacs/conversations/parser/AbstractParser.java8
-rw-r--r--src/main/java/eu/siacs/conversations/parser/IqParser.java13
-rw-r--r--src/main/java/eu/siacs/conversations/services/AvatarService.java13
4 files changed, 7 insertions, 87 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 9de9a201..ce32cedb 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -44,58 +44,6 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- protected static IqPacket publish(final String node, final Element item) {
- final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
- final Element pubsub = packet.addChild("pubsub",
- "http://jabber.org/protocol/pubsub");
- final Element publish = pubsub.addChild("publish");
- publish.setAttribute("node", node);
- publish.addChild(item);
- return packet;
- }
-
- protected static IqPacket retrieve(String node, Element item) {
- final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
- final Element pubsub = packet.addChild("pubsub",
- "http://jabber.org/protocol/pubsub");
- final Element items = pubsub.addChild("items");
- items.setAttribute("node", node);
- if (item != null) {
- items.addChild(item);
- }
- return packet;
- }
-
- public static IqPacket publishAvatar(Avatar avatar) {
- final Element item = new Element("item");
- item.setAttribute("id", avatar.sha1sum);
- final Element data = item.addChild("data", "urn:xmpp:avatar:data");
- data.setContent(avatar.image);
- return publish("urn:xmpp:avatar:data", item);
- }
-
- public static IqPacket publishAvatarMetadata(final Avatar avatar) {
- final Element item = new Element("item");
- item.setAttribute("id", avatar.sha1sum);
- final Element metadata = item
- .addChild("metadata", "urn:xmpp:avatar:metadata");
- final Element info = metadata.addChild("info");
- info.setAttribute("bytes", avatar.size);
- info.setAttribute("id", avatar.sha1sum);
- info.setAttribute("height", avatar.height);
- info.setAttribute("width", avatar.height);
- info.setAttribute("type", avatar.type);
- return publish("urn:xmpp:avatar:metadata", item);
- }
-
- public static IqPacket retrievePepAvatar(final Avatar avatar) {
- final Element item = new Element("item");
- item.setAttribute("id", avatar.sha1sum);
- final IqPacket packet = retrieve("urn:xmpp:avatar:data", item);
- packet.setTo(avatar.owner);
- return packet;
- }
-
public static IqPacket retrieveVcardAvatar(final Avatar avatar) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(avatar.owner);
@@ -103,14 +51,6 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- public static IqPacket retrieveAvatarMetaData(final Jid to) {
- final IqPacket packet = retrieve("urn:xmpp:avatar:metadata", null);
- if (to != null) {
- packet.setTo(to);
- }
- return packet;
- }
-
public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
final Element query = packet.query("urn:xmpp:mam:0");
diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
index 2e0852a3..ca20f592 100644
--- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
@@ -89,12 +89,4 @@ public abstract class AbstractParser {
}
}
}
-
- protected static String avatarData(Element items) {
- Element item = items.findChild("item");
- if (item == null) {
- return null;
- }
- return item.findChildContent("data", "urn:xmpp:avatar:data");
- }
}
diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java
index 94047b5d..1183fe23 100644
--- a/src/main/java/eu/siacs/conversations/parser/IqParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java
@@ -59,19 +59,6 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
mXmppConnectionService.updateRosterUi();
}
- public static String avatarData(final IqPacket packet) {
- final Element pubsub = packet.findChild("pubsub",
- "http://jabber.org/protocol/pubsub");
- if (pubsub == null) {
- return null;
- }
- final Element items = pubsub.findChild("items");
- if (items == null) {
- return null;
- }
- return AbstractParser.avatarData(items);
- }
-
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) {
diff --git a/src/main/java/eu/siacs/conversations/services/AvatarService.java b/src/main/java/eu/siacs/conversations/services/AvatarService.java
index 33e7b8e4..1fb34c4c 100644
--- a/src/main/java/eu/siacs/conversations/services/AvatarService.java
+++ b/src/main/java/eu/siacs/conversations/services/AvatarService.java
@@ -18,6 +18,8 @@ import de.thedevstack.conversationsplus.utils.AvatarUtil;
import de.thedevstack.conversationsplus.utils.ImageUtil;
import de.thedevstack.conversationsplus.utils.UiUpdateHelper;
import de.thedevstack.conversationsplus.utils.XmppSendUtil;
+import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacketGenerator;
+import de.thedevstack.conversationsplus.xmpp.avatar.AvatarPacketParser;
import eu.siacs.conversations.R;
import eu.siacs.conversations.Config;
@@ -28,7 +30,6 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.generator.IqGenerator;
-import eu.siacs.conversations.parser.IqParser;
import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.utils.UIHelper;
@@ -324,13 +325,13 @@ public class AvatarService {
callback.error(R.string.error_saving_avatar, avatar);
return;
}
- final IqPacket packet = IqGenerator.publishAvatar(avatar);
+ final IqPacket packet = AvatarPacketGenerator.generatePublishAvatarPacket(avatar);
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) {
- final IqPacket packet = IqGenerator.publishAvatarMetadata(avatar);
+ final IqPacket packet = AvatarPacketGenerator.generatePublishAvatarMetadataPacket(avatar);
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
@@ -386,7 +387,7 @@ public class AvatarService {
}
private void fetchAvatarPep(final Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
- IqPacket packet = IqGenerator.retrievePepAvatar(avatar);
+ IqPacket packet = AvatarPacketGenerator.generateRetrieveAvatarPacket(avatar);
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
@@ -397,7 +398,7 @@ public class AvatarService {
final String ERROR = account.getJid().toBareJid()
+ ": fetching avatar for " + avatar.owner + " failed ";
if (result.getType() == IqPacket.TYPE.RESULT) {
- avatar.image = IqParser.avatarData(result);
+ avatar.image = AvatarPacketParser.parseAvatarData(result);
if (avatar.image != null) {
if (AvatarUtil.save(avatar)) {
if (account.getJid().toBareJid().equals(avatar.owner)) {
@@ -473,7 +474,7 @@ public class AvatarService {
}
public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
- IqPacket packet = IqGenerator.retrieveAvatarMetaData(null);
+ IqPacket packet = AvatarPacketGenerator.generateRetrieveAvatarMetadataPacket(null);
XmppSendUtil.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override