Search in sources :

Example 1 with HistoryMessage

use of org.jivesoftware.sparkimpl.plugin.transcripts.HistoryMessage in project Spark by igniterealtime.

the class ChatRoomImpl method loadHistory.

protected void loadHistory() {
    // Add VCard Panel
    vcardPanel = new VCardPanel(participantJID.asBareJid());
    getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 2), 0, 0));
    if (!Default.getBoolean(Default.HISTORY_DISABLED) && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) {
        final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
        if (!localPreferences.isChatHistoryEnabled()) {
            return;
        }
        if (!localPreferences.isPrevChatHistoryEnabled()) {
            return;
        }
        final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(getParticipantJID());
        final String personalNickname = SparkManager.getUserManager().getNickname();
        for (HistoryMessage message : chatTranscript.getMessages()) {
            String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom().asBareJid());
            String messageBody = message.getBody();
            if (nickname.equals(message.getFrom().toString()) || nickname.equals(message.getFrom().asBareJid().toString())) {
                BareJid otherJID = message.getFrom().asBareJid();
                EntityBareJid myJID = SparkManager.getSessionManager().getUserBareAddress();
                if (otherJID.equals(myJID)) {
                    nickname = personalNickname;
                } else {
                    Resourcepart resourcepart = message.getFrom().getResourceOrNull();
                    if (resourcepart == null) {
                        Localpart localpart = message.getFrom().getLocalpartOrNull();
                        if (localpart != null) {
                            nickname = localpart.toString();
                        }
                    } else {
                        nickname = resourcepart.toString();
                    }
                }
            }
            if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) {
                messageBody = messageBody.replaceFirst("/me", nickname);
            }
            final Date messageDate = message.getDate();
            getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate);
        }
        if (0 < chatTranscript.getMessages().size()) {
            // Check if we have history mesages
            getTranscriptWindow().insertHorizontalLine();
        }
        chatTranscript.release();
    }
}
Also used : ChatTranscript(org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscript) Localpart(org.jxmpp.jid.parts.Localpart) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) HistoryMessage(org.jivesoftware.sparkimpl.plugin.transcripts.HistoryMessage) Date(java.util.Date) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

Date (java.util.Date)1 ChatTranscript (org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscript)1 HistoryMessage (org.jivesoftware.sparkimpl.plugin.transcripts.HistoryMessage)1 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)1 Localpart (org.jxmpp.jid.parts.Localpart)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1