Commit e192e9aa authored by Ryan Graham's avatar Ryan Graham Committed by ryang

* added support for a welcome message

* minor refactoring


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1272 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5a24a338
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
package org.jivesoftware.messenger.plugin; package org.jivesoftware.messenger.plugin;
import java.io.File;
import java.util.Map;
import org.jivesoftware.messenger.SessionManager; import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.XMPPServer; import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.container.Plugin; import org.jivesoftware.messenger.container.Plugin;
...@@ -18,32 +21,29 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -18,32 +21,29 @@ import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.io.File;
import java.util.Map;
public class RegistrationPlugin implements Plugin { public class RegistrationPlugin implements Plugin {
private PluginManager pluginManager; private PluginManager pluginManager;
private SessionManager sessionManager; private SessionManager sessionManager;
private RegistrationUserEventListener listener = new RegistrationUserEventListener(); private RegistrationUserEventListener listener = new RegistrationUserEventListener();
private static String serverName; private static String serverName;
private boolean serviceEnabled; private boolean registrationNotificationEnabled;
private boolean registrationWelcomeEnabled;
private String contact; private String contact;
public RegistrationPlugin() { public RegistrationPlugin() {
sessionManager = SessionManager.getInstance(); sessionManager = SessionManager.getInstance();
serverName = XMPPServer.getInstance().getServerInfo().getName(); serverName = XMPPServer.getInstance().getServerInfo().getName();
serviceEnabled = JiveGlobals.getBooleanProperty("registration.notification.enabled", true); registrationNotificationEnabled = JiveGlobals.getBooleanProperty("registration.notification.enabled", false);
setServiceEnabled(serviceEnabled); setRegistrationNotificationEnabled(registrationNotificationEnabled);
contact = JiveGlobals.getProperty("registration.notification.contact"); registrationWelcomeEnabled = JiveGlobals.getBooleanProperty("registration.welcome.enabled", false);
if (contact == null) { setRegistrationNotificationEnabled(registrationWelcomeEnabled);
contact = "admin";
JiveGlobals.setProperty("registration.notification.contact", contact); contact = JiveGlobals.getProperty("registration.notification.contact", "admin");
}
UserEventDispatcher.addListener(listener);
UserEventDispatcher.addListener(listener);
} }
public String getName() { public String getName() {
...@@ -61,7 +61,7 @@ public class RegistrationPlugin implements Plugin { ...@@ -61,7 +61,7 @@ public class RegistrationPlugin implements Plugin {
public String getVersion() { public String getVersion() {
return pluginManager.getVersion(this); return pluginManager.getVersion(this);
} }
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
} }
...@@ -70,44 +70,75 @@ public class RegistrationPlugin implements Plugin { ...@@ -70,44 +70,75 @@ public class RegistrationPlugin implements Plugin {
} }
public void destroyPlugin() { public void destroyPlugin() {
UserEventDispatcher.removeListener(listener); UserEventDispatcher.removeListener(listener);
pluginManager = null; pluginManager = null;
sessionManager = null; sessionManager = null;
} }
public void setServiceEnabled(boolean enable) { public void setRegistrationNotificationEnabled(boolean enable) {
serviceEnabled = enable; JiveGlobals.setProperty("registration.notification.enabled", enable ? "true" : "false");
JiveGlobals.setProperty("registration.notification.enabled", serviceEnabled ? "true" : "false");
} }
public boolean serviceEnabled() { public boolean registrationNotificationEnabled() {
return "true".equals(JiveGlobals.getProperty("registration.notification.enabled")); return JiveGlobals.getBooleanProperty("registration.notification.enabled", false);
} }
public void setContact(String contact) { public void setContact(String contact) {
this.contact = contact; this.contact = contact;
JiveGlobals.setProperty("registration.notification.contact", contact); JiveGlobals.setProperty("registration.notification.contact", contact);
} }
public String getContact() { public String getContact() {
return contact; return contact;
} }
public void setRegistrationWelcomeEnabled(boolean enable) {
JiveGlobals.setProperty("registration.welcome.enabled", enable ? "true" : "false");
}
public boolean registrationWelcomeEnabled() {
return JiveGlobals.getBooleanProperty("registration.welcome.enabled", false);
}
public void setWelcomeMessage(String message) {
JiveGlobals.setProperty("registration.welcome.message", message);
}
public String getWelcomeMessage() {
return JiveGlobals.getProperty("registration.welcome.message", "Welcome to Jive Messenger!");
}
private void sendRegistrationNotificatonMessage(User user) {
String msg = " A new user with the username of '" + user.getUsername() + "' just registered";
sessionManager.sendServerMessage(new JID(getContact() + "@" + serverName),
"Registration Notification",
msg);
}
private void sendWelcomeMessage(User user) {
sessionManager.sendServerMessage(new JID(user.getUsername() + "@" + serverName),
"Welcome",
getWelcomeMessage());
}
//TODO JM-170
//TODO add the ability for the admin to monitor when users are deleted?
private class RegistrationUserEventListener implements UserEventListener {
public void userCreated(User user, Map params) {
if (registrationNotificationEnabled) {
sendRegistrationNotificatonMessage(user);
}
if (registrationWelcomeEnabled) {
sendWelcomeMessage(user);
}
}
//TODO JM-170 public void userDeleting(User user, Map params) {
//TODO add the ability to have a admin configurable messange sent to newly registered user }
//TODO add the ability for the admin to monitor when users are created and/or deleted?
private class RegistrationUserEventListener implements UserEventListener {
public void userCreated(User user, Map params) {
String msg = " A new user with the username of '" + user.getUsername() + "' just registered";
sessionManager.sendServerMessage(new JID(getContact() + "@" + serverName),
"Registration Notification",
msg);
}
public void userDeleting(User user, Map params) {
}
public void userModified(User user, Map params) { public void userModified(User user, Map params) {
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment