Search in sources :

Example 11 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class Contact method asElement.

public Element asElement() {
    final Element item = new Element("item");
    item.setAttribute("jid", this.jid.toString());
    if (this.serverName != null) {
        item.setAttribute("name", this.serverName);
    }
    for (String group : getGroups()) {
        item.addChild("group").setContent(group);
    }
    return item;
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 12 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method entityTimeResponse.

public IqPacket entityTimeResponse(IqPacket request) {
    final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
    Element time = packet.addChild("time", "urn:xmpp:time");
    final long now = System.currentTimeMillis();
    time.addChild("utc").setContent(getTimestamp(now));
    TimeZone ourTimezone = TimeZone.getDefault();
    long offsetSeconds = ourTimezone.getOffset(now) / 1000;
    long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60);
    long offsetHours = offsetSeconds / 3600;
    String hours;
    if (offsetHours < 0) {
        hours = String.format(Locale.US, "%03d", offsetHours);
    } else {
        hours = String.format(Locale.US, "%02d", offsetHours);
    }
    String minutes = String.format(Locale.US, "%02d", offsetMinutes);
    time.addChild("tzo").setContent(hours + ":" + minutes);
    return packet;
}
Also used : TimeZone(java.util.TimeZone) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 13 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method versionResponse.

public IqPacket versionResponse(final IqPacket request) {
    final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
    Element query = packet.query("jabber:iq:version");
    query.addChild("name").setContent(mXmppConnectionService.getString(R.string.app_name));
    query.addChild("version").setContent(getIdentityVersion());
    if ("chromium".equals(android.os.Build.BRAND)) {
        query.addChild("os").setContent("Chrome OS");
    } else {
        query.addChild("os").setContent("Android");
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 14 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method changeRole.

public IqPacket changeRole(Conversation conference, String nick, String role) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(conference.getJid().toBareJid());
    packet.setFrom(conference.getAccount().getJid());
    Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
    item.setAttribute("nick", nick);
    item.setAttribute("role", role);
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 15 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class IqGenerator method queryMessageArchiveManagement.

public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    final Element query = packet.query(mam.isLegacy() ? Namespace.MAM_LEGACY : Namespace.MAM);
    query.setAttribute("queryid", mam.getQueryId());
    final Data data = new Data();
    data.setFormType(mam.isLegacy() ? Namespace.MAM_LEGACY : Namespace.MAM);
    if (mam.muc()) {
        packet.setTo(mam.getWith());
    } else if (mam.getWith() != null) {
        data.put("with", mam.getWith().toString());
    }
    data.put("start", getTimestamp(mam.getStart()));
    data.put("end", getTimestamp(mam.getEnd()));
    data.submit();
    query.addChild(data);
    if (mam.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
        query.addChild("set", "http://jabber.org/protocol/rsm").addChild("before").setContent(mam.getReference());
    } else if (mam.getReference() != null) {
        query.addChild("set", "http://jabber.org/protocol/rsm").addChild("after").setContent(mam.getReference());
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Element (eu.siacs.conversations.xml.Element)93 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)43 Account (eu.siacs.conversations.entities.Account)21 Jid (eu.siacs.conversations.xmpp.jid.Jid)17 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)16 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Contact (eu.siacs.conversations.entities.Contact)7 Conversation (eu.siacs.conversations.entities.Conversation)6 ArrayList (java.util.ArrayList)6 Data (eu.siacs.conversations.xmpp.forms.Data)5 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)5 IOException (java.io.IOException)5 MucOptions (eu.siacs.conversations.entities.MucOptions)4 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)4 Pair (android.util.Pair)3 Bookmark (eu.siacs.conversations.entities.Bookmark)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3