Option for new behaviour of detecting a contact's capabilities

This reintroduces some old code in order to give the user the option to
switch between those two behaviours.

It also prevents the removal of all caps nodes (and thusly breaking the
new detection) when a rogue offline presence event comes in. This is
such an event in which a contact is falsely assumed as offline, if the
preferred resource of two or more same prioritised resources goes
offline. We are checking this by looking whether it is a
"resourceChanged"-event. This should probably be changed again, after
those offline presence updates have been fixed.
smack4
Timur Masar 10 years ago
parent 6fcbb76665
commit 45d8ee64c4

@ -1069,6 +1069,8 @@ plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS=Remove special symbols before
plugin.generalconfig.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS=Convert letters in phone numbers
plugin.generalconfig.ACCEPT_PHONE_NUMBER_WITH_ALPHA_CHARS_EXAMPLE=e.g. +1-800-MYPHONE -> +1-800-694663
plugin.generalconfig.SIP_CALL_CONFIG=SIP
plugin.generalconfig.XMPP_CONFIG=XMPP
plugin.generalconfig.XMPP_USE_ALL_RESOURCES=Use all resources when detecting a contact's features
plugin.generalconfig.OPUS_CONFIG=Opus
plugin.generalconfig.OPUS_AUDIO_BANDWIDTH=Sampling rate:
plugin.generalconfig.OPUS_BITRATE=Encoder average bitrate (kbps):

@ -26,7 +26,7 @@
import net.java.sip.communicator.util.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.*;
/**
* Represents an <tt>OperationSet</tt> to query the <tt>OperationSet</tt>s
@ -51,6 +51,19 @@ public class OperationSetContactCapabilitiesJabberImpl
private static final Logger logger
= Logger.getLogger(OperationSetContactCapabilitiesJabberImpl.class);
/**
* The name of the property used to control whether to use
* all resources to show capabilities
*/
public static final String PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES =
"net.java.sip.communicator.XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES";
/**
* The default value for the capabilities setting
*/
public static final boolean USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT =
true;
/**
* The list of <tt>OperationSet</tt> capabilities presumed to be supported
* by a <tt>Contact</tt> when it is offline.
@ -295,13 +308,14 @@ protected Map<String, OperationSet> getLargestSupportedOperationSet(
{
Map<String, OperationSet> supportedOperationSets =
new HashMap<String, OperationSet>();
if (fullJids!=null){
if (fullJids!=null)
{
for (String fullJid : fullJids)
{
Map<String, OperationSet> newSupportedOperationSets=
getSupportedOperationSets(fullJid, true);
if (newSupportedOperationSets.size()>
supportedOperationSets.size())
supportedOperationSets.size())
{
supportedOperationSets = newSupportedOperationSets;
}
@ -466,40 +480,61 @@ public void userCapsNodeRemoved(String user, ArrayList<String> fullJids,
* @param node the entity caps node#ver
* @param online indicates if the given user is online
*/
public void userCapsNodeChanged(String user, ArrayList<String> fullJids, String node, boolean online)
public void userCapsNodeChanged(String user, ArrayList<String> fullJids,
String node, boolean online)
{
OperationSetPresence opsetPresence
= parentProvider.getOperationSet(OperationSetPresence.class);
if (opsetPresence != null)
{
String bareJid = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(bareJid);
// If the contact isn't null and is online we try to discover the
// new set of operation sets and to notify interested parties.
// Otherwise we ignore the event.
if (contact != null)
= parentProvider.getOperationSet(OperationSetPresence.class);
if (opsetPresence != null) {
if(JabberActivator.getConfigurationService()
.getBoolean(
PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT))
{
if(online)
String bareJid = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(bareJid);
if (contact != null)
{
// when going online we have received a presence
// and make sure we discover this particular jid
// for getSupportedOperationSets
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED,
ContactCapabilitiesEvent.
SUPPORTED_OPERATION_SETS_CHANGED,
getLargestSupportedOperationSet(fullJids));
}
else
}
else
{
String jid = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(jid);
// If the contact isn't null and is online we try to discover
// the new set of operation sets and to notify interested
// parties. Otherwise we ignore the event.
if (contact != null)
{
// when offline, we use the contact, and selecting
// the most connected jid
// for getSupportedOperationSets
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED,
getLargestSupportedOperationSet(fullJids));
if(online)
{
// when going online we have received a presence
// and make sure we discover this particular jid
// for getSupportedOperationSets
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.
SUPPORTED_OPERATION_SETS_CHANGED,
getSupportedOperationSets(user,
online));
}
else
{
// when offline, we use the contact, and selecting
// the most connected jid
// for getSupportedOperationSets
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.
SUPPORTED_OPERATION_SETS_CHANGED,
getSupportedOperationSets(contact));
}
}
}
}
@ -516,7 +551,8 @@ public void contactPresenceStatusChanged(
{
// If the user goes offline we ensure to remove the caps node.
if (capsManager != null
&& evt.getNewStatus().getStatus() < PresenceStatus.ONLINE_THRESHOLD)
&& evt.getNewStatus().getStatus() < PresenceStatus.ONLINE_THRESHOLD
&& !evt.isResourceChanged())
{
capsManager.removeContactCapsNode(evt.getSourceContact());
}
@ -525,31 +561,59 @@ public void contactPresenceStatusChanged(
/**
* Fires event that contact capabilities has changed.
* @param user the user to search for its contact.
* @param fullJids a list of all resources of the user (full JIDs)
*/
public void fireContactCapabilitiesChanged(String user)
public void fireContactCapabilitiesChanged(String user,
ArrayList<String> fullJids)
{
OperationSetPresence opsetPresence
if(!JabberActivator.getConfigurationService()
.getBoolean(
PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT)
||fullJids.isEmpty())
{
OperationSetPresence opsetPresence
= parentProvider.getOperationSet(OperationSetPresence.class);
if (opsetPresence != null)
if (opsetPresence != null)
{
String userID = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(userID);
// this called by received discovery info for particular jid
// so we use its online and opsets for this particular jid
boolean online = false;
Presence presence = parentProvider.getConnection().getRoster()
.getPresence(user);
if(presence != null)
online = presence.isAvailable();
if(contact != null)
{
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.
SUPPORTED_OPERATION_SETS_CHANGED,
getSupportedOperationSets(user, online));
}
}
}
else
{
String userID = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(userID);
// this called by received discovery info for particular jid
// so we use its online and opsets for this particular jid
boolean online = false;
Presence presence = parentProvider.getConnection().getRoster()
.getPresence(user);
if(presence != null)
online = presence.isAvailable();
if(contact != null)
OperationSetPresence opsetPresence
= parentProvider.getOperationSet(OperationSetPresence.class);
if (opsetPresence != null)
{
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED,
getSupportedOperationSets(user, online));
String bareJid = StringUtils.parseBareAddress(user);
Contact contact = opsetPresence.findContactByID(bareJid);
if(contact != null)
{
fireContactCapabilitiesEvent(
contact,
ContactCapabilitiesEvent.
SUPPORTED_OPERATION_SETS_CHANGED,
getLargestSupportedOperationSet(fullJids));
}
}
}
}

