mirror of https://github.com/sipwise/jitsi.git
Commits the patch of Sebastien Vincent provided on the dev mailing list in an e-mail with the subject "[Patch] Warnings" which fixes multiple warnings about unnecessary casts, missing or incorrect javadocs.
parent
d10540987f
commit
dfb0c91c94
@ -1,117 +1,117 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license.
|
* Distributable under LGPL license.
|
||||||
* See terms of license at gnu.org.
|
* See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.impl.gui.main.call;
|
package net.java.sip.communicator.impl.gui.main.call;
|
||||||
|
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
import net.java.sip.communicator.impl.gui.*;
|
import net.java.sip.communicator.impl.gui.*;
|
||||||
import net.java.sip.communicator.impl.gui.utils.*;
|
import net.java.sip.communicator.impl.gui.utils.*;
|
||||||
import net.java.sip.communicator.service.protocol.*;
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
import net.java.sip.communicator.util.*;
|
import net.java.sip.communicator.util.*;
|
||||||
import net.java.sip.communicator.util.swing.*;
|
import net.java.sip.communicator.util.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lubomir Marinov
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class LocalVideoButton
|
public class LocalVideoButton
|
||||||
extends SIPCommToggleButton
|
extends SIPCommToggleButton
|
||||||
{
|
{
|
||||||
private static final Logger logger
|
private static final Logger logger
|
||||||
= Logger.getLogger(LocalVideoButton.class);
|
= Logger.getLogger(LocalVideoButton.class);
|
||||||
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a <tt>LocalVideoButton</tt> by specifying the corresponding
|
* Creates a <tt>LocalVideoButton</tt> by specifying the corresponding
|
||||||
* <tt>call</tt>.
|
* <tt>call</tt>.
|
||||||
* @param call the corresponding to this button call
|
* @param call the corresponding to this button call
|
||||||
*/
|
*/
|
||||||
public LocalVideoButton(Call call)
|
public LocalVideoButton(Call call)
|
||||||
{
|
{
|
||||||
setBgImage(ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
|
setBgImage(ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
|
||||||
setBgRolloverImage(
|
setBgRolloverImage(
|
||||||
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
|
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_BG));
|
||||||
setIconImage(ImageLoader.getImage(ImageLoader.LOCAL_VIDEO_BUTTON));
|
setIconImage(ImageLoader.getImage(ImageLoader.LOCAL_VIDEO_BUTTON));
|
||||||
setPressedImage(
|
setPressedImage(
|
||||||
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_PRESSED_BG));
|
ImageLoader.getImage(ImageLoader.CALL_SETTING_BUTTON_PRESSED_BG));
|
||||||
|
|
||||||
setModel(new LocalVideoButtonModel(call));
|
setModel(new LocalVideoButtonModel(call));
|
||||||
setToolTipText(GuiActivator.getResources().getI18NString(
|
setToolTipText(GuiActivator.getResources().getI18NString(
|
||||||
"service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP"));
|
"service.gui.LOCAL_VIDEO_BUTTON_TOOL_TIP"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LocalVideoButtonModel
|
private static class LocalVideoButtonModel
|
||||||
extends ToggleButtonModel
|
extends ToggleButtonModel
|
||||||
implements ActionListener,
|
implements ActionListener,
|
||||||
Runnable
|
Runnable
|
||||||
{
|
{
|
||||||
private final Call call;
|
private final Call call;
|
||||||
|
|
||||||
private Thread runner;
|
private Thread runner;
|
||||||
|
|
||||||
public LocalVideoButtonModel(Call call)
|
public LocalVideoButtonModel(Call call)
|
||||||
{
|
{
|
||||||
this.call = call;
|
this.call = call;
|
||||||
|
|
||||||
addActionListener(this);
|
addActionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void actionPerformed(ActionEvent event)
|
public synchronized void actionPerformed(ActionEvent event)
|
||||||
{
|
{
|
||||||
if (runner == null)
|
if (runner == null)
|
||||||
{
|
{
|
||||||
runner = new Thread(this, LocalVideoButton.class.getName());
|
runner = new Thread(this, LocalVideoButton.class.getName());
|
||||||
runner.setDaemon(true);
|
runner.setDaemon(true);
|
||||||
|
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
runner.start();
|
runner.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
doRun();
|
doRun();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
if (Thread.currentThread().equals(runner))
|
if (Thread.currentThread().equals(runner))
|
||||||
{
|
{
|
||||||
runner = null;
|
runner = null;
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doRun()
|
private void doRun()
|
||||||
{
|
{
|
||||||
OperationSetVideoTelephony telephony = (OperationSetVideoTelephony)
|
OperationSetVideoTelephony telephony =
|
||||||
call.getProtocolProvider()
|
call.getProtocolProvider()
|
||||||
.getOperationSet(OperationSetVideoTelephony.class);
|
.getOperationSet(OperationSetVideoTelephony.class);
|
||||||
|
|
||||||
if (telephony != null)
|
if (telephony != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
telephony.setLocalVideoAllowed(
|
telephony.setLocalVideoAllowed(
|
||||||
call,
|
call,
|
||||||
!telephony.isLocalVideoAllowed(call));
|
!telephony.isLocalVideoAllowed(call));
|
||||||
}
|
}
|
||||||
catch (OperationFailedException ex)
|
catch (OperationFailedException ex)
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to toggle the streaming of local video.",
|
"Failed to toggle the streaming of local video.",
|
||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,416 +1,416 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license.
|
* Distributable under LGPL license.
|
||||||
* See terms of license at gnu.org.
|
* See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.impl.protocol;
|
package net.java.sip.communicator.impl.protocol;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.osgi.framework.*;
|
import org.osgi.framework.*;
|
||||||
|
|
||||||
import net.java.sip.communicator.service.protocol.*;
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
import net.java.sip.communicator.service.protocol.event.*;
|
import net.java.sip.communicator.service.protocol.event.*;
|
||||||
import net.java.sip.communicator.util.*;
|
import net.java.sip.communicator.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imposes the policy to have one call in progress i.e. to put existing calls on
|
* Imposes the policy to have one call in progress i.e. to put existing calls on
|
||||||
* hold when a new call enters in progress.
|
* hold when a new call enters in progress.
|
||||||
*
|
*
|
||||||
* @author Lubomir Marinov
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class SingleCallInProgressPolicy
|
public class SingleCallInProgressPolicy
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the configuration property which specifies whether
|
* The name of the configuration property which specifies whether
|
||||||
* <code>SingleCallInProgressPolicy</code> is enabled i.e. whether it should
|
* <code>SingleCallInProgressPolicy</code> is enabled i.e. whether it should
|
||||||
* put existing calls on hold when a new call enters in progress.
|
* put existing calls on hold when a new call enters in progress.
|
||||||
*/
|
*/
|
||||||
private static final String PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED
|
private static final String PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED
|
||||||
= "net.java.sip.communicator.impl.protocol.SingleCallInProgressPolicy.enabled";
|
= "net.java.sip.communicator.impl.protocol.SingleCallInProgressPolicy.enabled";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the listeners interfaces used by this policy.
|
* Implements the listeners interfaces used by this policy.
|
||||||
*/
|
*/
|
||||||
private class SingleCallInProgressPolicyListener
|
private class SingleCallInProgressPolicyListener
|
||||||
implements CallChangeListener,
|
implements CallChangeListener,
|
||||||
CallListener,
|
CallListener,
|
||||||
ServiceListener
|
ServiceListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Stops tracking the state of a specific <code>Call</code> and no
|
* Stops tracking the state of a specific <code>Call</code> and no
|
||||||
* longer tries to put it on hold when it ends.
|
* longer tries to put it on hold when it ends.
|
||||||
*
|
*
|
||||||
* @see CallListener#callEnded(CallEvent)
|
* @see CallListener#callEnded(CallEvent)
|
||||||
*/
|
*/
|
||||||
public void callEnded(CallEvent callEvent)
|
public void callEnded(CallEvent callEvent)
|
||||||
{
|
{
|
||||||
SingleCallInProgressPolicy.this.handleCallEvent(
|
SingleCallInProgressPolicy.this.handleCallEvent(
|
||||||
CallEvent.CALL_ENDED, callEvent);
|
CallEvent.CALL_ENDED, callEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does nothing because adding <code>CallPeer<code>s to
|
* Does nothing because adding <code>CallPeer<code>s to
|
||||||
* <code>Call</code>s isn't related to the policy to put existing calls
|
* <code>Call</code>s isn't related to the policy to put existing calls
|
||||||
* on hold when a new call becomes in-progress and just implements
|
* on hold when a new call becomes in-progress and just implements
|
||||||
* <code>CallChangeListener</code>.
|
* <code>CallChangeListener</code>.
|
||||||
*
|
*
|
||||||
* @see CallChangeListener#callPeerAdded(CallPeerEvent)
|
* @see CallChangeListener#callPeerAdded(CallPeerEvent)
|
||||||
*/
|
*/
|
||||||
public void callPeerAdded( CallPeerEvent callPeerEvent)
|
public void callPeerAdded( CallPeerEvent callPeerEvent)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Not of interest, just implementing CallChangeListener in which
|
* Not of interest, just implementing CallChangeListener in which
|
||||||
* only #callStateChanged(CallChangeEvent) is of interest.
|
* only #callStateChanged(CallChangeEvent) is of interest.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does nothing because removing <code>CallPeer<code>s to
|
* Does nothing because removing <code>CallPeer<code>s to
|
||||||
* <code>Call</code>s isn't related to the policy to put existing calls
|
* <code>Call</code>s isn't related to the policy to put existing calls
|
||||||
* on hold when a new call becomes in-progress and just implements
|
* on hold when a new call becomes in-progress and just implements
|
||||||
* <code>CallChangeListener</code>.
|
* <code>CallChangeListener</code>.
|
||||||
*
|
*
|
||||||
* @see CallChangeListener#callPeerRemoved(CallPeerEvent)
|
* @see CallChangeListener#callPeerRemoved(CallPeerEvent)
|
||||||
*/
|
*/
|
||||||
public void callPeerRemoved( CallPeerEvent callPeerEvent)
|
public void callPeerRemoved( CallPeerEvent callPeerEvent)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Not of interest, just implementing CallChangeListener in which
|
* Not of interest, just implementing CallChangeListener in which
|
||||||
* only #callStateChanged(CallChangeEvent) is of interest.
|
* only #callStateChanged(CallChangeEvent) is of interest.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upon a <code>Call</code> changing its state to
|
* Upon a <code>Call</code> changing its state to
|
||||||
* <code>CallState.CALL_IN_PROGRESS</code>, puts the other existing
|
* <code>CallState.CALL_IN_PROGRESS</code>, puts the other existing
|
||||||
* <code>Call</code>s on hold.
|
* <code>Call</code>s on hold.
|
||||||
*
|
*
|
||||||
* @param callChangeEvent the <tt>CallChangeEvent</tt> that we are to
|
* @param callChangeEvent the <tt>CallChangeEvent</tt> that we are to
|
||||||
* deliver.
|
* deliver.
|
||||||
*
|
*
|
||||||
* @see CallChangeListener#callStateChanged(CallChangeEvent)
|
* @see CallChangeListener#callStateChanged(CallChangeEvent)
|
||||||
*/
|
*/
|
||||||
public void callStateChanged(CallChangeEvent callChangeEvent)
|
public void callStateChanged(CallChangeEvent callChangeEvent)
|
||||||
{
|
{
|
||||||
SingleCallInProgressPolicy.this.callStateChanged(callChangeEvent);
|
SingleCallInProgressPolicy.this.callStateChanged(callChangeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remembers an incoming <code>Call</code> so that it can put the other
|
* Remembers an incoming <code>Call</code> so that it can put the other
|
||||||
* existing <code>Call</code>s on hold when it changes its state to
|
* existing <code>Call</code>s on hold when it changes its state to
|
||||||
* <code>CallState.CALL_IN_PROGRESS</code>.
|
* <code>CallState.CALL_IN_PROGRESS</code>.
|
||||||
*
|
*
|
||||||
* @see CallListener#incomingCallReceived(CallEvent)
|
* @see CallListener#incomingCallReceived(CallEvent)
|
||||||
*/
|
*/
|
||||||
public void incomingCallReceived(CallEvent callEvent)
|
public void incomingCallReceived(CallEvent callEvent)
|
||||||
{
|
{
|
||||||
SingleCallInProgressPolicy.this.handleCallEvent(
|
SingleCallInProgressPolicy.this.handleCallEvent(
|
||||||
CallEvent.CALL_RECEIVED, callEvent);
|
CallEvent.CALL_RECEIVED, callEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remembers an outgoing <code>Call</code> so that it can put the other
|
* Remembers an outgoing <code>Call</code> so that it can put the other
|
||||||
* existing <code>Call</code>s on hold when it changes its state to
|
* existing <code>Call</code>s on hold when it changes its state to
|
||||||
* <code>CallState.CALL_IN_PROGRESS</code>.
|
* <code>CallState.CALL_IN_PROGRESS</code>.
|
||||||
*
|
*
|
||||||
* @see CallListener#outgoingCallCreated(CallEvent)
|
* @see CallListener#outgoingCallCreated(CallEvent)
|
||||||
*/
|
*/
|
||||||
public void outgoingCallCreated(CallEvent callEvent)
|
public void outgoingCallCreated(CallEvent callEvent)
|
||||||
{
|
{
|
||||||
SingleCallInProgressPolicy.this.handleCallEvent(
|
SingleCallInProgressPolicy.this.handleCallEvent(
|
||||||
CallEvent.CALL_INITIATED, callEvent);
|
CallEvent.CALL_INITIATED, callEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts/stops tracking the new <code>Call</code>s originating from a
|
* Starts/stops tracking the new <code>Call</code>s originating from a
|
||||||
* specific <code>ProtocolProviderService</code> when it
|
* specific <code>ProtocolProviderService</code> when it
|
||||||
* registers/unregisters in order to take them into account when putting
|
* registers/unregisters in order to take them into account when putting
|
||||||
* existing calls on hold upon a new call entering its in-progress
|
* existing calls on hold upon a new call entering its in-progress
|
||||||
* state.
|
* state.
|
||||||
*
|
*
|
||||||
* @param serviceEvent
|
* @param serviceEvent
|
||||||
* the <code>ServiceEvent</code> event describing a change in
|
* the <code>ServiceEvent</code> event describing a change in
|
||||||
* the state of a service registration which may be a
|
* the state of a service registration which may be a
|
||||||
* <code>ProtocolProviderService</code> supporting
|
* <code>ProtocolProviderService</code> supporting
|
||||||
* <code>OperationSetBasicTelephony</code> and thus being
|
* <code>OperationSetBasicTelephony</code> and thus being
|
||||||
* able to create new <code>Call</code>s
|
* able to create new <code>Call</code>s
|
||||||
*/
|
*/
|
||||||
public void serviceChanged(ServiceEvent serviceEvent)
|
public void serviceChanged(ServiceEvent serviceEvent)
|
||||||
{
|
{
|
||||||
SingleCallInProgressPolicy.this.serviceChanged(serviceEvent);
|
SingleCallInProgressPolicy.this.serviceChanged(serviceEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Our class logger
|
* Our class logger
|
||||||
*/
|
*/
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
Logger.getLogger(SingleCallInProgressPolicy.class);
|
Logger.getLogger(SingleCallInProgressPolicy.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>BundleContext</code> to the Calls of which this policy applies.
|
* The <code>BundleContext</code> to the Calls of which this policy applies.
|
||||||
*/
|
*/
|
||||||
private final BundleContext bundleContext;
|
private final BundleContext bundleContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>Call</code>s this policy manages i.e. put on hold when one of
|
* The <code>Call</code>s this policy manages i.e. put on hold when one of
|
||||||
* them enters in progress.
|
* them enters in progress.
|
||||||
*/
|
*/
|
||||||
private final List<Call> calls = new ArrayList<Call>();
|
private final List<Call> calls = new ArrayList<Call>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The listener utilized by this policy to discover new <code>Call</code>
|
* The listener utilized by this policy to discover new <code>Call</code>
|
||||||
* and track their in-progress state.
|
* and track their in-progress state.
|
||||||
*/
|
*/
|
||||||
private final SingleCallInProgressPolicyListener listener =
|
private final SingleCallInProgressPolicyListener listener =
|
||||||
new SingleCallInProgressPolicyListener();
|
new SingleCallInProgressPolicyListener();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new <code>SingleCallInProgressPolicy</code> instance which
|
* Initializes a new <code>SingleCallInProgressPolicy</code> instance which
|
||||||
* will apply to the <code>Call</code>s of a specific
|
* will apply to the <code>Call</code>s of a specific
|
||||||
* <code>BundleContext</code>.
|
* <code>BundleContext</code>.
|
||||||
*
|
*
|
||||||
* @param bundleContext
|
* @param bundleContext
|
||||||
* the <code>BundleContext</code> to the
|
* the <code>BundleContext</code> to the
|
||||||
* <code>Call<code>s of which the new policy should apply
|
* <code>Call<code>s of which the new policy should apply
|
||||||
*/
|
*/
|
||||||
public SingleCallInProgressPolicy(BundleContext bundleContext)
|
public SingleCallInProgressPolicy(BundleContext bundleContext)
|
||||||
{
|
{
|
||||||
this.bundleContext = bundleContext;
|
this.bundleContext = bundleContext;
|
||||||
|
|
||||||
this.bundleContext.addServiceListener(listener);
|
this.bundleContext.addServiceListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a specific <code>Call</code> with this policy in order to have
|
* Registers a specific <code>Call</code> with this policy in order to have
|
||||||
* the rules of the latter apply to the former.
|
* the rules of the latter apply to the former.
|
||||||
*
|
*
|
||||||
* @param call
|
* @param call
|
||||||
* the <code>Call</code> to register with this policy in order to
|
* the <code>Call</code> to register with this policy in order to
|
||||||
* have the rules of the latter apply to the former
|
* have the rules of the latter apply to the former
|
||||||
*/
|
*/
|
||||||
private void addCallListener(Call call)
|
private void addCallListener(Call call)
|
||||||
{
|
{
|
||||||
synchronized (calls)
|
synchronized (calls)
|
||||||
{
|
{
|
||||||
if (!calls.contains(call))
|
if (!calls.contains(call))
|
||||||
{
|
{
|
||||||
CallState callState = call.getCallState();
|
CallState callState = call.getCallState();
|
||||||
|
|
||||||
if ((callState != null)
|
if ((callState != null)
|
||||||
&& !callState.equals(CallState.CALL_ENDED))
|
&& !callState.equals(CallState.CALL_ENDED))
|
||||||
{
|
{
|
||||||
calls.add(call);
|
calls.add(call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
call.addCallChangeListener(listener);
|
call.addCallChangeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a specific <code>OperationSetBasicTelephony</code> with this
|
* Registers a specific <code>OperationSetBasicTelephony</code> with this
|
||||||
* policy in order to have the rules of the latter apply to the
|
* policy in order to have the rules of the latter apply to the
|
||||||
* <code>Call</code>s created by the former.
|
* <code>Call</code>s created by the former.
|
||||||
*
|
*
|
||||||
* @param telephony
|
* @param telephony
|
||||||
* the <code>OperationSetBasicTelephony</code> to register with
|
* the <code>OperationSetBasicTelephony</code> to register with
|
||||||
* this policy in order to have the rules of the latter apply to
|
* this policy in order to have the rules of the latter apply to
|
||||||
* the <code>Call</code>s created by the former
|
* the <code>Call</code>s created by the former
|
||||||
*/
|
*/
|
||||||
private void addOperationSetBasicTelephonyListener(
|
private void addOperationSetBasicTelephonyListener(
|
||||||
OperationSetBasicTelephony telephony)
|
OperationSetBasicTelephony telephony)
|
||||||
{
|
{
|
||||||
telephony.addCallListener(listener);
|
telephony.addCallListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles changes in the state of a <code>Call</code> this policy applies
|
* Handles changes in the state of a <code>Call</code> this policy applies
|
||||||
* to in order to detect when new calls become in-progress and when the
|
* to in order to detect when new calls become in-progress and when the
|
||||||
* other calls should be put on hold.
|
* other calls should be put on hold.
|
||||||
*
|
*
|
||||||
* @param callChangeEvent
|
* @param callChangeEvent
|
||||||
* a <code>CallChangeEvent</code> value which describes the
|
* a <code>CallChangeEvent</code> value which describes the
|
||||||
* <code>Call</code> and the change in its state
|
* <code>Call</code> and the change in its state
|
||||||
*/
|
*/
|
||||||
private void callStateChanged(CallChangeEvent callChangeEvent)
|
private void callStateChanged(CallChangeEvent callChangeEvent)
|
||||||
{
|
{
|
||||||
Call call = callChangeEvent.getSourceCall();
|
Call call = callChangeEvent.getSourceCall();
|
||||||
|
|
||||||
if (CallState.CALL_INITIALIZATION.equals(callChangeEvent.getOldValue())
|
if (CallState.CALL_INITIALIZATION.equals(callChangeEvent.getOldValue())
|
||||||
&& CallState.CALL_IN_PROGRESS.equals(call.getCallState())
|
&& CallState.CALL_IN_PROGRESS.equals(call.getCallState())
|
||||||
&& ProtocolProviderActivator
|
&& ProtocolProviderActivator
|
||||||
.getConfigurationService()
|
.getConfigurationService()
|
||||||
.getBoolean(
|
.getBoolean(
|
||||||
PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED,
|
PNAME_SINGLE_CALL_IN_PROGRESS_POLICY_ENABLED,
|
||||||
true))
|
true))
|
||||||
{
|
{
|
||||||
synchronized (calls)
|
synchronized (calls)
|
||||||
{
|
{
|
||||||
for (Call otherCall : calls)
|
for (Call otherCall : calls)
|
||||||
if (!call.equals(otherCall)
|
if (!call.equals(otherCall)
|
||||||
&& CallState.CALL_IN_PROGRESS
|
&& CallState.CALL_IN_PROGRESS
|
||||||
.equals(otherCall.getCallState()))
|
.equals(otherCall.getCallState()))
|
||||||
putOnHold(otherCall);
|
putOnHold(otherCall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs end-of-life cleanup associated with this instance e.g. removes
|
* Performs end-of-life cleanup associated with this instance e.g. removes
|
||||||
* added listeners.
|
* added listeners.
|
||||||
*/
|
*/
|
||||||
public void dispose()
|
public void dispose()
|
||||||
{
|
{
|
||||||
bundleContext.removeServiceListener(listener);
|
bundleContext.removeServiceListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the start and end of the <code>Call</code>s this policy applies
|
* Handles the start and end of the <code>Call</code>s this policy applies
|
||||||
* to in order to have them or stop having them put the other existing calls
|
* to in order to have them or stop having them put the other existing calls
|
||||||
* on hold when the former change their states to
|
* on hold when the former change their states to
|
||||||
* <code>CallState.CALL_IN_PROGRESS</code>.
|
* <code>CallState.CALL_IN_PROGRESS</code>.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* one of {@link CallEvent#CALL_ENDED},
|
* one of {@link CallEvent#CALL_ENDED},
|
||||||
* {@link CallEvent#CALL_INITIATED} and
|
* {@link CallEvent#CALL_INITIATED} and
|
||||||
* {@link CallEvent#CALL_RECEIVED} which described the type of
|
* {@link CallEvent#CALL_RECEIVED} which described the type of
|
||||||
* the event to be handled
|
* the event to be handled
|
||||||
* @param callEvent
|
* @param callEvent
|
||||||
* a <code>CallEvent</code> value which describes the change and
|
* a <code>CallEvent</code> value which describes the change and
|
||||||
* the <code>Call</code> associated with it
|
* the <code>Call</code> associated with it
|
||||||
*/
|
*/
|
||||||
private void handleCallEvent(int type, CallEvent callEvent)
|
private void handleCallEvent(int type, CallEvent callEvent)
|
||||||
{
|
{
|
||||||
Call call = callEvent.getSourceCall();
|
Call call = callEvent.getSourceCall();
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CallEvent.CALL_ENDED:
|
case CallEvent.CALL_ENDED:
|
||||||
removeCallListener(call);
|
removeCallListener(call);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CallEvent.CALL_INITIATED:
|
case CallEvent.CALL_INITIATED:
|
||||||
case CallEvent.CALL_RECEIVED:
|
case CallEvent.CALL_RECEIVED:
|
||||||
addCallListener(call);
|
addCallListener(call);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the <code>CallPeer</code>s of a specific <code>Call</code> on
|
* Puts the <code>CallPeer</code>s of a specific <code>Call</code> on
|
||||||
* hold.
|
* hold.
|
||||||
*
|
*
|
||||||
* @param call
|
* @param call
|
||||||
* the <code>Call</code> the <code>CallPeer</code>s of
|
* the <code>Call</code> the <code>CallPeer</code>s of
|
||||||
* which are to be put on hold
|
* which are to be put on hold
|
||||||
*/
|
*/
|
||||||
private void putOnHold(Call call)
|
private void putOnHold(Call call)
|
||||||
{
|
{
|
||||||
OperationSetBasicTelephony telephony =
|
OperationSetBasicTelephony telephony =
|
||||||
(OperationSetBasicTelephony) call.getProtocolProvider()
|
call.getProtocolProvider()
|
||||||
.getOperationSet(OperationSetBasicTelephony.class);
|
.getOperationSet(OperationSetBasicTelephony.class);
|
||||||
|
|
||||||
if (telephony != null)
|
if (telephony != null)
|
||||||
{
|
{
|
||||||
for (Iterator<? extends CallPeer> peerIter =
|
for (Iterator<? extends CallPeer> peerIter =
|
||||||
call.getCallPeers(); peerIter.hasNext();)
|
call.getCallPeers(); peerIter.hasNext();)
|
||||||
{
|
{
|
||||||
CallPeer peer = peerIter.next();
|
CallPeer peer = peerIter.next();
|
||||||
CallPeerState peerState = peer.getState();
|
CallPeerState peerState = peer.getState();
|
||||||
|
|
||||||
if (!CallPeerState.DISCONNECTED.equals(peerState)
|
if (!CallPeerState.DISCONNECTED.equals(peerState)
|
||||||
&& !CallPeerState.FAILED.equals(peerState)
|
&& !CallPeerState.FAILED.equals(peerState)
|
||||||
&& !CallPeerState.isOnHold(peerState))
|
&& !CallPeerState.isOnHold(peerState))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
telephony.putOnHold(peer);
|
telephony.putOnHold(peer);
|
||||||
}
|
}
|
||||||
catch (OperationFailedException ex)
|
catch (OperationFailedException ex)
|
||||||
{
|
{
|
||||||
logger.error("Failed to put " + peer
|
logger.error("Failed to put " + peer
|
||||||
+ " on hold.", ex);
|
+ " on hold.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a specific <code>Call</code> from this policy in order to
|
* Unregisters a specific <code>Call</code> from this policy in order to
|
||||||
* have the rules of the latter no longer applied to the former.
|
* have the rules of the latter no longer applied to the former.
|
||||||
*
|
*
|
||||||
* @param call
|
* @param call
|
||||||
* the <code>Call</code> to unregister from this policy in order
|
* the <code>Call</code> to unregister from this policy in order
|
||||||
* to have the rules of the latter no longer apply to the former
|
* to have the rules of the latter no longer apply to the former
|
||||||
*/
|
*/
|
||||||
private void removeCallListener(Call call)
|
private void removeCallListener(Call call)
|
||||||
{
|
{
|
||||||
call.removeCallChangeListener(listener);
|
call.removeCallChangeListener(listener);
|
||||||
|
|
||||||
synchronized (calls)
|
synchronized (calls)
|
||||||
{
|
{
|
||||||
calls.remove(call);
|
calls.remove(call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a specific <code>OperationSetBasicTelephony</code> from this
|
* Unregisters a specific <code>OperationSetBasicTelephony</code> from this
|
||||||
* policy in order to have the rules of the latter no longer apply to the
|
* policy in order to have the rules of the latter no longer apply to the
|
||||||
* <code>Call</code>s created by the former.
|
* <code>Call</code>s created by the former.
|
||||||
*
|
*
|
||||||
* @param telephony
|
* @param telephony
|
||||||
* the <code>OperationSetBasicTelephony</code> to unregister from
|
* the <code>OperationSetBasicTelephony</code> to unregister from
|
||||||
* this policy in order to have the rules of the latter apply to
|
* this policy in order to have the rules of the latter apply to
|
||||||
* the <code>Call</code>s created by the former
|
* the <code>Call</code>s created by the former
|
||||||
*/
|
*/
|
||||||
private void removeOperationSetBasicTelephonyListener(
|
private void removeOperationSetBasicTelephonyListener(
|
||||||
OperationSetBasicTelephony telephony)
|
OperationSetBasicTelephony telephony)
|
||||||
{
|
{
|
||||||
telephony.removeCallListener(listener);
|
telephony.removeCallListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the registering and unregistering of
|
* Handles the registering and unregistering of
|
||||||
* <code>OperationSetBasicTelephony</code> instances in order to apply or
|
* <code>OperationSetBasicTelephony</code> instances in order to apply or
|
||||||
* unapply the rules of this policy to the <code>Call</code>s originating
|
* unapply the rules of this policy to the <code>Call</code>s originating
|
||||||
* from them.
|
* from them.
|
||||||
*
|
*
|
||||||
* @param serviceEvent
|
* @param serviceEvent
|
||||||
* a <code>ServiceEvent</code> value which described a change in
|
* a <code>ServiceEvent</code> value which described a change in
|
||||||
* a OSGi service and which is to be examined for the registering
|
* a OSGi service and which is to be examined for the registering
|
||||||
* or unregistering of a <code>ProtocolProviderService</code> and
|
* or unregistering of a <code>ProtocolProviderService</code> and
|
||||||
* thus a <code>OperationSetBasicTelephony</code>
|
* thus a <code>OperationSetBasicTelephony</code>
|
||||||
*/
|
*/
|
||||||
private void serviceChanged(ServiceEvent serviceEvent)
|
private void serviceChanged(ServiceEvent serviceEvent)
|
||||||
{
|
{
|
||||||
Object service =
|
Object service =
|
||||||
bundleContext.getService(serviceEvent.getServiceReference());
|
bundleContext.getService(serviceEvent.getServiceReference());
|
||||||
|
|
||||||
if (service instanceof ProtocolProviderService)
|
if (service instanceof ProtocolProviderService)
|
||||||
{
|
{
|
||||||
OperationSetBasicTelephony telephony =
|
OperationSetBasicTelephony telephony =
|
||||||
(OperationSetBasicTelephony) ((ProtocolProviderService) service)
|
((ProtocolProviderService) service)
|
||||||
.getOperationSet(OperationSetBasicTelephony.class);
|
.getOperationSet(OperationSetBasicTelephony.class);
|
||||||
|
|
||||||
if (telephony != null)
|
if (telephony != null)
|
||||||
{
|
{
|
||||||
switch (serviceEvent.getType())
|
switch (serviceEvent.getType())
|
||||||
{
|
{
|
||||||
case ServiceEvent.REGISTERED:
|
case ServiceEvent.REGISTERED:
|
||||||
addOperationSetBasicTelephonyListener(telephony);
|
addOperationSetBasicTelephonyListener(telephony);
|
||||||
break;
|
break;
|
||||||
case ServiceEvent.UNREGISTERING:
|
case ServiceEvent.UNREGISTERING:
|
||||||
removeOperationSetBasicTelephonyListener(telephony);
|
removeOperationSetBasicTelephonyListener(telephony);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,396 +1,395 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.impl.protocol.facebook;
|
package net.java.sip.communicator.impl.protocol.facebook;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.java.sip.communicator.service.protocol.*;
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
import net.java.sip.communicator.service.protocol.event.*;
|
import net.java.sip.communicator.service.protocol.event.*;
|
||||||
import net.java.sip.communicator.util.*;
|
import net.java.sip.communicator.util.*;
|
||||||
|
|
||||||
import org.apache.http.*;
|
import org.apache.http.*;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for the Facebook protocol. This class works as a bridge between the
|
* Adapter for the Facebook protocol. This class works as a bridge between the
|
||||||
* Facebook specific classes and the sip communication interfaces. It manages
|
* Facebook specific classes and the sip communication interfaces. It manages
|
||||||
* the lifecycle of the classes responsible of accessing Facebook servers and
|
* the lifecycle of the classes responsible of accessing Facebook servers and
|
||||||
* also manage the necessary {@link Thread threads} used to update the state
|
* also manage the necessary {@link Thread threads} used to update the state
|
||||||
* with the latest server changes.
|
* with the latest server changes.
|
||||||
*
|
*
|
||||||
* @author Dai Zhiwei
|
* @author Dai Zhiwei
|
||||||
* @author Lubomir Marinov
|
* @author Lubomir Marinov
|
||||||
* @author Edgar Poce
|
* @author Edgar Poce
|
||||||
*/
|
*/
|
||||||
public class FacebookAdapter
|
public class FacebookAdapter
|
||||||
implements FacebookSessionListener
|
implements FacebookSessionListener
|
||||||
{
|
{
|
||||||
private static Logger logger = Logger.getLogger(FacebookAdapter.class);
|
private static Logger logger = Logger.getLogger(FacebookAdapter.class);
|
||||||
|
|
||||||
private final OperationSetBasicInstantMessagingFacebookImpl
|
private final OperationSetBasicInstantMessagingFacebookImpl
|
||||||
basicInstantMessaging;
|
basicInstantMessaging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent service provider
|
* Parent service provider
|
||||||
*/
|
*/
|
||||||
private final ProtocolProviderServiceFacebookImpl parentProvider;
|
private final ProtocolProviderServiceFacebookImpl parentProvider;
|
||||||
|
|
||||||
private final OperationSetPersistentPresenceFacebookImpl persistentPresence;
|
private final OperationSetPersistentPresenceFacebookImpl persistentPresence;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Facebook session
|
* The Facebook session
|
||||||
*/
|
*/
|
||||||
private FacebookSession session;
|
private FacebookSession session;
|
||||||
|
|
||||||
private final OperationSetTypingNotificationsFacebookImpl
|
private final OperationSetTypingNotificationsFacebookImpl
|
||||||
typingNotifications;
|
typingNotifications;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache of typing notifications
|
* Cache of typing notifications
|
||||||
*/
|
*/
|
||||||
private final Map<String, TypingNotificationRecord> typingNotificationRecord
|
private final Map<String, TypingNotificationRecord> typingNotificationRecord
|
||||||
= new HashMap<String, TypingNotificationRecord>();
|
= new HashMap<String, TypingNotificationRecord>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for each Facebook Chat account.
|
* Adapter for each Facebook Chat account.
|
||||||
*
|
*
|
||||||
* @param parentProvider the parent service provider
|
* @param parentProvider the parent service provider
|
||||||
* @param persistentPresence
|
* @param persistentPresence
|
||||||
* @param basicInstantMessaging
|
* @param basicInstantMessaging
|
||||||
* @param typingNotifications
|
* @param typingNotifications
|
||||||
*/
|
*/
|
||||||
public FacebookAdapter(
|
public FacebookAdapter(
|
||||||
ProtocolProviderServiceFacebookImpl parentProvider,
|
ProtocolProviderServiceFacebookImpl parentProvider,
|
||||||
OperationSetPersistentPresenceFacebookImpl persistentPresence,
|
OperationSetPersistentPresenceFacebookImpl persistentPresence,
|
||||||
OperationSetBasicInstantMessagingFacebookImpl basicInstantMessaging,
|
OperationSetBasicInstantMessagingFacebookImpl basicInstantMessaging,
|
||||||
OperationSetTypingNotificationsFacebookImpl typingNotifications)
|
OperationSetTypingNotificationsFacebookImpl typingNotifications)
|
||||||
{
|
{
|
||||||
this.parentProvider = parentProvider;
|
this.parentProvider = parentProvider;
|
||||||
this.persistentPresence = persistentPresence;
|
this.persistentPresence = persistentPresence;
|
||||||
this.basicInstantMessaging = basicInstantMessaging;
|
this.basicInstantMessaging = basicInstantMessaging;
|
||||||
this.typingNotifications = typingNotifications;
|
this.typingNotifications = typingNotifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the facebook id of this account
|
* Get the facebook id of this account
|
||||||
*
|
*
|
||||||
* @return the facebook id of this account
|
* @return the facebook id of this account
|
||||||
*/
|
*/
|
||||||
public String getUID()
|
public String getUID()
|
||||||
{
|
{
|
||||||
return this.session.getUid();
|
return this.session.getUid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent service provider
|
* Get the parent service provider
|
||||||
*
|
*
|
||||||
* @return parent service provider
|
* @return parent service provider
|
||||||
*/
|
*/
|
||||||
public ProtocolProviderServiceFacebookImpl getParentProvider()
|
public ProtocolProviderServiceFacebookImpl getParentProvider()
|
||||||
{
|
{
|
||||||
return parentProvider;
|
return parentProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the {@link FacebookSession},<br>
|
* Initializes the {@link FacebookSession},<br>
|
||||||
* Initializes the {@link Thread}s to update the buddy list and to poll
|
* Initializes the {@link Thread}s to update the buddy list and to poll
|
||||||
* messages
|
* messages
|
||||||
*
|
*
|
||||||
* @param email
|
* @param email
|
||||||
* @param password
|
* @param password
|
||||||
* @return true if the user is logged in
|
* @return true if the user is logged in
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws BrokenFacebookProtocolException
|
* @throws BrokenFacebookProtocolException
|
||||||
*/
|
*/
|
||||||
public synchronized boolean initialize(
|
public synchronized boolean initialize(
|
||||||
final String email,
|
final String email,
|
||||||
final String password)
|
final String password)
|
||||||
throws OperationFailedException
|
throws OperationFailedException
|
||||||
{
|
{
|
||||||
if (this.session != null && this.session.isLoggedIn())
|
if (this.session != null && this.session.isLoggedIn())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
logger.info("initializing facebook adapter. account");
|
logger.info("initializing facebook adapter. account");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.session = new FacebookSession();
|
this.session = new FacebookSession();
|
||||||
boolean loggedIn = session.login(email, password);
|
boolean loggedIn = session.login(email, password);
|
||||||
if (loggedIn)
|
if (loggedIn)
|
||||||
session.addListener(this);
|
session.addListener(this);
|
||||||
return loggedIn;
|
return loggedIn;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw
|
throw
|
||||||
new OperationFailedException(
|
new OperationFailedException(
|
||||||
"unable to initialize adapter",
|
"unable to initialize adapter",
|
||||||
FacebookErrorException.kError_Login_GenericError,
|
FacebookErrorException.kError_Login_GenericError,
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post typing notification to the given contact.
|
* Post typing notification to the given contact.
|
||||||
*
|
*
|
||||||
* @param notifiedContact
|
* @param notifiedContact
|
||||||
* the contact we want to notify
|
* the contact we want to notify
|
||||||
* @param typingState
|
* @param typingState
|
||||||
* our current typing state(SC)
|
* our current typing state(SC)
|
||||||
* @throws HttpException
|
* @throws HttpException
|
||||||
* the http exception
|
* the http exception
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* IO exception
|
* IO exception
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
* JSON parsing exception
|
* JSON parsing exception
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* the general exception
|
* the general exception
|
||||||
*/
|
*/
|
||||||
public void postTypingNotification(Contact notifiedContact, int typingState)
|
public void postTypingNotification(Contact notifiedContact, int typingState)
|
||||||
throws HttpException,
|
throws HttpException,
|
||||||
IOException,
|
IOException,
|
||||||
JSONException,
|
JSONException,
|
||||||
Exception
|
Exception
|
||||||
{
|
{
|
||||||
TypingNotificationRecord record
|
TypingNotificationRecord record
|
||||||
= typingNotificationRecord.get(notifiedContact.getAddress());
|
= typingNotificationRecord.get(notifiedContact.getAddress());
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
record = new TypingNotificationRecord(-1l, -1);
|
record = new TypingNotificationRecord(-1l, -1);
|
||||||
synchronized (typingNotificationRecord)
|
synchronized (typingNotificationRecord)
|
||||||
{
|
{
|
||||||
typingNotificationRecord
|
typingNotificationRecord
|
||||||
.put(notifiedContact.getAddress(), record);
|
.put(notifiedContact.getAddress(), record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (record.getTime() < System.currentTimeMillis() - 1000)
|
if (record.getTime() < System.currentTimeMillis() - 1000)
|
||||||
{
|
{
|
||||||
FacebookOutgoingTypingNotification msg
|
FacebookOutgoingTypingNotification msg
|
||||||
= new FacebookOutgoingTypingNotification(session);
|
= new FacebookOutgoingTypingNotification(session);
|
||||||
msg.setAddress(notifiedContact.getAddress());
|
msg.setAddress(notifiedContact.getAddress());
|
||||||
msg.setTypingState(typingState);
|
msg.setTypingState(typingState);
|
||||||
msg.send();
|
msg.send();
|
||||||
record.setTime(System.currentTimeMillis());
|
record.setTime(System.currentTimeMillis());
|
||||||
record.setType(typingState);
|
record.setType(typingState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatusMessage(String statusMessage)
|
public void setStatusMessage(String statusMessage)
|
||||||
throws OperationFailedException
|
throws OperationFailedException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.session.setStatusMessage(statusMessage);
|
this.session.setStatusMessage(statusMessage);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw
|
throw
|
||||||
new OperationFailedException(
|
new OperationFailedException(
|
||||||
"unable to change facebook status message",
|
"unable to change facebook status message",
|
||||||
-1,
|
-1,
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void shutdown()
|
public synchronized void shutdown()
|
||||||
{
|
{
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
logger.info("shutting down facebook adapter");
|
logger.info("shutting down facebook adapter");
|
||||||
session.logout();
|
session.logout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
* @param to
|
* @param to
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public synchronized MessageDeliveryFailedEvent postMessage(
|
public synchronized MessageDeliveryFailedEvent postMessage(
|
||||||
Message message,
|
Message message,
|
||||||
Contact to)
|
Contact to)
|
||||||
{
|
{
|
||||||
FacebookOutgoingMailboxMessage msg
|
FacebookOutgoingMailboxMessage msg
|
||||||
= new FacebookOutgoingMailboxMessage(session);
|
= new FacebookOutgoingMailboxMessage(session);
|
||||||
msg.setAddress(to.getAddress());
|
msg.setAddress(to.getAddress());
|
||||||
msg.setContent(message.getContent());
|
msg.setContent(message.getContent());
|
||||||
msg.setSubject(message.getSubject());
|
msg.setSubject(message.getSubject());
|
||||||
msg.setUid(message.getMessageUID());
|
msg.setUid(message.getMessageUID());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
msg.send();
|
msg.send();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (BrokenFacebookProtocolException e)
|
catch (BrokenFacebookProtocolException e)
|
||||||
{
|
{
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
return new MessageDeliveryFailedEvent(message, to, -1, System
|
return new MessageDeliveryFailedEvent(message, to, -1, System
|
||||||
.currentTimeMillis(), e.getMessage());
|
.currentTimeMillis(), e.getMessage());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
logger.warn(e);
|
logger.warn(e);
|
||||||
return new MessageDeliveryFailedEvent(message, to, -1, System
|
return new MessageDeliveryFailedEvent(message, to, -1, System
|
||||||
.currentTimeMillis(), e.getMessage());
|
.currentTimeMillis(), e.getMessage());
|
||||||
}
|
}
|
||||||
catch (FacebookErrorException e)
|
catch (FacebookErrorException e)
|
||||||
{
|
{
|
||||||
return new MessageDeliveryFailedEvent(message, to, e.getCode());
|
return new MessageDeliveryFailedEvent(message, to, e.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageDeliveryFailedEvent postFacebookChatMessage(
|
public MessageDeliveryFailedEvent postFacebookChatMessage(
|
||||||
Message message,
|
Message message,
|
||||||
Contact to)
|
Contact to)
|
||||||
{
|
{
|
||||||
FacebookOutgoingChatMessage msg
|
FacebookOutgoingChatMessage msg
|
||||||
= new FacebookOutgoingChatMessage(session);
|
= new FacebookOutgoingChatMessage(session);
|
||||||
msg.setAddress(to.getAddress());
|
msg.setAddress(to.getAddress());
|
||||||
msg.setContent(message.getContent());
|
msg.setContent(message.getContent());
|
||||||
msg.setMessageUid(message.getMessageUID());
|
msg.setMessageUid(message.getMessageUID());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
msg.send();
|
msg.send();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (BrokenFacebookProtocolException e)
|
catch (BrokenFacebookProtocolException e)
|
||||||
{
|
{
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
return new MessageDeliveryFailedEvent(message, to, -1, System
|
return new MessageDeliveryFailedEvent(message, to, -1, System
|
||||||
.currentTimeMillis(), e.getMessage());
|
.currentTimeMillis(), e.getMessage());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
logger.warn(e);
|
logger.warn(e);
|
||||||
return new MessageDeliveryFailedEvent(message, to, -1, System
|
return new MessageDeliveryFailedEvent(message, to, -1, System
|
||||||
.currentTimeMillis(), e.getMessage());
|
.currentTimeMillis(), e.getMessage());
|
||||||
}
|
}
|
||||||
catch (FacebookErrorException e)
|
catch (FacebookErrorException e)
|
||||||
{
|
{
|
||||||
return new MessageDeliveryFailedEvent(message, to, e.getCode());
|
return new MessageDeliveryFailedEvent(message, to, e.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promotes the incoming message to the GUI
|
* Promotes the incoming message to the GUI
|
||||||
*
|
*
|
||||||
* @see FacebookIncomingMessageListener#onIncomingChatMessage(FacebookMessage)
|
* @see FacebookSessionListener#onIncomingChatMessage(FacebookMessage)
|
||||||
*/
|
*/
|
||||||
public void onIncomingChatMessage(FacebookMessage msg)
|
public void onIncomingChatMessage(FacebookMessage msg)
|
||||||
{
|
{
|
||||||
if (!msg.getFrom().equals(this.session.getUid()))
|
if (!msg.getFrom().equals(this.session.getUid()))
|
||||||
basicInstantMessaging.receivedInstantMessage(msg);
|
basicInstantMessaging.receivedInstantMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promotes the incoming notification to the GUI
|
* Promotes the incoming notification to the GUI
|
||||||
*
|
*
|
||||||
* @see FacebookIncomingMessageListener#onIncomingTypingNotification(String,
|
* @see FacebookSessionListener#onIncomingTypingNotification(String, int)
|
||||||
* int)
|
*/
|
||||||
*/
|
public void onIncomingTypingNotification(String buddyUid, int state)
|
||||||
public void onIncomingTypingNotification(String buddyUid, int state)
|
{
|
||||||
{
|
if (!buddyUid.equals(this.session.getUid()))
|
||||||
if (!buddyUid.equals(this.session.getUid()))
|
{
|
||||||
{
|
Contact fromContact = persistentPresence.findContactByID(buddyUid);
|
||||||
Contact fromContact = persistentPresence.findContactByID(buddyUid);
|
if (fromContact == null)
|
||||||
if (fromContact == null)
|
fromContact
|
||||||
fromContact
|
= persistentPresence.createVolatileContact(buddyUid);
|
||||||
= persistentPresence.createVolatileContact(buddyUid);
|
|
||||||
|
int typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
|
||||||
int typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
|
switch (state)
|
||||||
switch (state)
|
{
|
||||||
{
|
case 1:
|
||||||
case 1:
|
typingState = OperationSetTypingNotifications.STATE_TYPING;
|
||||||
typingState = OperationSetTypingNotifications.STATE_TYPING;
|
break;
|
||||||
break;
|
case 0:
|
||||||
case 0:
|
typingState = OperationSetTypingNotifications.STATE_STOPPED;
|
||||||
typingState = OperationSetTypingNotifications.STATE_STOPPED;
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
|
||||||
typingState = OperationSetTypingNotifications.STATE_UNKNOWN;
|
}
|
||||||
}
|
|
||||||
|
typingNotifications
|
||||||
typingNotifications
|
.receivedTypingNotification(fromContact, typingState);
|
||||||
.receivedTypingNotification(fromContact, typingState);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* notifies SC that the connection is lost
|
||||||
* notifies SC that the connection is lost
|
*/
|
||||||
*/
|
public void onFacebookConnectionLost() {
|
||||||
public void onFacebookConnectionLost() {
|
if (parentProvider.isRegistered())
|
||||||
if (parentProvider.isRegistered())
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
parentProvider.unregister();
|
||||||
parentProvider.unregister();
|
}
|
||||||
}
|
catch (OperationFailedException e)
|
||||||
catch (OperationFailedException e)
|
{
|
||||||
{
|
logger.error("unable to unregister", e);
|
||||||
logger.error("unable to unregister", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// tag all the buddies as offline
|
||||||
// tag all the buddies as offline
|
persistentPresence
|
||||||
persistentPresence
|
.setPresenceStatusForAllContacts(FacebookStatusEnum.OFFLINE);
|
||||||
.setPresenceStatusForAllContacts(FacebookStatusEnum.OFFLINE);
|
}
|
||||||
}
|
|
||||||
|
public void onBuddyListUpdated()
|
||||||
public void onBuddyListUpdated()
|
{
|
||||||
{
|
for (FacebookUser user : this.session.getBuddyList().getBuddies())
|
||||||
for (FacebookUser user : this.session.getBuddyList().getBuddies())
|
{
|
||||||
{
|
PresenceStatus newStatus;
|
||||||
PresenceStatus newStatus;
|
if (user.isOnline && user.isIdle)
|
||||||
if (user.isOnline && user.isIdle)
|
newStatus = FacebookStatusEnum.IDLE;
|
||||||
newStatus = FacebookStatusEnum.IDLE;
|
else if (user.isOnline)
|
||||||
else if (user.isOnline)
|
newStatus = FacebookStatusEnum.ONLINE;
|
||||||
newStatus = FacebookStatusEnum.ONLINE;
|
else
|
||||||
else
|
newStatus = FacebookStatusEnum.OFFLINE;
|
||||||
newStatus = FacebookStatusEnum.OFFLINE;
|
|
||||||
|
persistentPresence.setPresenceStatusForContact(user.uid, newStatus);
|
||||||
persistentPresence.setPresenceStatusForContact(user.uid, newStatus);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public FacebookSession getSession()
|
||||||
public FacebookSession getSession()
|
{
|
||||||
{
|
return session;
|
||||||
return session;
|
}
|
||||||
}
|
|
||||||
|
private static class TypingNotificationRecord
|
||||||
private static class TypingNotificationRecord
|
{
|
||||||
{
|
private long time;
|
||||||
private long time;
|
private int type;
|
||||||
private int type;
|
|
||||||
|
public TypingNotificationRecord(long time, int type)
|
||||||
public TypingNotificationRecord(long time, int type)
|
{
|
||||||
{
|
this.time = time;
|
||||||
this.time = time;
|
this.type = type;
|
||||||
this.type = type;
|
}
|
||||||
}
|
|
||||||
|
public long getTime()
|
||||||
public long getTime()
|
{
|
||||||
{
|
return time;
|
||||||
return time;
|
}
|
||||||
}
|
|
||||||
|
public int getType()
|
||||||
public int getType()
|
{
|
||||||
{
|
return type;
|
||||||
return type;
|
}
|
||||||
}
|
|
||||||
|
public void setTime(long time)
|
||||||
public void setTime(long time)
|
{
|
||||||
{
|
this.time = time;
|
||||||
this.time = time;
|
}
|
||||||
}
|
|
||||||
|
public void setType(int type)
|
||||||
public void setType(int type)
|
{
|
||||||
{
|
this.type = type;
|
||||||
this.type = type;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,288 +1,287 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.impl.protocol.facebook;
|
package net.java.sip.communicator.impl.protocol.facebook;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.java.sip.communicator.util.*;
|
import net.java.sip.communicator.util.*;
|
||||||
|
|
||||||
import org.apache.http.*;
|
import org.apache.http.*;
|
||||||
import org.apache.http.client.entity.*;
|
import org.apache.http.client.entity.*;
|
||||||
import org.apache.http.client.methods.*;
|
import org.apache.http.client.methods.*;
|
||||||
import org.apache.http.message.*;
|
import org.apache.http.message.*;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
import org.apache.http.util.*;
|
import org.apache.http.util.*;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facebook buddy list that store the online buddies information we got from the
|
* Facebook buddy list that store the online buddies information we got from the
|
||||||
* server since we logged in. Some information of ourselves also included. <br>
|
* server since we logged in. Some information of ourselves also included. <br>
|
||||||
* This class is responsible of establishing the http connections and updating
|
* This class is responsible of establishing the http connections and updating
|
||||||
* its state when requested.
|
* its state when requested.
|
||||||
*
|
*
|
||||||
* @author Dai Zhiwei
|
* @author Dai Zhiwei
|
||||||
* @author Edgar Poce
|
* @author Edgar Poce
|
||||||
*/
|
*/
|
||||||
public class FacebookBuddyList
|
public class FacebookBuddyList
|
||||||
{
|
{
|
||||||
private static Logger logger = Logger.getLogger(FacebookBuddyList.class);
|
private static Logger logger = Logger.getLogger(FacebookBuddyList.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url of the update
|
* The url of the update
|
||||||
*/
|
*/
|
||||||
private static final String BUDDYLIST_URL
|
private static final String BUDDYLIST_URL
|
||||||
= "http://www.facebook.com/ajax/chat/buddy_list.php";
|
= "http://www.facebook.com/ajax/chat/buddy_list.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Facebook Session
|
* The Facebook Session
|
||||||
*/
|
*/
|
||||||
private final FacebookSession session;
|
private final FacebookSession session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Our (online) buddies' information cache
|
* Our (online) buddies' information cache
|
||||||
*/
|
*/
|
||||||
private transient Map<String, FacebookUser> cache
|
private transient Map<String, FacebookUser> cache
|
||||||
= new LinkedHashMap<String, FacebookUser>();
|
= new LinkedHashMap<String, FacebookUser>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some information of ourselves/myself.
|
* Some information of ourselves/myself.
|
||||||
*/
|
*/
|
||||||
private transient FacebookUser me;
|
private transient FacebookUser me;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener of this buddy list
|
* Listener of this buddy list
|
||||||
*/
|
*/
|
||||||
private List<FacebookSessionListener> listeners
|
private List<FacebookSessionListener> listeners
|
||||||
= new ArrayList<FacebookSessionListener>();
|
= new ArrayList<FacebookSessionListener>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the cache and the parent adapter.
|
* Init the cache and the parent adapter.
|
||||||
*
|
*
|
||||||
* @param adapter
|
* @param session the Facebook session
|
||||||
*/
|
*/
|
||||||
public FacebookBuddyList(FacebookSession session)
|
public FacebookBuddyList(FacebookSession session)
|
||||||
{
|
{
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
throws BrokenFacebookProtocolException,
|
throws BrokenFacebookProtocolException,
|
||||||
IOException,
|
IOException,
|
||||||
FacebookErrorException
|
FacebookErrorException
|
||||||
{
|
{
|
||||||
// reconnecting
|
// reconnecting
|
||||||
this.session.reconnect();
|
this.session.reconnect();
|
||||||
logger.info("Updating buddy list...");
|
logger.info("Updating buddy list...");
|
||||||
// perform POST request
|
// perform POST request
|
||||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||||
nvps.add(new BasicNameValuePair("buddy_list", "1"));
|
nvps.add(new BasicNameValuePair("buddy_list", "1"));
|
||||||
nvps.add(new BasicNameValuePair("notifications", "1"));
|
nvps.add(new BasicNameValuePair("notifications", "1"));
|
||||||
nvps.add(new BasicNameValuePair("force_render", "true"));
|
nvps.add(new BasicNameValuePair("force_render", "true"));
|
||||||
nvps.add(new BasicNameValuePair("post_form_id", session.getFormId()));
|
nvps.add(new BasicNameValuePair("post_form_id", session.getFormId()));
|
||||||
nvps.add(new BasicNameValuePair("user", session.getUid()));
|
nvps.add(new BasicNameValuePair("user", session.getUid()));
|
||||||
HttpPost post = new HttpPost(BUDDYLIST_URL);
|
HttpPost post = new HttpPost(BUDDYLIST_URL);
|
||||||
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
|
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
|
||||||
HttpResponse response = this.session.getHttpClient().execute(post);
|
HttpResponse response = this.session.getHttpClient().execute(post);
|
||||||
String body = EntityUtils.toString(response.getEntity());
|
String body = EntityUtils.toString(response.getEntity());
|
||||||
if (response.getStatusLine().getStatusCode() != 200)
|
if (response.getStatusLine().getStatusCode() != 200)
|
||||||
{
|
{
|
||||||
throw new BrokenFacebookProtocolException("Code "
|
throw new BrokenFacebookProtocolException("Code "
|
||||||
+ response.getStatusLine().getStatusCode()
|
+ response.getStatusLine().getStatusCode()
|
||||||
+ ". Unable to update Facebook buddy list.");
|
+ ". Unable to update Facebook buddy list.");
|
||||||
}
|
}
|
||||||
this.update(body);
|
this.update(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get meta info of this account
|
* Get meta info of this account
|
||||||
*
|
*
|
||||||
* @return meta info of this account
|
* @return meta info of this account
|
||||||
*/
|
*/
|
||||||
public FacebookUser getMyMetaInfo()
|
public FacebookUser getMyMetaInfo()
|
||||||
{
|
{
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get our buddy who has the given id from the cache.
|
* Get our buddy who has the given id from the cache.
|
||||||
*
|
*
|
||||||
* @param contactID
|
* @param uid the id we want to look up
|
||||||
* the id we wanna look up
|
* @return the buddy who has the given id
|
||||||
* @return the buddy who has the given id
|
* @throws FacebookErrorException
|
||||||
* @throws FacebookErrorException
|
* @throws IOException
|
||||||
* @throws IOException
|
* @throws BrokenFacebookProtocolException
|
||||||
* @throws BrokenFacebookProtocolException
|
*/
|
||||||
*/
|
public FacebookUser getBuddyByUID(String uid)
|
||||||
public FacebookUser getBuddyByUID(String uid)
|
throws BrokenFacebookProtocolException,
|
||||||
throws BrokenFacebookProtocolException,
|
IOException,
|
||||||
IOException,
|
FacebookErrorException
|
||||||
FacebookErrorException
|
{
|
||||||
{
|
FacebookUser buddy = this.cache.get(uid);
|
||||||
FacebookUser buddy = this.cache.get(uid);
|
if (buddy == null && this.me != null && this.me.uid.equals(uid))
|
||||||
if (buddy == null && this.me != null && this.me.uid.equals(uid))
|
{
|
||||||
{
|
buddy = me;
|
||||||
buddy = me;
|
}
|
||||||
}
|
return buddy;
|
||||||
return buddy;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* @return the users in the cache
|
||||||
* @return the users in the cache
|
*/
|
||||||
*/
|
public Collection<FacebookUser> getBuddies()
|
||||||
public Collection<FacebookUser> getBuddies()
|
{
|
||||||
{
|
return Collections.unmodifiableCollection(this.cache.values());
|
||||||
return Collections.unmodifiableCollection(this.cache.values());
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Release the resource
|
||||||
* Release the resource
|
*/
|
||||||
*/
|
public void clear()
|
||||||
public void clear()
|
{
|
||||||
{
|
for (FacebookUser u : this.cache.values())
|
||||||
for (FacebookUser u : this.cache.values())
|
{
|
||||||
{
|
u.isOnline = false;
|
||||||
u.isOnline = false;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Updates the buddy list<br>
|
||||||
* Updates the buddy list<br>
|
* If the {@link FacebookSession} is logged out then this method returns
|
||||||
* If the {@link FacebookSession} is logged out then this method returns
|
* without modifying the state of the buddy list.
|
||||||
* without modifying the state of the buddy list.
|
*
|
||||||
*
|
* @param body
|
||||||
* @param body
|
* @throws BrokenFacebookProtocolException
|
||||||
* @throws BrokenFacebookProtocolException
|
* @throws FacebookErrorException
|
||||||
* @throws FacebookErrorException
|
*/
|
||||||
*/
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
public void update(String body)
|
||||||
public void update(String body)
|
throws BrokenFacebookProtocolException,
|
||||||
throws BrokenFacebookProtocolException,
|
FacebookErrorException
|
||||||
FacebookErrorException
|
{
|
||||||
{
|
// the session might be getting closed by another thread
|
||||||
// the session might be getting closed by another thread
|
// do nothing if it's logged out
|
||||||
// do nothing if it's logged out
|
synchronized (session)
|
||||||
synchronized (session)
|
{
|
||||||
{
|
if (!session.isLoggedIn())
|
||||||
if (!session.isLoggedIn())
|
{
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
JSONObject jsonBuddyList = parseBody(body);
|
||||||
JSONObject jsonBuddyList = parseBody(body);
|
try {
|
||||||
try {
|
/*
|
||||||
/*
|
* If listChanged, then we can get the buddies available via looking
|
||||||
* If listChanged, then we can get the buddies available via looking
|
* at the nowAvailableList else. we can only get the buddies' info,
|
||||||
* at the nowAvailableList else. we can only get the buddies' info,
|
* and the nowAvailableList is empty.
|
||||||
* and the nowAvailableList is empty.
|
*/
|
||||||
*/
|
JSONObject userInfos = (JSONObject) jsonBuddyList.get("userInfos");
|
||||||
JSONObject userInfos = (JSONObject) jsonBuddyList.get("userInfos");
|
if (userInfos != null)
|
||||||
if (userInfos != null)
|
{
|
||||||
{
|
// Then add the new buddies and set them as online(constructor)
|
||||||
// Then add the new buddies and set them as online(constructor)
|
Iterator<String> it = userInfos.keys();
|
||||||
Iterator<String> it = userInfos.keys();
|
while (it.hasNext())
|
||||||
while (it.hasNext())
|
{
|
||||||
{
|
String key = it.next();
|
||||||
String key = it.next();
|
JSONObject jsonUser = (JSONObject) userInfos.get(key);
|
||||||
JSONObject jsonUser = (JSONObject) userInfos.get(key);
|
if (jsonUser == null)
|
||||||
if (jsonUser == null)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(
|
||||||
throw new BrokenFacebookProtocolException(
|
"unable to get user info. " + userInfos);
|
||||||
"unable to get user info. " + userInfos);
|
}
|
||||||
}
|
FacebookUser buddy = new FacebookUser(key, jsonUser);
|
||||||
FacebookUser buddy = new FacebookUser(key, jsonUser);
|
if (buddy.uid.equals(this.session.getUid()))
|
||||||
if (buddy.uid.equals(this.session.getUid()))
|
{
|
||||||
{
|
this.me = buddy;
|
||||||
this.me = buddy;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
this.cache.put(key, buddy);
|
||||||
this.cache.put(key, buddy);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
JSONObject nowAvailableList = jsonBuddyList
|
||||||
JSONObject nowAvailableList = jsonBuddyList
|
.getJSONObject("nowAvailableList");
|
||||||
.getJSONObject("nowAvailableList");
|
|
||||||
|
if (nowAvailableList == null)
|
||||||
if (nowAvailableList == null)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(
|
||||||
throw new BrokenFacebookProtocolException(
|
"Unable to read Facebook now available list");
|
||||||
"Unable to read Facebook now available list");
|
}
|
||||||
}
|
|
||||||
|
for (FacebookUser user : this.cache.values())
|
||||||
for (FacebookUser user : this.cache.values())
|
{
|
||||||
{
|
if (nowAvailableList.has(user.uid))
|
||||||
if (nowAvailableList.has(user.uid))
|
{
|
||||||
{
|
user.isOnline = true;
|
||||||
user.isOnline = true;
|
user.lastSeen = Calendar.getInstance().getTimeInMillis();
|
||||||
user.lastSeen = Calendar.getInstance().getTimeInMillis();
|
user.isIdle = nowAvailableList.getJSONObject(user.uid)
|
||||||
user.isIdle = nowAvailableList.getJSONObject(user.uid)
|
.getBoolean("i");
|
||||||
.getBoolean("i");
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
user.isOnline = false;
|
||||||
user.isOnline = false;
|
}
|
||||||
}
|
}
|
||||||
}
|
// notify listeners
|
||||||
// notify listeners
|
for (FacebookSessionListener l : this.listeners)
|
||||||
for (FacebookSessionListener l : this.listeners)
|
l.onBuddyListUpdated();
|
||||||
l.onBuddyListUpdated();
|
}
|
||||||
}
|
catch (JSONException e)
|
||||||
catch (JSONException e)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(e);
|
||||||
throw new BrokenFacebookProtocolException(e);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private JSONObject parseBody(String body)
|
||||||
private JSONObject parseBody(String body)
|
throws BrokenFacebookProtocolException,
|
||||||
throws BrokenFacebookProtocolException,
|
FacebookErrorException
|
||||||
FacebookErrorException
|
{
|
||||||
{
|
FacebookJsonResponse jsonResponse = new FacebookJsonResponse(session,
|
||||||
FacebookJsonResponse jsonResponse = new FacebookJsonResponse(session,
|
body);
|
||||||
body);
|
try
|
||||||
try
|
{
|
||||||
{
|
JSONObject json = jsonResponse.getJson();
|
||||||
JSONObject json = jsonResponse.getJson();
|
JSONObject payload = (JSONObject) json.get("payload");
|
||||||
JSONObject payload = (JSONObject) json.get("payload");
|
if (payload == null)
|
||||||
if (payload == null)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(
|
||||||
throw new BrokenFacebookProtocolException(
|
"unable to parse buddy list. there's no payload field. "
|
||||||
"unable to parse buddy list. there's no payload field. "
|
+ jsonResponse);
|
||||||
+ jsonResponse);
|
}
|
||||||
}
|
JSONObject jsonBuddyList = (JSONObject) payload.get("buddy_list");
|
||||||
JSONObject jsonBuddyList = (JSONObject) payload.get("buddy_list");
|
if (jsonBuddyList == null)
|
||||||
if (jsonBuddyList == null)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(
|
||||||
throw new BrokenFacebookProtocolException(
|
"unable to parse buddy list. there's no buddy list field. "
|
||||||
"unable to parse buddy list. there's no buddy list field. "
|
+ jsonResponse);
|
||||||
+ jsonResponse);
|
}
|
||||||
}
|
return jsonBuddyList;
|
||||||
return jsonBuddyList;
|
}
|
||||||
}
|
catch (JSONException e)
|
||||||
catch (JSONException e)
|
{
|
||||||
{
|
throw new BrokenFacebookProtocolException(
|
||||||
throw new BrokenFacebookProtocolException(
|
"unable to parse json response");
|
||||||
"unable to parse json response");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public int getSize()
|
||||||
public int getSize()
|
{
|
||||||
{
|
return this.cache.size();
|
||||||
return this.cache.size();
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Adds a listener which is notified when the buddy list state changes
|
||||||
* Adds a listener which is notified when the buddy list state changes
|
*
|
||||||
*
|
* @param listener
|
||||||
* @param listener
|
*/
|
||||||
*/
|
public void addListener(FacebookSessionListener listener)
|
||||||
public void addListener(FacebookSessionListener listener)
|
{
|
||||||
{
|
this.listeners.add(listener);
|
||||||
this.listeners.add(listener);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,266 +1,265 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.impl.protocol.facebook;
|
package net.java.sip.communicator.impl.protocol.facebook;
|
||||||
|
|
||||||
import net.java.sip.communicator.service.protocol.*;
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
import net.java.sip.communicator.service.protocol.event.*;
|
import net.java.sip.communicator.service.protocol.event.*;
|
||||||
import net.java.sip.communicator.util.*;
|
import net.java.sip.communicator.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instant messaging functionality for the Facebook protocol.
|
* Instant messaging functionality for the Facebook protocol.
|
||||||
*
|
*
|
||||||
* @author Dai Zhiwei
|
* @author Dai Zhiwei
|
||||||
* @author Lubomir Marinov
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class OperationSetBasicInstantMessagingFacebookImpl
|
public class OperationSetBasicInstantMessagingFacebookImpl
|
||||||
extends AbstractOperationSetBasicInstantMessaging
|
extends AbstractOperationSetBasicInstantMessaging
|
||||||
{
|
{
|
||||||
private static final Logger logger
|
private static final Logger logger
|
||||||
= Logger.getLogger(OperationSetBasicInstantMessagingFacebookImpl.class);
|
= Logger.getLogger(OperationSetBasicInstantMessagingFacebookImpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The currently valid persistent presence operation set..
|
* The currently valid persistent presence operation set..
|
||||||
*/
|
*/
|
||||||
private OperationSetPersistentPresenceFacebookImpl opSetPersPresence = null;
|
private OperationSetPersistentPresenceFacebookImpl opSetPersPresence = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The protocol provider that created us.
|
* The protocol provider that created us.
|
||||||
*/
|
*/
|
||||||
private ProtocolProviderServiceFacebookImpl parentProvider = null;
|
private ProtocolProviderServiceFacebookImpl parentProvider = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of this operation set keeping a reference to the
|
* Creates an instance of this operation set keeping a reference to the
|
||||||
* parent protocol provider and presence operation set.
|
* parent protocol provider and presence operation set.
|
||||||
*
|
*
|
||||||
* @param provider The provider instance that creates us.
|
* @param provider The provider instance that creates us.
|
||||||
* @param opSetPersPresence the currently valid
|
* @param opSetPersPresence the currently valid
|
||||||
* <tt>OperationSetPersistentPresenceFacebookImpl</tt>
|
* <tt>OperationSetPersistentPresenceFacebookImpl</tt>
|
||||||
* instance.
|
* instance.
|
||||||
*/
|
*/
|
||||||
public OperationSetBasicInstantMessagingFacebookImpl(
|
public OperationSetBasicInstantMessagingFacebookImpl(
|
||||||
ProtocolProviderServiceFacebookImpl provider,
|
ProtocolProviderServiceFacebookImpl provider,
|
||||||
OperationSetPersistentPresenceFacebookImpl opSetPersPresence)
|
OperationSetPersistentPresenceFacebookImpl opSetPersPresence)
|
||||||
{
|
{
|
||||||
this.opSetPersPresence = opSetPersPresence;
|
this.opSetPersPresence = opSetPersPresence;
|
||||||
this.parentProvider = provider;
|
this.parentProvider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Implements
|
* Implements
|
||||||
* AbstractOperationSetBasicInstantMessaging#createMessage(String, String,
|
* AbstractOperationSetBasicInstantMessaging#createMessage(String, String,
|
||||||
* String, String). Creates a new MessageFacebookImpl instance with the
|
* String, String). Creates a new MessageFacebookImpl instance with the
|
||||||
* specified properties.
|
* specified properties.
|
||||||
*/
|
*/
|
||||||
public Message createMessage(
|
public Message createMessage(
|
||||||
String content, String contentType, String encoding, String subject)
|
String content, String contentType, String encoding, String subject)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
new MessageFacebookImpl(content, contentType, encoding, subject);
|
new MessageFacebookImpl(content, contentType, encoding, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the <tt>message</tt> to the destination indicated by the
|
* Sends the <tt>message</tt> to the destination indicated by the
|
||||||
* <tt>to</tt> contact.
|
* <tt>to</tt> contact.
|
||||||
*
|
*
|
||||||
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
|
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
|
||||||
* @param message the <tt>Message</tt> to send.
|
* @param message the <tt>Message</tt> to send.
|
||||||
* @throws IllegalStateException if the underlying ICQ stack is not
|
* @throws IllegalStateException if the underlying ICQ stack is not
|
||||||
* registered and initialized.
|
* registered and initialized.
|
||||||
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
|
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
|
||||||
* belonging to the underlying implementation.
|
* belonging to the underlying implementation.
|
||||||
*/
|
*/
|
||||||
public void sendInstantMessage(final Contact to, final Message message)
|
public void sendInstantMessage(final Contact to, final Message message)
|
||||||
throws IllegalStateException,
|
throws IllegalStateException,
|
||||||
IllegalArgumentException
|
IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (!(to instanceof ContactFacebookImpl))
|
if (!(to instanceof ContactFacebookImpl))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"The specified contact is not a Facebook contact." + to);
|
"The specified contact is not a Facebook contact." + to);
|
||||||
|
|
||||||
Thread sender = new Thread(new Runnable()
|
Thread sender = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// deliver the facebook chat Message
|
// deliver the facebook chat Message
|
||||||
MessageDeliveryFailedEvent errorEvent = null;
|
MessageDeliveryFailedEvent errorEvent = null;
|
||||||
errorEvent =
|
errorEvent =
|
||||||
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
|
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
|
||||||
.getAdapter().postFacebookChatMessage(message, to);
|
.getAdapter().postFacebookChatMessage(message, to);
|
||||||
if (errorEvent == null)
|
if (errorEvent == null)
|
||||||
{
|
{
|
||||||
fireMessageDelivered(message, to);
|
fireMessageDelivered(message, to);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|
||||||
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
|
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
|
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
|
||||||
}
|
}
|
||||||
catch (OperationFailedException e1)
|
catch (OperationFailedException e1)
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
"Unable to unregister the protocol provider: "
|
"Unable to unregister the protocol provider: "
|
||||||
+ this
|
+ this
|
||||||
+ " due to the following exception: " + e1);
|
+ " due to the following exception: " + e1);
|
||||||
}
|
}
|
||||||
fireMessageDeliveryFailed(
|
fireMessageDeliveryFailed(
|
||||||
message,
|
message,
|
||||||
to,
|
to,
|
||||||
MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED);
|
MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the above delivery failed, we try again!
|
// if the above delivery failed, we try again!
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// wait a moment
|
// wait a moment
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
errorEvent =
|
errorEvent =
|
||||||
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
|
OperationSetBasicInstantMessagingFacebookImpl.this.parentProvider
|
||||||
.getAdapter().postFacebookChatMessage(message, to);
|
.getAdapter().postFacebookChatMessage(message, to);
|
||||||
if (errorEvent == null)
|
if (errorEvent == null)
|
||||||
{
|
{
|
||||||
fireMessageDelivered(message, to);
|
fireMessageDelivered(message, to);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|
if(errorEvent.getErrorCode() == FacebookErrorException.kError_Async_NotLoggedIn
|
||||||
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
|
|| errorEvent.getErrorCode() == FacebookErrorException.kError_Async_LoginChanged)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
|
parentProvider.unregister(RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS);
|
||||||
}
|
}
|
||||||
catch (OperationFailedException e1)
|
catch (OperationFailedException e1)
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
"Unable to unregister the protocol provider: "
|
"Unable to unregister the protocol provider: "
|
||||||
+ this
|
+ this
|
||||||
+ " due to the following exception: " + e1);
|
+ " due to the following exception: " + e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
logger.warn(e.getMessage());
|
logger.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
// if we get here, we have failed to deliver this message,
|
// if we get here, we have failed to deliver this message,
|
||||||
// twice.
|
// twice.
|
||||||
fireMessageDeliveryFailed(
|
fireMessageDeliveryFailed(
|
||||||
message,
|
message,
|
||||||
to,
|
to,
|
||||||
MessageDeliveryFailedEvent.UNKNOWN_ERROR);
|
MessageDeliveryFailedEvent.UNKNOWN_ERROR);
|
||||||
// now do message delivery.----what's this?
|
// now do message delivery.----what's this?
|
||||||
// in case that the "to" we deliver this message to is
|
// in case that the "to" we deliver this message to is
|
||||||
// ourselves?
|
// ourselves?
|
||||||
// deliverMessageToMyself(message, (ContactFacebookImpl)to);
|
// deliverMessageToMyself(message, (ContactFacebookImpl)to);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sender.start();
|
sender.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked by the facebook adapter when we got messages from the server.
|
* Invoked by the facebook adapter when we got messages from the server.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param fbmsg the received Facebook instant message
|
||||||
* @param from
|
*/
|
||||||
*/
|
public void receivedInstantMessage(FacebookMessage fbmsg)
|
||||||
public void receivedInstantMessage(FacebookMessage fbmsg)
|
{
|
||||||
{
|
Message message = this.createMessage(fbmsg.getText());
|
||||||
Message message = this.createMessage(fbmsg.getText());
|
String fromID = fbmsg.getFrom();
|
||||||
String fromID = fbmsg.getFrom();
|
|
||||||
|
// TODO handle the msgID.
|
||||||
// TODO handle the msgID.
|
// it's generated when we createMessage() by now.
|
||||||
// it's generated when we createMessage() by now.
|
// We should set the message id according to the fbmsg.msgID.
|
||||||
// We should set the message id according to the fbmsg.msgID.
|
// But it's not important.
|
||||||
// But it's not important.
|
|
||||||
|
Contact fromContact = opSetPersPresence.findContactByID(fromID);
|
||||||
Contact fromContact = opSetPersPresence.findContactByID(fromID);
|
if (fromContact == null)
|
||||||
if (fromContact == null)
|
{
|
||||||
{
|
// from facebook user who are not on our contact list
|
||||||
// from facebook user who are not on our contact list
|
// TODO creat volatile contact, fire event.
|
||||||
// TODO creat volatile contact, fire event.
|
fromContact = opSetPersPresence.createVolatileContact(fromID);
|
||||||
fromContact = opSetPersPresence.createVolatileContact(fromID);
|
// opSetPersPresence.subscribe(fromID);
|
||||||
// opSetPersPresence.subscribe(fromID);
|
}
|
||||||
}
|
fireMessageReceived(message, fromContact);
|
||||||
fireMessageReceived(message, fromContact);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Notifies all registered message listeners that a message has been
|
||||||
* Notifies all registered message listeners that a message has been
|
* delivered successfully to its addressee..
|
||||||
* delivered successfully to its addressee..
|
*
|
||||||
*
|
* @param message
|
||||||
* @param message
|
* the <tt>Message</tt> that has been delivered.
|
||||||
* the <tt>Message</tt> that has been delivered.
|
* @param to
|
||||||
* @param to
|
* the <tt>Contact</tt> that <tt>message</tt> was delivered to.
|
||||||
* the <tt>Contact</tt> that <tt>message</tt> was delivered to.
|
*/
|
||||||
*/
|
protected void fireMessageDelivered(Message message, Contact to)
|
||||||
protected void fireMessageDelivered(Message message, Contact to)
|
{
|
||||||
{
|
// we succeeded in sending a message to contact "to",
|
||||||
// we succeeded in sending a message to contact "to",
|
// so we know he is online
|
||||||
// so we know he is online
|
// but -- if we support the "invisible" status,
|
||||||
// but -- if we support the "invisible" status,
|
// this line could be commented
|
||||||
// this line could be commented
|
opSetPersPresence
|
||||||
opSetPersPresence
|
.setPresenceStatusForContact(
|
||||||
.setPresenceStatusForContact(
|
(ContactFacebookImpl) to,
|
||||||
(ContactFacebookImpl) to,
|
FacebookStatusEnum.ONLINE);
|
||||||
FacebookStatusEnum.ONLINE);
|
|
||||||
|
super.fireMessageDelivered(message, to);
|
||||||
super.fireMessageDelivered(message, to);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Notifies all registered message listeners that a message has been
|
||||||
* Notifies all registered message listeners that a message has been
|
* received.
|
||||||
* received.
|
*
|
||||||
*
|
* @param message the <tt>Message</tt> that has been received.
|
||||||
* @param message the <tt>Message</tt> that has been received.
|
* @param from the <tt>Contact</tt> that <tt>message</tt> was received
|
||||||
* @param from the <tt>Contact</tt> that <tt>message</tt> was received
|
* from.
|
||||||
* from.
|
*/
|
||||||
*/
|
protected void fireMessageReceived(Message message, Contact from)
|
||||||
protected void fireMessageReceived(Message message, Contact from)
|
{
|
||||||
{
|
// we got a message from contact "from", so we know he is online
|
||||||
// we got a message from contact "from", so we know he is online
|
opSetPersPresence
|
||||||
opSetPersPresence
|
.setPresenceStatusForContact(
|
||||||
.setPresenceStatusForContact(
|
(ContactFacebookImpl) from,
|
||||||
(ContactFacebookImpl) from,
|
FacebookStatusEnum.ONLINE);
|
||||||
FacebookStatusEnum.ONLINE);
|
|
||||||
|
super.fireMessageReceived(message, from);
|
||||||
super.fireMessageReceived(message, from);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Determines whether the protocol provider (or the protocol itself) support
|
||||||
* Determines whether the protocol provider (or the protocol itself) support
|
* sending and receiving offline messages. Most often this method would
|
||||||
* sending and receiving offline messages. Most often this method would
|
* return true for protocols that support offline messages and false for
|
||||||
* return true for protocols that support offline messages and false for
|
* those that don't. It is however possible for a protocol to support these
|
||||||
* those that don't. It is however possible for a protocol to support these
|
* messages and yet have a particular account that does not (i.e. feature
|
||||||
* messages and yet have a particular account that does not (i.e. feature
|
* not enabled on the protocol server). In cases like this it is possible
|
||||||
* not enabled on the protocol server). In cases like this it is possible
|
* for this method to return true even when offline messaging is not
|
||||||
* for this method to return true even when offline messaging is not
|
* supported, and then have the sendMessage method throw an
|
||||||
* supported, and then have the sendMessage method throw an
|
* OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED.
|
||||||
* OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED.
|
*
|
||||||
*
|
* @return <tt>true</tt> if the protocol supports offline messages and
|
||||||
* @return <tt>true</tt> if the protocol supports offline messages and
|
* <tt>false</tt> otherwise.
|
||||||
* <tt>false</tt> otherwise.
|
*/
|
||||||
*/
|
public boolean isOfflineMessagingSupported()
|
||||||
public boolean isOfflineMessagingSupported()
|
{
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Determines wheter the protocol supports the supplied content type
|
||||||
* Determines wheter the protocol supports the supplied content type
|
*
|
||||||
*
|
* @param contentType the type we want to check
|
||||||
* @param contentType the type we want to check
|
* @return <tt>true</tt> if the protocol supports it and <tt>false</tt>
|
||||||
* @return <tt>true</tt> if the protocol supports it and <tt>false</tt>
|
* otherwise.
|
||||||
* otherwise.
|
*/
|
||||||
*/
|
public boolean isContentTypeSupported(String contentType)
|
||||||
public boolean isContentTypeSupported(String contentType)
|
{
|
||||||
{
|
return contentType.equals(DEFAULT_MIME_TYPE);
|
||||||
return contentType.equals(DEFAULT_MIME_TYPE);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,194 +1,192 @@
|
|||||||
/*
|
/*
|
||||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||||
*
|
*
|
||||||
* Distributable under LGPL license.
|
* Distributable under LGPL license.
|
||||||
* See terms of license at gnu.org.
|
* See terms of license at gnu.org.
|
||||||
*/
|
*/
|
||||||
package net.java.sip.communicator.plugin.autoaway;
|
package net.java.sip.communicator.plugin.autoaway;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.java.sip.communicator.service.configuration.*;
|
import net.java.sip.communicator.service.configuration.*;
|
||||||
import net.java.sip.communicator.service.protocol.*;
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Runnable, which permanently looks at the mouse position. If the mouse is
|
* A Runnable, which permanently looks at the mouse position. If the mouse is
|
||||||
* not moved, all accounts are set to "Away" or similar states.
|
* not moved, all accounts are set to "Away" or similar states.
|
||||||
*
|
*
|
||||||
* @author Thomas Hofer
|
* @author Thomas Hofer
|
||||||
*/
|
*/
|
||||||
public class StatusUpdateThread
|
public class StatusUpdateThread
|
||||||
implements Runnable
|
implements Runnable
|
||||||
{
|
{
|
||||||
private boolean run = false;
|
private boolean run = false;
|
||||||
private Point lastPosition = null;
|
private Point lastPosition = null;
|
||||||
private final Map<ProtocolProviderService, PresenceStatus> lastStates
|
private final Map<ProtocolProviderService, PresenceStatus> lastStates
|
||||||
= new HashMap<ProtocolProviderService, PresenceStatus>();
|
= new HashMap<ProtocolProviderService, PresenceStatus>();
|
||||||
|
|
||||||
private static final int IDLE_TIMER = 3000;
|
private static final int IDLE_TIMER = 3000;
|
||||||
private static final int AWAY_DEFAULT_STATUS = 40;
|
private static final int AWAY_DEFAULT_STATUS = 40;
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
run = true;
|
run = true;
|
||||||
int timer = 0;
|
int timer = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (MouseInfo.getPointerInfo() != null)
|
if (MouseInfo.getPointerInfo() != null)
|
||||||
{
|
{
|
||||||
PointerInfo info = MouseInfo.getPointerInfo();
|
PointerInfo info = MouseInfo.getPointerInfo();
|
||||||
Point currentPosition
|
Point currentPosition
|
||||||
= (info != null) ? info.getLocation() : new Point(0, 0);
|
= (info != null) ? info.getLocation() : new Point(0, 0);
|
||||||
|
|
||||||
if (!isNear(lastPosition, currentPosition))
|
if (!isNear(lastPosition, currentPosition))
|
||||||
{
|
{
|
||||||
// position has changed
|
// position has changed
|
||||||
// check, if a minor state has been automatically set
|
// check, if a minor state has been automatically set
|
||||||
// and
|
// and
|
||||||
// reset this state to the former state.
|
// reset this state to the former state.
|
||||||
for (ProtocolProviderService protocolProviderService
|
for (ProtocolProviderService protocolProviderService
|
||||||
: AutoAwayActivator.getProtocolProviders())
|
: AutoAwayActivator.getProtocolProviders())
|
||||||
{
|
{
|
||||||
if (lastStates.get(protocolProviderService) != null)
|
if (lastStates.get(protocolProviderService) != null)
|
||||||
{
|
{
|
||||||
PresenceStatus lastState
|
PresenceStatus lastState
|
||||||
= lastStates.get(protocolProviderService);
|
= lastStates.get(protocolProviderService);
|
||||||
OperationSetPresence presence
|
OperationSetPresence presence
|
||||||
= (OperationSetPresence)
|
= protocolProviderService
|
||||||
protocolProviderService
|
.getOperationSet(
|
||||||
.getOperationSet(
|
OperationSetPresence.class);
|
||||||
OperationSetPresence.class);
|
try
|
||||||
try
|
{
|
||||||
{
|
presence
|
||||||
presence
|
.publishPresenceStatus(lastState, "");
|
||||||
.publishPresenceStatus(lastState, "");
|
} catch (IllegalArgumentException e)
|
||||||
} catch (IllegalArgumentException e)
|
{
|
||||||
{
|
} catch (IllegalStateException e)
|
||||||
} catch (IllegalStateException e)
|
{
|
||||||
{
|
} catch (OperationFailedException e)
|
||||||
} catch (OperationFailedException e)
|
{
|
||||||
{
|
}
|
||||||
}
|
lastStates.remove(protocolProviderService);
|
||||||
lastStates.remove(protocolProviderService);
|
}
|
||||||
}
|
}
|
||||||
}
|
timer = getTimer() * 1000 * 60;
|
||||||
timer = getTimer() * 1000 * 60;
|
} else
|
||||||
} else
|
{
|
||||||
{
|
// position has not changed!
|
||||||
// position has not changed!
|
// get all protocols and set them to away
|
||||||
// get all protocols and set them to away
|
for (ProtocolProviderService protocolProviderService
|
||||||
for (ProtocolProviderService protocolProviderService
|
: AutoAwayActivator.getProtocolProviders())
|
||||||
: AutoAwayActivator.getProtocolProviders())
|
{
|
||||||
{
|
OperationSetPresence presence
|
||||||
OperationSetPresence presence
|
= protocolProviderService
|
||||||
= (OperationSetPresence)
|
.getOperationSet(
|
||||||
protocolProviderService
|
OperationSetPresence.class);
|
||||||
.getOperationSet(
|
|
||||||
OperationSetPresence.class);
|
PresenceStatus status = presence
|
||||||
|
.getPresenceStatus();
|
||||||
PresenceStatus status = presence
|
|
||||||
.getPresenceStatus();
|
if (status.getStatus()
|
||||||
|
< PresenceStatus.AVAILABLE_THRESHOLD)
|
||||||
if (status.getStatus()
|
{
|
||||||
< PresenceStatus.AVAILABLE_THRESHOLD)
|
// already (manually) set to away or lower
|
||||||
{
|
continue;
|
||||||
// already (manually) set to away or lower
|
}
|
||||||
continue;
|
|
||||||
}
|
lastStates.put(protocolProviderService, status);
|
||||||
|
|
||||||
lastStates.put(protocolProviderService, status);
|
PresenceStatus newStatus = findAwayStatus(presence);
|
||||||
|
|
||||||
PresenceStatus newStatus = findAwayStatus(presence);
|
try
|
||||||
|
{
|
||||||
try
|
if (newStatus != null)
|
||||||
{
|
presence
|
||||||
if (newStatus != null)
|
.publishPresenceStatus(
|
||||||
presence
|
newStatus,
|
||||||
.publishPresenceStatus(
|
newStatus.getStatusName());
|
||||||
newStatus,
|
} catch (IllegalArgumentException e)
|
||||||
newStatus.getStatusName());
|
{
|
||||||
} catch (IllegalArgumentException e)
|
} catch (IllegalStateException e)
|
||||||
{
|
{
|
||||||
} catch (IllegalStateException e)
|
} catch (OperationFailedException e)
|
||||||
{
|
{
|
||||||
} catch (OperationFailedException e)
|
}
|
||||||
{
|
}
|
||||||
}
|
|
||||||
}
|
timer = IDLE_TIMER;
|
||||||
|
}
|
||||||
timer = IDLE_TIMER;
|
lastPosition = currentPosition;
|
||||||
}
|
}
|
||||||
lastPosition = currentPosition;
|
Thread.sleep(timer);
|
||||||
}
|
} catch (InterruptedException e)
|
||||||
Thread.sleep(timer);
|
{
|
||||||
} catch (InterruptedException e)
|
}
|
||||||
{
|
} while (run && timer > 0);
|
||||||
}
|
}
|
||||||
} while (run && timer > 0);
|
|
||||||
}
|
public void stop()
|
||||||
|
{
|
||||||
public void stop()
|
run = false;
|
||||||
{
|
}
|
||||||
run = false;
|
|
||||||
}
|
/**
|
||||||
|
* Finds the Away-Status of the protocols
|
||||||
/**
|
*
|
||||||
* Finds the Away-Status of the protocols
|
* @param presence
|
||||||
*
|
* @return
|
||||||
* @param presence
|
*/
|
||||||
* @return
|
private PresenceStatus findAwayStatus(OperationSetPresence presence)
|
||||||
*/
|
{
|
||||||
private PresenceStatus findAwayStatus(OperationSetPresence presence)
|
Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();
|
||||||
{
|
PresenceStatus status = null;
|
||||||
Iterator<PresenceStatus> statusSet = presence.getSupportedStatusSet();
|
|
||||||
PresenceStatus status = null;
|
while (statusSet.hasNext())
|
||||||
|
{
|
||||||
while (statusSet.hasNext())
|
PresenceStatus possibleState = statusSet.next();
|
||||||
{
|
int possibleStatus = possibleState.getStatus();
|
||||||
PresenceStatus possibleState = statusSet.next();
|
|
||||||
int possibleStatus = possibleState.getStatus();
|
if ((possibleStatus < PresenceStatus.AVAILABLE_THRESHOLD)
|
||||||
|
&& (possibleStatus >= PresenceStatus.ONLINE_THRESHOLD))
|
||||||
if ((possibleStatus < PresenceStatus.AVAILABLE_THRESHOLD)
|
{
|
||||||
&& (possibleStatus >= PresenceStatus.ONLINE_THRESHOLD))
|
if (status == null
|
||||||
{
|
|| (Math.abs(possibleStatus - AWAY_DEFAULT_STATUS)
|
||||||
if (status == null
|
< Math.abs(
|
||||||
|| (Math.abs(possibleStatus - AWAY_DEFAULT_STATUS)
|
status.getStatus()
|
||||||
< Math.abs(
|
- AWAY_DEFAULT_STATUS)))
|
||||||
status.getStatus()
|
{
|
||||||
- AWAY_DEFAULT_STATUS)))
|
status = possibleState;
|
||||||
{
|
}
|
||||||
status = possibleState;
|
}
|
||||||
}
|
}
|
||||||
}
|
return status;
|
||||||
}
|
}
|
||||||
return status;
|
|
||||||
}
|
private int getTimer()
|
||||||
|
{
|
||||||
private int getTimer()
|
ConfigurationService configService
|
||||||
{
|
= AutoAwayActivator.getConfigService();
|
||||||
ConfigurationService configService
|
|
||||||
= AutoAwayActivator.getConfigService();
|
return
|
||||||
|
configService.getBoolean(Preferences.ENABLE, false)
|
||||||
return
|
? configService.getInt(Preferences.TIMER, 0)
|
||||||
configService.getBoolean(Preferences.ENABLE, false)
|
: 0;
|
||||||
? configService.getInt(Preferences.TIMER, 0)
|
}
|
||||||
: 0;
|
|
||||||
}
|
public boolean isRunning()
|
||||||
|
{
|
||||||
public boolean isRunning()
|
return run;
|
||||||
{
|
}
|
||||||
return run;
|
|
||||||
}
|
private boolean isNear(Point p1, Point p2)
|
||||||
|
{
|
||||||
private boolean isNear(Point p1, Point p2)
|
return
|
||||||
{
|
(p1 != null)
|
||||||
return
|
&& (p2 != null)
|
||||||
(p1 != null)
|
&& (Math.abs(p1.x - p2.x) <= 10)
|
||||||
&& (p2 != null)
|
&& (Math.abs(p1.y - p2.y) <= 10);
|
||||||
&& (Math.abs(p1.x - p2.x) <= 10)
|
}
|
||||||
&& (Math.abs(p1.y - p2.y) <= 10);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue