Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Added types of message in messageListeners #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*.class
hs_err_pid*
*.jar
*.war
*.ear

# maven files

Expand All @@ -13,6 +15,7 @@ pom.xml.versionsBackup
pom.xml.next
release.properties
repo/.locks
dependency-reduced-pom.xml

# eclipse files

Expand All @@ -30,3 +33,30 @@ local.properties
*.launch
.classpath
.target

# NetBeans
nbproject/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

# IntelliJ IDEA
*.iml
*.ipr
*.iws
.idea/

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Linux
.*
!.gitattributes
!.gitignore
*~
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.delthas</groupId>
<artifactId>javaskype</artifactId>
<version>1.0.14</version>
<version>1.0.14.5-SNAPSHOT</version>

<name>JavaSkype</name>
<url>https://github.com/delthas/javaskype</url>
Expand Down Expand Up @@ -69,6 +69,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/fr/delthas/skype/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fr.delthas.skype;

import fr.delthas.skype.message.Message;

/**
* Interface for chats
*/
public interface Chat {

/**
* Get Skype client
*
* @return skype object
*/
Skype getSkype();

/**
* Get identity of a chat
*
* @return string
*/
String getIdentity();

/**
* Type of chat
*
* @return ChatType enum item
*/
ChatType getType();

/**
* Send message to chat
*
* @param message object of one of messages types
*/
void sendMessage(Message message);

/**
* Edit message to chat.
*
* Work only with text message.
*
* @param message object of one of messages types
*/
void editMessage(Message message);

/**
* Remove message to chat
*
* @param message object of one of messages types
*/
void removeMessage(Message message);

/**
* ChatType enum
*/
public enum ChatType {
GROUP,
USER
}
}
14 changes: 14 additions & 0 deletions src/main/java/fr/delthas/skype/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.delthas.skype;

/**
* Constants
*/
public class Constants {
public static String HEADER_TEXT = "Text";
public static String HEADER_RICH_TEXT = "RichText";
public static String HEADER_PICTURE = "RichText/UriObject";
public static String HEADER_FILE = "RichText/Media_GenericFile";
public static String HEADER_VIDEO = "RichText/Media_Video";
public static String HEADER_CONTACT = "RichText/Contacts";
public static String HEADER_MOJI = "RichText/Media_FlikMsg";
}
41 changes: 32 additions & 9 deletions src/main/java/fr/delthas/skype/Group.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.delthas.skype;

import fr.delthas.skype.message.Message;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand All @@ -10,9 +12,8 @@
* A conversation between some Skype users.
* <p>
* All information will be updated as updates are received (this object <b>is NOT</b> an immutable view/snapshot of a group).
*
*/
public class Group {
public class Group implements Chat {

private final Skype skype;
private final String id;
Expand All @@ -31,15 +32,28 @@ public class Group {
*
* @param message The message to send.
*/
@Deprecated
public void sendMessage(String message) {
skype.sendGroupMessage(this, message);
}

public void sendMessage(Message message) {
skype.doMessageAction(this, message, Skype.MessageAction.SEND);
}

public void editMessage(Message message) {
skype.doMessageAction(this, message, Skype.MessageAction.EDIT);
}

public void removeMessage(Message message) {
skype.doMessageAction(this, message, Skype.MessageAction.REMOVE);
}

/**
* The id of a group is a special String used by Skype to uniquely identify groups.
* <p>
* In case you know about network IDs and the like: if a group "adress" is "19:[email protected]", its id is "xxx".
*
* In case you know about network IDs and the like: if a group "address" is "19:[email protected]", its id is "19:xxx@thread.skype" or "19:[email protected]" .
*
* @return The id of the group.
*/
public String getId() {
Expand Down Expand Up @@ -89,7 +103,6 @@ void setUsers(List<Pair<User, Role>> users) {
*
* @param user The user to add to this group.
* @param role The role of the newly added user.
*
* @return true if the user wasn't in the group, and the Skype account has group admin rights if needed.
*/
public boolean addUser(User user, Role role) {
Expand All @@ -111,9 +124,7 @@ public boolean addUser(User user, Role role) {
* Removes a user from this group. Group admin rights are needed.
*
* @param user The user to remove from this group.
*
* @return true if the Skype account has admin rights, and the user was in the group.
*
* @see #isSelfAdmin()
*/
public boolean removeUser(User user) {
Expand All @@ -138,9 +149,7 @@ public boolean removeUser(User user) {
*
* @param user The user whose role is to be changed
* @param role The new role of the user.
*
* @return true if the Skype account has admin rights, and the user was in the group and didn't have this role already.
*
* @see #isSelfAdmin()
*/
public boolean changeUserRole(User user, Role role) {
Expand Down Expand Up @@ -213,4 +222,18 @@ public String toString() {
return "Group: " + getId();
}

@Override
public Skype getSkype() {
return skype;
}

@Override
public String getIdentity() {
return id;
}

@Override
public ChatType getType() {
return ChatType.GROUP;
}
}
45 changes: 39 additions & 6 deletions src/main/java/fr/delthas/skype/GroupMessageListener.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
package fr.delthas.skype;

import fr.delthas.skype.message.Message;

/**
* A listener for new messages sent to a Skype account.
*
*/
public interface GroupMessageListener {
public interface GroupMessageListener extends MessageListener {

/**
* Called when a message is sent from a user to a group the Skype account is in while it is connected.
*
* @param group The group in which the message has been sent.
* @param sender The sender of the message.
* @param message The message sent.
* @param group The group in which the message has been sent.
* @param sender The sender of the message.
* @param message The text of message sent.
*/
public void messageReceived(Group group, User sender, String message);
@Deprecated
default void messageReceived(Group group, User sender, String message) {
}

/**
* Called when a message is sent from a user to a group the Skype account is in while it is connected.
*
* @param group The group in which the message has been sent.
* @param sender The sender of the message.
* @param message The object of message sent.
*/
default void messageReceived(Group group, User sender, Message message) {
}

/**
* Called when a message is edited by a user in a group the Skype account is in while it is connected.
*
* @param group The group in which the message has been edit.
* @param sender The sender of the message.
* @param message The object of message sent.
*/
default void messageEdited(Group group, User sender, Message message) {
}

/**
* Called when a message is removed by a user in a group the Skype account is in while it is connected.
*
* @param group The group in which the message has been remove.
* @param sender The sender of the message.
* @param message The object of message sent.
*/
default void messageRemoved(Group group, User sender, Message message) {
}


}
12 changes: 12 additions & 0 deletions src/main/java/fr/delthas/skype/MessageListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.delthas.skype;

/**
* A root listener for new messages sent to a Skype account.
*/
public interface MessageListener {
enum MessageEvent {
RECEIVED,
EDITED,
REMOVED
}
}
Loading