[kune-commits] r1680 - in trunk/src/main/java/cc/kune: chat/client/actions core/client/rpcservices core/server/notifier core/server/rpc events/client/viewer

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Sat Feb 11 22:13:07 CET 2012


Author: vjrj_
Date: 2012-02-11 22:13:06 +0100 (Sat, 11 Feb 2012)
New Revision: 1680

Modified:
   trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddieHeaderButton.java
   trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddyAction.java
   trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkService.java
   trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkServiceAsync.java
   trunk/src/main/java/cc/kune/core/server/notifier/NotificationHtmlHelper.java
   trunk/src/main/java/cc/kune/core/server/notifier/NotificationService.java
   trunk/src/main/java/cc/kune/core/server/rpc/SocialNetworkRPC.java
   trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java
Log:
CLOSED - # 188: Add an email notification to "Add as buddie" action 
http://kune.ourproject.org/issues/ticket/188

Modified: trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddieHeaderButton.java
===================================================================
--- trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddieHeaderButton.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddieHeaderButton.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -33,6 +33,8 @@
 import cc.kune.core.client.events.StateChangedEvent.StateChangedHandler;
 import cc.kune.core.client.resources.CoreMessages;
 import cc.kune.core.client.resources.CoreResources;
+import cc.kune.core.client.rpcservices.AsyncCallbackSimple;
+import cc.kune.core.client.rpcservices.SocialNetworkServiceAsync;
 import cc.kune.core.client.state.Session;
 import cc.kune.core.client.state.StateManager;
 import cc.kune.core.client.ws.entheader.EntityHeader;
