mirror of https://github.com/sipwise/jitsi.git
				
				
				
			
							parent
							
								
									1622cf7598
								
							
						
					
					
						commit
						b9ba0d4ad0
					
				| @ -0,0 +1,195 @@ | ||||
| package net.java.sip.communicator.impl.protocol.irc; | ||||
| 
 | ||||
| import java.util.*; | ||||
| 
 | ||||
| import net.java.sip.communicator.service.protocol.*; | ||||
| 
 | ||||
| public class ContactGroupIrcImpl | ||||
|     implements ContactGroup | ||||
| { | ||||
|     /** | ||||
|      * The protocol provider service instance. | ||||
|      */ | ||||
|     private final ProtocolProviderServiceIrcImpl provider; | ||||
|      | ||||
|     /** | ||||
|      * Group name. | ||||
|      */ | ||||
|     private final String name; | ||||
|      | ||||
|     /** | ||||
|      * Subgroups | ||||
|      */ | ||||
|     private final List<ContactGroupIrcImpl> subgroups = new ArrayList<ContactGroupIrcImpl>(); | ||||
|      | ||||
|     /** | ||||
|      * Contacts in this group. | ||||
|      */ | ||||
|     private final List<ContactIrcImpl> contacts = new ArrayList<ContactIrcImpl>(); | ||||
| 
 | ||||
|     /** | ||||
|      * Parent contact group. | ||||
|      */ | ||||
|     private ContactGroup parent; | ||||
|      | ||||
|     /** | ||||
|      * Contact Group IRC implementation. | ||||
|      *  | ||||
|      * @param provider IRC protocol provider service instance. | ||||
|      */ | ||||
|     public ContactGroupIrcImpl(ProtocolProviderServiceIrcImpl provider) | ||||
|     { | ||||
|         this(provider, null, "root"); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Contact Group IRC implementation. | ||||
|      *  | ||||
|      * @param provider IRC protocol provider service instance. | ||||
|      * @param name Group name | ||||
|      */ | ||||
|     public ContactGroupIrcImpl(ProtocolProviderServiceIrcImpl provider, | ||||
|         ContactGroupIrcImpl parentGroup, String name) | ||||
|     { | ||||
|         if (provider == null) | ||||
|             throw new IllegalArgumentException("provider cannot be null"); | ||||
|         this.provider = provider; | ||||
|         this.parent = parentGroup; | ||||
|         if (name == null) | ||||
|             throw new IllegalArgumentException("name cannot be null"); | ||||
|         this.name = name; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Iterator<ContactGroup> subgroups() | ||||
|     { | ||||
|         return new ArrayList<ContactGroup>(this.subgroups).iterator(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int countSubgroups() | ||||
|     { | ||||
|         return this.subgroups.size(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup getGroup(int index) | ||||
|     { | ||||
|         return this.subgroups.get(index); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup getGroup(String groupName) | ||||
|     { | ||||
|         if (groupName == null) | ||||
|             return null; | ||||
|         for (ContactGroupIrcImpl group : this.subgroups) | ||||
|         { | ||||
|             if (groupName.equals(group.getGroupName())) | ||||
|             { | ||||
|                 return group; | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Iterator<Contact> contacts() | ||||
|     { | ||||
|         return new ArrayList<Contact>(this.contacts).iterator(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int countContacts() | ||||
|     { | ||||
|         return this.contacts.size(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Contact getContact(String id) | ||||
|     { | ||||
|         if (id == null) | ||||
|             return null; | ||||
|         for (ContactIrcImpl contact : this.contacts) | ||||
|         { | ||||
|             if (id.equals(contact.getAddress())) | ||||
|             { | ||||
|                 return contact; | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean canContainSubgroups() | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getGroupName() | ||||
|     { | ||||
|         return this.name; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ProtocolProviderServiceIrcImpl getProtocolProvider() | ||||
|     { | ||||
|         return this.provider; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup getParentContactGroup() | ||||
|     { | ||||
|         return this.parent; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean isPersistent() | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getUID() | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean isResolved() | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getPersistentData() | ||||
|     { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Add contact to the group. | ||||
|      *  | ||||
|      * @param contact Contact to be added. | ||||
|      */ | ||||
|     public void addContact(ContactIrcImpl contact) | ||||
|     { | ||||
|         if (contact == null) | ||||
|             throw new IllegalArgumentException("contact cannot be null"); | ||||
|         this.contacts.add(contact); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Add group as subgroup to this group. | ||||
|      *  | ||||
|      * @param group the group | ||||
|      */ | ||||
|     public void addSubGroup(ContactGroupIrcImpl group) | ||||
|     { | ||||
|         if (group == null) | ||||
|             throw new IllegalArgumentException("group cannot be null"); | ||||
|         this.subgroups.add(group); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,83 @@ | ||||
| package net.java.sip.communicator.impl.protocol.irc; | ||||
| 
 | ||||
| import net.java.sip.communicator.service.protocol.*; | ||||
| 
 | ||||
| public class ContactIrcImpl | ||||
|     extends AbstractContact | ||||
| { | ||||
|     private ProtocolProviderServiceIrcImpl provider; | ||||
|      | ||||
|     private String id; | ||||
| 
 | ||||
|     public ContactIrcImpl(ProtocolProviderServiceIrcImpl provider, String id) | ||||
|     { | ||||
|         if (provider == null) | ||||
|             throw new IllegalArgumentException("provider cannot be null"); | ||||
|         this.provider = provider; | ||||
|         if (id == null) | ||||
|             throw new IllegalArgumentException("id cannot be null"); | ||||
|         this.id = id; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getAddress() | ||||
|     { | ||||
|         return this.id; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getDisplayName() | ||||
|     { | ||||
|         return this.id; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public byte[] getImage() | ||||
|     { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public PresenceStatus getPresenceStatus() | ||||
|     { | ||||
|         return IrcStatusEnum.ONLINE; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup getParentContactGroup() | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ProtocolProviderService getProtocolProvider() | ||||
|     { | ||||
|         return this.provider; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean isPersistent() | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean isResolved() | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getPersistentData() | ||||
|     { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getStatusMessage() | ||||
|     { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,142 @@ | ||||
| package net.java.sip.communicator.impl.protocol.irc; | ||||
| 
 | ||||
| import net.java.sip.communicator.service.protocol.*; | ||||
| 
 | ||||
| public class OperationSetBasicInstantMessagingIrcImpl | ||||
|     extends AbstractOperationSetBasicInstantMessaging | ||||
| { | ||||
|     /** | ||||
|      * IRC protocol provider service. | ||||
|      */ | ||||
|     private final ProtocolProviderServiceIrcImpl provider; | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor. | ||||
|      *  | ||||
|      * @param provider IRC provider service. | ||||
|      */ | ||||
|     public OperationSetBasicInstantMessagingIrcImpl( | ||||
|         ProtocolProviderServiceIrcImpl provider) | ||||
|     { | ||||
|         if (provider == null) | ||||
|             throw new IllegalArgumentException("provider cannot be null"); | ||||
|         this.provider = provider; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Create a new message. | ||||
|      *  | ||||
|      * {@inheritDoc} | ||||
|      *  | ||||
|      * @param content Message content | ||||
|      * @param contentType Message content type | ||||
|      * @param contentEncoding message encoding | ||||
|      * @param subject Message subject | ||||
|      */ | ||||
|     @Override | ||||
|     public Message createMessage(String content, String contentType, | ||||
|         String contentEncoding, String subject) | ||||
|     { | ||||
|         return new IrcMessage(content, contentType, contentEncoding, subject); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Send instant message. | ||||
|      *  | ||||
|      * @param to contact to send message to | ||||
|      * @param message message to send | ||||
|      * @throws IllegalStateException in case of bad internal state | ||||
|      * @throws IllegalArgumentException in case invalid arguments have been | ||||
|      *             passed | ||||
|      */ | ||||
|     @Override | ||||
|     public void sendInstantMessage(Contact to, Message message) | ||||
|         throws IllegalStateException, | ||||
|         IllegalArgumentException | ||||
|     { | ||||
|         this.provider.getIrcStack().message(to, message.getContent()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if offline messaging is supported. | ||||
|      *  | ||||
|      * @return returns true if offline messaging is supported or false | ||||
|      *         otherwise. | ||||
|      */ | ||||
|     @Override | ||||
|     public boolean isOfflineMessagingSupported() | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Test content type support. | ||||
|      *  | ||||
|      * {@inheritDoc} | ||||
|      *  | ||||
|      * @param contentType contentType to test | ||||
|      * @return returns true if content type is supported | ||||
|      */ | ||||
|     @Override | ||||
|     public boolean isContentTypeSupported(String contentType) | ||||
|     { | ||||
|         return OperationSetBasicInstantMessaging.HTML_MIME_TYPE | ||||
|             .equalsIgnoreCase(contentType); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritDoc} | ||||
|      *  | ||||
|      * @param message the received message | ||||
|      * @param contactId the sender | ||||
|      */ | ||||
|     @Override | ||||
|     protected void fireMessageReceived(Message message, Contact from) | ||||
|     { | ||||
|         super.fireMessageReceived(message, from); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Implementation of an IRC basic instant message. | ||||
|      *  | ||||
|      * @author danny | ||||
|      */ | ||||
|     static class IrcMessage | ||||
|         extends AbstractMessage | ||||
|     { | ||||
|         /** | ||||
|          * Constructor. | ||||
|          *  | ||||
|          * @param message instant message | ||||
|          * @param contentType Message content type | ||||
|          * @param contentEncoding Message content encoding | ||||
|          * @param subject Message subject | ||||
|          */ | ||||
|         IrcMessage(String message, String contentType, | ||||
|             String contentEncoding, String subject) | ||||
|         { | ||||
|             super(message, contentType, contentEncoding, subject); | ||||
|         } | ||||
| 
 | ||||
|         /** | ||||
|          * Constructor for simple messages. | ||||
|          *  | ||||
|          * @param message instant message | ||||
|          */ | ||||
|         IrcMessage(String message) { | ||||
|             this(message, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, | ||||
|                 OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, ""); | ||||
|         } | ||||
| 
 | ||||
|         /** | ||||
|          * Constructor. | ||||
|          *  | ||||
|          * @param message instant message | ||||
|          */ | ||||
|         private IrcMessage(String message, String contentType, | ||||
|             String contentEncoding, String subject, String UUID) | ||||
|         { | ||||
|             super(message, contentType, contentEncoding, subject, UUID); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,264 @@ | ||||
| /* | ||||
|  * Jitsi, the OpenSource Java VoIP and Instant Messaging client. | ||||
|  * | ||||
|  * Distributable under LGPL license. | ||||
|  * See terms of license at gnu.org. | ||||
|  */ | ||||
| package net.java.sip.communicator.impl.protocol.irc; | ||||
| 
 | ||||
| import java.util.*; | ||||
| 
 | ||||
| import net.java.sip.communicator.service.protocol.*; | ||||
| import net.java.sip.communicator.service.protocol.event.*; | ||||
| import net.java.sip.communicator.util.*; | ||||
| 
 | ||||
| /** | ||||
|  * Implementation of support for Persistent Presence for IRC. | ||||
|  *  | ||||
|  * @author Danny van Heumen | ||||
|  */ | ||||
| public class OperationSetPersistentPresenceIrcImpl extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceIrcImpl> | ||||
| { | ||||
|     /** | ||||
|      * Logger. | ||||
|      */ | ||||
|     private final Logger LOGGER = Logger | ||||
|         .getLogger(OperationSetPersistentPresenceIrcImpl.class); | ||||
| 
 | ||||
|     /** | ||||
|      * Root contact group for IRC contacts. | ||||
|      */ | ||||
|     private final ContactGroupIrcImpl rootGroup = new ContactGroupIrcImpl(this.parentProvider); | ||||
| 
 | ||||
|     /** | ||||
|      * IRC implementation for OperationSetPersistentPresence. | ||||
|      *  | ||||
|      * @param parentProvider IRC instance of protocol provider service. | ||||
|      */ | ||||
|     protected OperationSetPersistentPresenceIrcImpl( | ||||
|         ProtocolProviderServiceIrcImpl parentProvider) | ||||
|     { | ||||
|         super(parentProvider); | ||||
|     } | ||||
|      | ||||
|     ContactIrcImpl createVolatileContact(String id) | ||||
|     { | ||||
|         ContactIrcImpl newVolatileContact = | ||||
|             new ContactIrcImpl(this.parentProvider, id); | ||||
| 
 | ||||
|         // Check whether a volatile group already exists and if not create
 | ||||
|         // one
 | ||||
|         ContactGroupIrcImpl volatileGroup = getNonPersistentGroup(); | ||||
| 
 | ||||
|         // if the parent group is null then add necessary create the group
 | ||||
|         if (volatileGroup == null) | ||||
|         { | ||||
|             volatileGroup = | ||||
|                 new ContactGroupIrcImpl(this.parentProvider, this.rootGroup, | ||||
|                     IrcActivator.getResources().getI18NString( | ||||
|                         "service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME")); | ||||
| 
 | ||||
|             this.rootGroup.addSubGroup(volatileGroup); | ||||
|              | ||||
|             this.fireServerStoredGroupEvent(volatileGroup, | ||||
|                 ServerStoredGroupEvent.GROUP_CREATED_EVENT); | ||||
|         } | ||||
|         volatileGroup.addContact(newVolatileContact); | ||||
| 
 | ||||
|         this.fireSubscriptionEvent(newVolatileContact, volatileGroup, | ||||
|             SubscriptionEvent.SUBSCRIPTION_CREATED); | ||||
| 
 | ||||
|         return newVolatileContact; | ||||
|     } | ||||
| 
 | ||||
|     ContactGroupIrcImpl getNonPersistentGroup() | ||||
|     { | ||||
|         String groupName | ||||
|             = IrcActivator.getResources().getI18NString( | ||||
|                 "service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME"); | ||||
| 
 | ||||
|         for (int i = 0; i < getRootGroup().countSubgroups(); i++) | ||||
|         { | ||||
|             ContactGroupIrcImpl gr = | ||||
|                 (ContactGroupIrcImpl)getRootGroup().getGroup(i); | ||||
| 
 | ||||
|             if(!gr.isPersistent() && gr.getGroupName().equals(groupName)) | ||||
|                 return gr; | ||||
|         } | ||||
| 
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     public ContactGroup getRootGroup() | ||||
|     { | ||||
|         return rootGroup; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void subscribe(String contactIdentifier) | ||||
|         throws IllegalArgumentException, | ||||
|         IllegalStateException, | ||||
|         OperationFailedException | ||||
|     { | ||||
|         System.out.println("subscribe(\"" + contactIdentifier + "\") called"); | ||||
|         // TODO Auto-generated method stub
 | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void subscribe(ContactGroup parent, String contactIdentifier) | ||||
|         throws IllegalArgumentException, | ||||
|         IllegalStateException, | ||||
|         OperationFailedException | ||||
|     { | ||||
|         System.out.println("subscribe(\"" + parent.getGroupName() + "\", \"" | ||||
|             + contactIdentifier + "\") called"); | ||||
|         // TODO Auto-generated method stub
 | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void unsubscribe(Contact contact) | ||||
|         throws IllegalArgumentException, | ||||
|         IllegalStateException, | ||||
|         OperationFailedException | ||||
|     { | ||||
|         System.out.println("unsubscribe(\"" + contact.getAddress() | ||||
|             + "\") called"); | ||||
|         // TODO Auto-generated method stub
 | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void createServerStoredContactGroup(ContactGroup parent, | ||||
|         String groupName) throws OperationFailedException | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void removeServerStoredContactGroup(ContactGroup group) | ||||
|         throws OperationFailedException | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void renameServerStoredContactGroup(ContactGroup group, | ||||
|         String newName) | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void moveContactToGroup(Contact contactToMove, ContactGroup newParent) | ||||
|         throws OperationFailedException | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup getServerStoredContactListRoot() | ||||
|     { | ||||
|         return this.rootGroup; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Contact createUnresolvedContact(String address, | ||||
|         String persistentData, ContactGroup parentGroup) | ||||
|     { | ||||
|         LOGGER.warn("Unresolved contact: " + address + " " + persistentData | ||||
|             + " group: " + parentGroup.getGroupName()); | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ContactGroup createUnresolvedContactGroup(String groupUID, | ||||
|         String persistentData, ContactGroup parentGroup) | ||||
|     { | ||||
|         LOGGER.warn("Unresolved contactgroup: " + groupUID + " " | ||||
|             + persistentData + " parent: " + parentGroup.getGroupName()); | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public PresenceStatus getPresenceStatus() | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void publishPresenceStatus(PresenceStatus status, | ||||
|         String statusMessage) | ||||
|         throws IllegalArgumentException, | ||||
|         IllegalStateException, | ||||
|         OperationFailedException | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Iterator<PresenceStatus> getSupportedStatusSet() | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public PresenceStatus queryContactStatus(String contactIdentifier) | ||||
|         throws IllegalArgumentException, | ||||
|         IllegalStateException, | ||||
|         OperationFailedException | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Contact findContactByID(String contactID) | ||||
|     { | ||||
|         // FIXME DEBUG
 | ||||
|         LOGGER.warn("findContactByID(\"" + contactID + "\") called"); | ||||
|         if (contactID == null) | ||||
|             return null; | ||||
|         Contact contact = this.rootGroup.getContact(contactID); | ||||
|         if (contact != null) | ||||
|             return contact; | ||||
|         Iterator<ContactGroup> groups = this.rootGroup.subgroups(); | ||||
|         while (groups.hasNext()) | ||||
|         { | ||||
|             ContactGroup group = groups.next(); | ||||
|             contact = group.getContact(contactID); | ||||
|             if (contact != null) | ||||
|                 return contact; | ||||
|         } | ||||
|         // FIXME currently just creates a new volatile contact
 | ||||
|         return createVolatileContact(contactID); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void setAuthorizationHandler(AuthorizationHandler handler) | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getCurrentStatusMessage() | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Contact createUnresolvedContact(String address, String persistentData) | ||||
|     { | ||||
|         // TODO Auto-generated method stub
 | ||||
|         return null; | ||||
|     }     | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue