Set up bookmarkEngine._incomingShareOffer to use Myk's new Notification stuff to offer a notification to the user, asking them to accept or reject the incoming share.
authorjonathandicarlo@jonathan-dicarlos-macbook-pro.local
Wed, 25 Jun 2008 15:54:33 -0700
changeset 44747 44649eec63a04eb86e6c27a30861d5b4e607af3b
parent 44745 e7e4defa3d6804a9fb95693f410243bec2054502
child 44748 d081cddcf9fc761a403d49c00b89280579559a5f
push idunknown
push userunknown
push dateunknown
Set up bookmarkEngine._incomingShareOffer to use Myk's new Notification stuff to offer a notification to the user, asking them to accept or reject the incoming share.
services/sync/modules/engines/bookmarks.js
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -129,60 +129,73 @@ BookmarksSharingManager.prototype = {
         */
  	let words = messageText.split(" ");
 	let commandWord = words[0];
 	let serverPath = words[1];
 	let directoryName = words.slice(2).join(" ");
         if ( commandWord == "share" ) {
 	  bmkSharing._incomingShareOffer(from, serverPath, folderName);
 	} else if ( commandWord == "stop" ) {
-	  bmkSharing._incomingShareWithdrawn(from, serverPath, folderName);
+          bmkSharing._log.info("User " + user + " withdrew " + folderName);
+          bmkSharing._stopIncomingShare(user, serverPath, folderName);
 	}
       }
     };
 
     this._xmppClient.registerMessageHandler( messageHandler );
     this._xmppClient.connect( realm, self.cb );
     yield;
     if ( this._xmppClient._connectionStatus == this._xmppClient.FAILED ) {
       this._log.warn( "Weave can't log in to xmpp server: xmpp disabled." );
     } else if ( this._xmppClient._connectionStatus == this._xmppClient.CONNECTED ) {
       this._log.info( "Weave logged into xmpp OK." );
     }
     self.done();
   },
 
   _incomingShareOffer: function BmkSharing__incomingShareOffer(user,
-                                                              serverPath,
-                                                              folderName) {
+                                                               serverPath,
+                                                               folderName) {
     /* Called when we receive an offer from another user to share a
-       folder.
-
-       TODO what should happen is that we add a notification to the queue
-       telling that the incoming share has been offered; when the offer
-       is accepted we will call createIncomingShare and then
-       updateIncomingShare.
-
-       But since we don't have notification in place yet, I'm going to skip
-       right ahead to creating the incoming share.
+       folder.  Set up a notification telling our user about the share offer
+       and allowing them to accept or reject it.
     */
     this._log.info("User " + user + " offered to share folder " + folderName);
-    this._createIncomingShare(user, serverPath, folderName);
+
+    let bmkSharing = this;
+    let acceptButton = new Weave.NotificationButton(
+      "Accept Share",
+      "a",
+      function() {
+	// This is what happens when they click the Accept button:
+	bmkSharing._log.info("Accepted bookmark share from " + user);
+	bmkSharing._createIncomingShare(user, serverPath, folderName);
+	bmkSharing._updateAllIncomingShares();
+	return false;
+      }
+    );
+    let rejectButton = new Weave.NotificationButton(
+      "No Thanks",
+      "n",
+      function() {return false;}
+    );
+
+    let title = "Bookmark Share Offer From " + user;
+    let description ="Weave user " + user +
+      " is offering to share a bookmark folder called " + folderName +
+      " with you. Do you want to accept it?";
+    let notification = Weave.Notification(title,
+					  description,
+					  null,
+					  Weave.Notifications.PRIORITY_INFO,
+					  [acceptButton, rejectButton]
+					 );
+    Weave.Notifications.add(notification);
   },
 
-  _incomingShareWithdrawn: function BmkSharing__incomingShareStop(user,
-                                                                 serverPath,
-                                                                 folderName) {
-    /* Called when we receive a message telling us that a user who has
-       already shared a directory with us has chosen to stop sharing
-       the directory.
-    */
-    this._log.info("User " + user + " stopped sharing folder " + folderName);
-    this._stopIncomingShare(user, serverPath, folderName);
-  },
   _share: function BmkSharing__share( selectedFolder, username ) {
     // Return true if success, false if failure.
     let ret = false;
     let self = yield;
 
     /* TODO What should the behavior be if i'm already sharing it with user
        A and I ask to share it with user B?  (This should be prevented by
        the UI. */