org.jivesoftware.smackx.packet.DelayInformation Java Examples

The following examples show how to use org.jivesoftware.smackx.packet.DelayInformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientHelper.java    From olat with Apache License 2.0 6 votes vote down vote up
public static String getSendDate(final Message msg, final Locale loc) {
    for (final Iterator iter = msg.getExtensions().iterator(); iter.hasNext();) {
        final PacketExtension extension = (PacketExtension) iter.next();
        if (extension.getNamespace().equals("jabber:x:delay")) {
            final DelayInformation delayInfo = (DelayInformation) extension;
            final Date date = delayInfo.getStamp();
            // why does formatter with this method return a time in the afternoon
            // like 03:24 instead of 15:24 like formatTime does??
            return Formatter.getInstance(loc).formatDateAndTime(date);
        }
    }
    // if no delay time now is returned
    // return Formatter.getInstance(locale).formatTime(new Date());
    final Long receiveTime = (Long) msg.getProperty("receiveTime");
    final Date d = new Date();
    d.setTime(receiveTime.longValue());
    return Formatter.getInstance(loc).formatTime(d);
}
 
Example #2
Source File: ClientHelper.java    From olat with Apache License 2.0 6 votes vote down vote up
public static String getSendDate(final Message msg, final Locale loc) {
    for (final Iterator iter = msg.getExtensions().iterator(); iter.hasNext();) {
        final PacketExtension extension = (PacketExtension) iter.next();
        if (extension.getNamespace().equals("jabber:x:delay")) {
            final DelayInformation delayInfo = (DelayInformation) extension;
            final Date date = delayInfo.getStamp();
            // why does formatter with this method return a time in the afternoon
            // like 03:24 instead of 15:24 like formatTime does??
            return Formatter.getInstance(loc).formatDateAndTime(date);
        }
    }
    // if no delay time now is returned
    // return Formatter.getInstance(locale).formatTime(new Date());
    final Long receiveTime = (Long) msg.getProperty("receiveTime");
    final Date d = new Date();
    d.setTime(receiveTime.longValue());
    return Formatter.getInstance(loc).formatTime(d);
}
 
Example #3
Source File: MultiUserChatTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
public void testDiscussionHistory() {
    try {
        // User1 sends some messages to the room
        muc.sendMessage("Message 1");
        muc.sendMessage("Message 2");
        // Wait 5 seconds before sending the last message
        Thread.sleep(5000);
        muc.sendMessage("Message 3");

        // User2 joins the room requesting to receive the messages of the last 2 seconds.
        MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
        DiscussionHistory history = new DiscussionHistory();
        history.setSeconds(2);
        muc2.join("testbot2", null, history, SmackConfiguration.getPacketReplyTimeout());

        Message msg;
        // Get first historic message
        msg = muc2.nextMessage(1000);
        assertNotNull("First message is null", msg);
        DelayInformation delay = DelayInformationManager.getDelayInformation(msg);
        assertNotNull("Message contains no delay information", delay);
        SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
        UTC_FORMAT.setTimeZone(TimeZone.getDefault());
        System.out.println(UTC_FORMAT.format(delay.getStamp()));

        assertEquals("Body of first message is incorrect", "Message 3", msg.getBody());
        // Try to get second historic message
        msg = muc2.nextMessage(1000);
        assertNull("Second message is not null", msg);


        // User3 joins the room requesting to receive the last 2 messages.
        MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
        history = new DiscussionHistory();
        history.setMaxStanzas(2);
        muc3.join("testbot3", null, history, SmackConfiguration.getPacketReplyTimeout());

        // Get first historic message
        msg = muc3.nextMessage(1000);
        assertNotNull("First message is null", msg);
        assertEquals("Body of first message is incorrect", "Message 2", msg.getBody());
        // Get second historic message
        msg = muc3.nextMessage(1000);
        assertNotNull("Second message is null", msg);
        assertEquals("Body of second message is incorrect", "Message 3", msg.getBody());
        // Try to get third historic message
        msg = muc3.nextMessage(1000);
        assertNull("Third message is not null", msg);

        // User2 leaves the room
        muc2.leave();
        // User3 leaves the room
        muc3.leave();

    }
    catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}