@ -27,6 +27,7 @@
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.util.*;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.packet.*;
@ -791,7 +792,11 @@ private void requestDiscoveryInfo(final String entityID,
// fire event
if(fireEvent && capabilitiesOpSet != null)
{
capabilitiesOpSet.fireContactCapabilitiesChanged(entityID);
capabilitiesOpSet.fireContactCapabilitiesChanged(
entityID,
capsManager.getFullJidsByBareJid(
StringUtils.parseBareAddress(entityID))
);
}
}
catch(XMPPException ex)

@ -107,6 +107,14 @@ public class GeneralConfigPluginActivator
=
"net.java.sip.communicator.plugin.generalconfig.sipconfig.DISABLED";
/**
* Indicates if the XMPP configuration form should be disabled, i.e.
* not visible to the user.
*/
private static final String XMPP_CONFIG_DISABLED_PROP
=
"net.java.sip.communicator.plugin.generalconfig.xmppconfig.DISABLED";
/**
* Starts this bundle.
*/
@ -155,6 +163,22 @@ public void start(Object dependentService)
52, true),
properties);
}
if (!getConfigurationService()
.getBoolean(XMPP_CONFIG_DISABLED_PROP, false))
{
// Registers the XMPP config panel as advanced configuration form.
properties.put( ConfigurationForm.FORM_TYPE,
ConfigurationForm.ADVANCED_TYPE);
bundleContext.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
XMPPConfigForm.class.getName(),
getClass().getClassLoader(),
null,
"plugin.generalconfig.XMPP_CONFIG",
52, true),
properties);
}
properties.put( ConfigurationForm.FORM_TYPE,
ConfigurationForm.ADVANCED_TYPE);
bundleContext.registerService(

@ -0,0 +1,101 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.plugin.generalconfig;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.jitsi.service.configuration.*;
import net.java.sip.communicator.plugin.desktoputil.*;
/**
* Implementation of the configuration form.
*
* @author Timur Masar
*/
public class XMPPConfigForm
extends TransparentPanel
{
/**
* Serial version UID.
*/
private static final long serialVersionUID = 0L;
/**
* The name of the property used to control whether to use
* all resources to show capabilities
*/
public static final String PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES =
"net.java.sip.communicator.XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES";
/**
* The default value for the capabilities setting
*/
public static final boolean USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT =
true;
/**
* The <tt>ConfigurationService</tt> to be used to access configuration
*/
private final ConfigurationService configurationService
= GeneralConfigPluginActivator.getConfigurationService();
/**
* Creates the form.
*/
public XMPPConfigForm()
{
super(new BorderLayout());
Box box = Box.createVerticalBox();
add(box, BorderLayout.NORTH);
TransparentPanel contentPanel = new TransparentPanel();
contentPanel.setLayout(new BorderLayout(10, 10));
box.add(contentPanel);
TransparentPanel labelPanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
TransparentPanel valuePanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
contentPanel.add(labelPanel, BorderLayout.CENTER);
contentPanel.add(valuePanel, BorderLayout.WEST);
final JCheckBox useAllResourcesForCapabilitiesCheckbox =
new SIPCommCheckBox(Resources.getString(
"plugin.generalconfig.XMPP_USE_ALL_RESOURCES"));
useAllResourcesForCapabilitiesCheckbox.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
configurationService.setProperty(
PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
useAllResourcesForCapabilitiesCheckbox.isSelected());
}
});
useAllResourcesForCapabilitiesCheckbox.setSelected(
configurationService.getBoolean(
PROP_XMPP_USE_ALL_RESOURCES_FOR_CAPABILITIES,
USE_ALL_RESOURCES_FOR_CAPABILITIES_DEFAULT));
valuePanel.add(useAllResourcesForCapabilitiesCheckbox);
}
}
Loading…
Cancel
Save