use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.
the class ForwardedProvider method parse.
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth) throws Exception {
DelayInformation di = null;
Stanza packet = null;
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String name = parser.getName();
String namespace = parser.getNamespace();
switch(name) {
case DelayInformation.ELEMENT:
if (DelayInformation.NAMESPACE.equals(namespace)) {
di = DelayInformationProvider.INSTANCE.parse(parser, parser.getDepth());
} else {
LOGGER.warning("Namespace '" + namespace + "' does not match expected namespace '" + DelayInformation.NAMESPACE + "'");
}
break;
case Message.ELEMENT:
packet = PacketParserUtils.parseMessage(parser);
break;
default:
LOGGER.warning("Unsupported forwarded packet type: " + name);
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
if (packet == null)
throw new SmackException("forwarded extension must contain a packet");
return new Forwarded(di, packet);
}
use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.
the class DelayInformationTest method parsePresenceWithInvalidLegacyDelayed.
@Test
public void parsePresenceWithInvalidLegacyDelayed() throws Exception {
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>" + "<x xmlns='jabber:x:delay'/></presence>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
DelayInformation delay = DelayInformationManager.getXep203DelayInformation(presence);
assertNull(delay);
}
use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.
the class DelayInformationTest method legacyDateFormatsTest.
@Test
public void legacyDateFormatsTest() throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
LegacyDelayInformationProvider p = new LegacyDelayInformationProvider();
DelayInformation delayInfo;
String control;
// XEP-0091 date format
control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "20020910T23:08:25").asString(outputProperties);
delayInfo = p.parse(PacketParserUtils.getParserFor(control));
assertEquals(calendar.getTime(), delayInfo.getStamp());
// XEP-0091 date format without leading 0 in month
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
GregorianCalendar dateInPast = new GregorianCalendar();
if (dateInPast.get(Calendar.MONTH) >= 10) {
dateInPast.set(Calendar.MONTH, dateInPast.get(Calendar.MONTH) - 3);
}
dateInPast.add(Calendar.DAY_OF_MONTH, -3);
dateInPast.set(Calendar.MILLISECOND, 0);
control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", dateFormat.format(dateInPast.getTime())).asString(outputProperties);
delayInfo = p.parse(PacketParserUtils.getParserFor(control));
assertEquals(dateInPast.getTime(), delayInfo.getStamp());
// XEP-0091 date format from SMACK-243
control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "200868T09:16:20").asString(outputProperties);
delayInfo = p.parse(PacketParserUtils.getParserFor(control));
Date controlDate = XmppDateTime.parseDate("2008-06-08T09:16:20.0Z");
assertEquals(controlDate, delayInfo.getStamp());
}
use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.
the class ForwardedTest method forwardedWithDelayTest.
@Test
public void forwardedWithDelayTest() throws Exception {
XmlPullParser parser;
String control;
Forwarded fwd;
// @formatter:off
control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").up().e("delay").ns(DelayInformation.NAMESPACE).a("stamp", "2010-07-10T23:08:25Z").asString(outputProperties);
// @formatter:on
parser = PacketParserUtils.getParserFor(control);
fwd = new ForwardedProvider().parse(parser);
// assert there is delay information in packet
DelayInformation delay = fwd.getDelayInformation();
assertNotNull(delay);
// check message
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("forwarded", parser.getName());
}
use of org.jivesoftware.smackx.delay.packet.DelayInformation in project xabber-android by redsolution.
the class AbstractChat method sendQueue.
/**
* Requests to send messages from queue.
*
* @param intent can be <code>null</code>.
*/
protected void sendQueue(MessageItem intent) {
if (!canSendMessage())
return;
final ArrayList<MessageItem> sentMessages = new ArrayList<MessageItem>();
final ArrayList<MessageItem> removeMessages = new ArrayList<MessageItem>();
for (final MessageItem messageItem : sendQuery) {
String text = prepareText(messageItem.getText());
if (text == null) {
messageItem.markAsError();
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
if (messageItem.getId() != null)
MessageTable.getInstance().markAsError(messageItem.getId());
}
});
} else {
Message message = createMessagePacket(text);
messageItem.setPacketID(message.getPacketID());
ChatStateManager.getInstance().updateOutgoingMessage(this, message);
ReceiptManager.getInstance().updateOutgoingMessage(this, message, messageItem);
CarbonManager.getInstance().updateOutgoingMessage(this, message, messageItem);
if (messageItem != intent)
message.addExtension(new DelayInformation(messageItem.getTimestamp()));
try {
ConnectionManager.getInstance().sendStanza(account, message);
} catch (NetworkException e) {
break;
}
}
if (MessageArchiveManager.getInstance().getSaveMode(account, user, threadId) == SaveMode.fls)
messageItem.setTag(NO_RECORD_TAG);
if (messageItem != intent) {
messageItem.setSentTimeStamp(new Date());
Collections.sort(messages);
}
messageItem.markAsSent();
if (AccountManager.getInstance().getArchiveMode(messageItem.getChat().getAccount()).saveLocally())
sentMessages.add(messageItem);
else
removeMessages.add(messageItem);
}
sendQuery.removeAll(sentMessages);
sendQuery.removeAll(removeMessages);
MessageManager.getInstance().onChatChanged(account, user, false);
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
Collection<Long> sentIds = MessageManager.getMessageIds(sentMessages, false);
Collection<Long> removeIds = MessageManager.getMessageIds(removeMessages, true);
MessageTable.getInstance().markAsSent(sentIds);
MessageTable.getInstance().removeMessages(removeIds);
}
});
}
Aggregations