Java Code Examples for org.jxmpp.jid.BareJid#equals()
The following examples show how to use
org.jxmpp.jid.BareJid#equals() .
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: IoTDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
public boolean isRegistry(BareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Objects.requireNonNull(jid, "JID argument must not be null"); // At some point 'usedRegistries' will also contain the registry returned by findRegistry(), but since this is // not the case from the beginning, we perform findRegistry().equals(jid) too. Jid registry = findRegistry(); if (jid.equals(registry)) { return true; } if (usedRegistries.contains(jid)) { return true; } return false; }
Example 2
Source File: PresenceManager.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns the presence of a user. * * @param jidString the users jid. * @return the users presence. */ public static Presence getPresence(BareJid jid) { if (jid.equals(SparkManager.getSessionManager().getBareAddress())) { return SparkManager.getWorkspace().getStatusBar().getPresence(); } else { final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() ); return roster.getPresence(jid); } }
Example 3
Source File: IntegrationTestRosterUtil.java From Smack with Apache License 2.0 | 4 votes |
public static void ensureSubscribedTo(final XMPPConnection presenceRequestReceiverConnection, final XMPPConnection presenceRequestingConnection, long timeout) throws TimeoutException, Exception { final Roster presenceRequestReceiverRoster = Roster.getInstanceFor(presenceRequestReceiverConnection); final Roster presenceRequestingRoster = Roster.getInstanceFor(presenceRequestingConnection); final EntityFullJid presenceRequestReceiverAddress = presenceRequestReceiverConnection.getUser(); final EntityFullJid presenceRequestingAddress = presenceRequestingConnection.getUser(); if (presenceRequestReceiverRoster.isSubscribedToMyPresence(presenceRequestingAddress)) { return; } final SubscribeListener subscribeListener = new SubscribeListener() { @Override public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) { if (from.equals(presenceRequestingConnection.getUser().asBareJid())) { return SubscribeAnswer.Approve; } return SubscribeAnswer.Deny; } }; presenceRequestReceiverRoster.addSubscribeListener(subscribeListener); final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint(); final PresenceEventListener presenceEventListener = new AbstractPresenceEventListener() { @Override public void presenceSubscribed(BareJid address, Presence subscribedPresence) { if (!address.equals(presenceRequestReceiverAddress.asBareJid())) { return; } syncPoint.signal(); } }; presenceRequestingRoster.addPresenceEventListener(presenceEventListener); try { presenceRequestingRoster.sendSubscriptionRequest(presenceRequestReceiverAddress.asBareJid()); syncPoint.waitForResult(timeout); } finally { presenceRequestReceiverRoster.removeSubscribeListener(subscribeListener); presenceRequestingRoster.removePresenceEventListener(presenceEventListener); } }
Example 4
Source File: ChatRoomImpl.java From Spark with Apache License 2.0 | 4 votes |
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("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())) { BareJid otherJID = message.getFrom().asBareJid(); EntityBareJid myJID = SparkManager.getSessionManager().getBareUserAddress(); 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(); } }
Example 5
Source File: HistoryTranscript.java From Spark with Apache License 2.0 | 4 votes |
/** * Builds html string with the stored messages * @return String containing the messages as html */ public final String buildString(List<HistoryMessage> messages){ StringBuilder builder = new StringBuilder(); final String personalNickname = SparkManager.getUserManager().getNickname(); Date lastPost = null; Jid broadcastnick = null; boolean initialized = false; for (HistoryMessage message : messages) { String color = "blue"; Jid from = message.getFrom(); String nickname = SparkManager.getUserManager() .getUserNicknameFromJID(message.getFrom().asBareJid()); String body = org.jivesoftware.spark.util.StringUtils .escapeHTMLTags(message.getBody()); if (nickname.equals(message.getFrom())) { BareJid otherJID = message .getFrom().asBareJid(); EntityBareJid myJID = SparkManager.getSessionManager() .getBareUserAddress(); if (otherJID.equals(myJID)) { nickname = personalNickname; } else { nickname = XmppStringUtils.parseLocalpart(nickname); broadcastnick = message.getFrom(); } } if (!from.asBareJid().equals( SparkManager.getSessionManager().getBareUserAddress())) { color = "red"; } long lastPostTime = lastPost != null ? lastPost.getTime() : 0; int diff; if (DateUtils.getDaysDiff(lastPostTime, message.getDate() .getTime()) != 0) { diff = DateUtils.getDaysDiff(lastPostTime, message .getDate().getTime()); } else { diff = DateUtils.getDayOfWeek(lastPostTime) - DateUtils.getDayOfWeek(message.getDate() .getTime()); } if (diff != 0) { if (initialized) { builder.append("<tr><td><br></td></tr>"); } builder.append( "<tr><td colspan=2><font face=dialog size=3 color=black><b><u>") .append(notificationDateFormatter.format(message .getDate())) .append("</u></b></font></td></tr>"); initialized = true; } String value = "(" + messageDateFormatter.format(message.getDate()) + ") "; builder.append("<tr valign=top><td colspan=2>"); builder.append("<font face=dialog size=3 color='").append(color).append("'>"); builder.append(value); if (broadcastnick == null){ builder.append(nickname + ": "); } else { builder.append(broadcastnick + ": "); } builder.append("</font>"); builder.append("<font face=dialog size=3>"); builder.append(body); builder.append("</font>"); builder.append("</td></tr><br>"); lastPost = message.getDate(); broadcastnick = null; } builder.append("</table></body></html>"); return builder.toString(); }