@@ -43,20 +45,24 @@
 import com.calclab.emite.im.client.roster.events.RosterRetrievedEvent;
 import com.calclab.emite.im.client.roster.events.RosterRetrievedHandler;
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 
 public class AddAsBuddieHeaderButton {
 
   public static class AddAsBuddieHeaderAction extends AbstractExtendedAction {
     private final ChatClient chatEngine;
     private final Session session;
+    private final Provider<SocialNetworkServiceAsync> snService;
 
     @Inject
     public AddAsBuddieHeaderAction(final ChatClient chatEngine, final Session session,
         final ChatInstances chatInstances, final StateManager stateManager,
-        final I18nTranslationService i18n, final CoreResources img) {
+        final I18nTranslationService i18n, final CoreResources img,
+        final Provider<SocialNetworkServiceAsync> snService) {
       super();
       this.chatEngine = chatEngine;
       this.session = session;
+      this.snService = snService;
       stateManager.onStateChanged(true, new StateChangedHandler() {
         @Override
         public void onStateChanged(final StateChangedEvent event) {
@@ -81,9 +87,14 @@
 
     @Override
     public void actionPerformed(final ActionEvent event) {
-      chatEngine.addNewBuddy(session.getCurrentState().getGroup().getShortName());
-      // NotifyUser.info("Added as buddy. Waiting buddy response");
+      final String username = session.getCurrentState().getGroup().getShortName();
+      chatEngine.addNewBuddy(username);
       setEnabled(false);
+      snService.get().addAsBuddie(session.getUserHash(), username, new AsyncCallbackSimple<Void>() {
+        @Override
+        public void onSuccess(final Void result) {
+        }
+      });
     }
 
     private boolean currentGroupsIsAsPerson(final StateAbstractDTO state) {

Modified: trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddyAction.java
===================================================================
--- trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddyAction.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/chat/client/actions/AddAsBuddyAction.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -27,20 +27,29 @@
 import cc.kune.common.shared.i18n.I18nTranslationService;
 import cc.kune.core.client.resources.CoreMessages;
 import cc.kune.core.client.resources.CoreResources;
+import cc.kune.core.client.rpcservices.AsyncCallbackSimple;
+import cc.kune.core.client.rpcservices.SocialNetworkServiceAsync;
+import cc.kune.core.client.state.Session;
 import cc.kune.core.client.state.StateManager;
 import cc.kune.core.shared.dto.GroupDTO;
 import cc.kune.core.shared.dto.UserSimpleDTO;
 
 import com.google.inject.Inject;
+import com.google.inject.Provider;
 
 public class AddAsBuddyAction extends AbstractExtendedAction {
   private final ChatClient chatEngine;
+  private final Session session;
+  private final Provider<SocialNetworkServiceAsync> snService;
 
   @Inject
   public AddAsBuddyAction(final ChatClient chatEngine, final ChatInstances chatInstances,
-      final StateManager stateManager, final I18nTranslationService i18n, final CoreResources img) {
+      final StateManager stateManager, final I18nTranslationService i18n, final CoreResources img,
+      final Provider<SocialNetworkServiceAsync> snService, final Session session) {
     super();
     this.chatEngine = chatEngine;
+    this.snService = snService;
+    this.session = session;
     putValue(Action.NAME, i18n.t(CoreMessages.ADD_AS_A_BUDDY));
     putValue(Action.SMALL_ICON, img.addGreen());
   }
@@ -55,8 +64,12 @@
     }
     if (username != null) {
       chatEngine.addNewBuddy(username);
-      // NotifyUser.info("Added as buddy. Waiting buddy response");
       setEnabled(false);
+      snService.get().addAsBuddie(session.getUserHash(), username, new AsyncCallbackSimple<Void>() {
+        @Override
+        public void onSuccess(final Void result) {
+        }
+      });
     }
   }
 }

Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkService.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkService.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -36,6 +36,8 @@
   SocialNetworkDataDTO addAdminMember(String hash, StateToken groupToken, String groupToAddShortName)
       throws DefaultException;
 
+  void addAsBuddie(String hash, String userName) throws DefaultException;
+
   SocialNetworkDataDTO addCollabMember(String hash, StateToken groupToken, String groupToAddShortName)
       throws DefaultException;
 

Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkServiceAsync.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkServiceAsync.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/SocialNetworkServiceAsync.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -33,6 +33,8 @@
   void addAdminMember(String hash, StateToken groupToken, String groupToAddShortName,
       AsyncCallback<SocialNetworkDataDTO> callback);
 
+  void addAsBuddie(String hash, String userName, AsyncCallback<Void> callback);
+
   void addCollabMember(String hash, StateToken groupToken, String groupToAddShortName,
       AsyncCallback<SocialNetworkDataDTO> callback);
 

Modified: trunk/src/main/java/cc/kune/core/server/notifier/NotificationHtmlHelper.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/NotificationHtmlHelper.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/core/server/notifier/NotificationHtmlHelper.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -35,6 +35,14 @@
     this.fileDownloadUtils = fileDownloadUtils;
   }
 
+  private FormatedString entityNotification(final String groupName, final boolean hasLogo,
+      final String message, final boolean isPersonal) {
+    final String groupUrl = fileDownloadUtils.getUrl(groupName);
+    return FormatedString.build(false, GROUP_TEMPLATE, groupUrl,
+        fileDownloadUtils.getLogoAvatarHtml(groupName, hasLogo, isPersonal, 50, 5), groupUrl, groupName,
+        message);
+  }
+
   /**
    * Generates a group notification in html like [logo|message]
    * 
@@ -50,13 +58,28 @@
    */
   public FormatedString groupNotification(final String groupName, final boolean hasLogo,
       final String message) {
-    final String groupUrl = fileDownloadUtils.getUrl(groupName);
-    return FormatedString.build(false, GROUP_TEMPLATE, groupUrl,
-        fileDownloadUtils.getLogoAvatarHtml(groupName, hasLogo, false, 50, 5), groupUrl, groupName,
-        message);
+    return entityNotification(groupName, hasLogo, message, false);
   }
 
   /**
+   * Generates a user notification in html like [logo|message]
+   * 
+   * @param userName
+   *          the user name you want to get the notification
+   * @param hasLogo
+   *          the has logo?
+   * @param message
+   *          the message to show close to the logo
+   * @param readMoreMsg
+   *          the read more msg
+   * @return the html string
+   */
+  public FormatedString userNotification(final String userName, final boolean hasLogo,
+      final String message) {
+    return entityNotification(userName, hasLogo, message, true);
+  }
+
+  /**
    * Format a user notification with an additional link. The first an unique %s
    * in body is changed by the site name.
    * 

Modified: trunk/src/main/java/cc/kune/core/server/notifier/NotificationService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/notifier/NotificationService.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/core/server/notifier/NotificationService.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -80,6 +80,12 @@
     notifyToAll(groupSender, subject, message, adminMembers);
   }
 
+  public void notifyGroupToUser(final Group group, final User to, final String subject,
+      final String message) {
+    sender.add(NotificationType.email, createPlainSubject(subject),
+        helper.groupNotification(group.getShortName(), group.hasLogo(), message), true, false, to);
+  }
+
   private void notifyToAll(final Group groupSender, final String subject, final String message,
       final Collection<User> users) {
     for (final User to : users) {
@@ -89,14 +95,14 @@
     }
   }
 
-  public void notifyUser(final User to, final Group group, final String subject, final String message) {
+  public void notifyUserToUser(final User from, final User to, final String subject, final String message) {
     sender.add(NotificationType.email, createPlainSubject(subject),
-        helper.groupNotification(group.getShortName(), group.hasLogo(), message), true, true, to);
+        helper.userNotification(from.getShortName(), from.hasLogo(), message), true, false, to);
   }
 
   /**
-   * Send email to an User with a link.The first an unique %s in body is changed
-   * by the site name.
+   * Send email to an User with a link. The first an unique %s in body is
+   * changed by the site name.
    * 
    * @param to
    *          the User to send the notification

Modified: trunk/src/main/java/cc/kune/core/server/rpc/SocialNetworkRPC.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/rpc/SocialNetworkRPC.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/core/server/rpc/SocialNetworkRPC.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -35,6 +35,7 @@
 import cc.kune.core.shared.dto.SocialNetworkRequestResult;
 import cc.kune.domain.Group;
 import cc.kune.domain.User;
+import cc.kune.domain.finders.UserFinder;
 
 import com.google.inject.Inject;
 import com.google.inject.persist.Transactional;
@@ -45,16 +46,18 @@
   private final Mapper mapper;
   private final NotificationService notifyService;
   private final SocialNetworkManager socialNetworkManager;
+  private final UserFinder userFinder;
   private final UserSessionManager userSessionManager;
 
   @Inject
   public SocialNetworkRPC(final UserSessionManager userSessionManager, final GroupManager groupManager,
-      final SocialNetworkManager socialNetworkManager, final Mapper mapper,
+      final SocialNetworkManager socialNetworkManager, final Mapper mapper, final UserFinder userFinder,
       final NotificationService notifyService) {
     this.userSessionManager = userSessionManager;
     this.groupManager = groupManager;
     this.socialNetworkManager = socialNetworkManager;
     this.mapper = mapper;
+    this.userFinder = userFinder;
     this.notifyService = notifyService;
   }
 
@@ -92,6 +95,15 @@
 
   @Override
   @Authenticated
+  @Transactional
+  public void addAsBuddie(final String hash, final String userName) throws DefaultException {
+    final User userLogged = userSessionManager.getUser();
+    final User toUser = userFinder.findByShortName(userName);
+    notifyService.notifyUserToUser(userLogged, toUser, "Added as buddie", "He/she added you as buddie");
+  }
+
+  @Override
+  @Authenticated
   @Authorizated(actionLevel = ActionLevel.group, accessRolRequired = AccessRol.Administrator)
   @Transactional
   public SocialNetworkDataDTO addCollabMember(final String hash, final StateToken groupToken,
@@ -232,5 +244,4 @@
     notifyService.notifyGroupAdmins(group, userLogged.getUserGroup(), "Some member left this group",
         "Some member have left this group");
   }
-
 }

Modified: trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java	2012-02-11 20:34:43 UTC (rev 1679)
+++ trunk/src/main/java/cc/kune/events/client/viewer/CalendarViewerPresenter.java	2012-02-11 21:13:06 UTC (rev 1680)
@@ -116,7 +116,7 @@
     getView().addTimeBlockClickHandler(new TimeBlockClickHandler<Date>() {
       @Override
       public void onTimeBlockClick(final TimeBlockClickEvent<Date> event) {
-        NotifyUser.info("on time block");
+        // NotifyUser.info("on time block");
         appToEdit = NO_APPOINT;
         onOverDate = event.getTarget();
         updateMenuItems();
@@ -138,14 +138,14 @@
         }
         event.setCancelled(!editable);
         // event.setCancelled(true);
-        NotifyUser.info("updated handler");
+        // NotifyUser.info("updated handler");
         hideMenu();
       }
     });
     getView().addOpenHandler(new OpenHandler<Appointment>() {
       @Override
       public void onOpen(final OpenEvent<Appointment> event) {
-        NotifyUser.info("open handler");
+        // NotifyUser.info("open handler");
       }
     });
     getView().addSelectionHandler(new SelectionHandler<Appointment>() {
@@ -153,7 +153,7 @@
       public void onSelection(final SelectionEvent<Appointment> event) {
         appToEdit = event.getSelectedItem();
         onOverDate = event.getSelectedItem().getStart();
-        NotifyUser.info("on selection");
+        // NotifyUser.info("on selection");
         updateMenuItems();
         showMenu();
       }




More information about the kune-commits mailing list