moah client side stuff and temp database schema
This commit is contained in:
		
							parent
							
								
									2a48c2da55
								
							
						
					
					
						commit
						3ed466930c
					
				
					 2 changed files with 97 additions and 15 deletions
				
			
		|  | @ -1,15 +1,50 @@ | |||
| exports.postAceInit = function(){ | ||||
| 
 | ||||
|    | ||||
|   // after 10 seconds if we dont already have an email for this author then prompt them
 | ||||
|   setTimeout(function(){askClientToEnterEmail()},10000); | ||||
|   setTimeout(function(){init()},10000); | ||||
| } | ||||
| 
 | ||||
| function init(){ | ||||
|   if(clientHasAlreadyRegistered){ // if the client has already registered for emails on this pad.
 | ||||
|     showAlreadyRegistered(); // client has already registered, let em know..
 | ||||
|   }else{ | ||||
|     askClientToEnterEmail(); // ask the client to register
 | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| function showAlreadyRegistered(){ // the client already registered for emails on this pad so notify the UI
 | ||||
|   $.gritter.add({ | ||||
|     // (string | mandatory) the heading of the notification
 | ||||
|     title: "Email subscription", | ||||
|     // (string | mandatory) the text inside the notification
 | ||||
|     text: "You are already registered for emails for this pad", | ||||
|     // (bool | optional) if you want it to fade out on its own or just sit there
 | ||||
|     sticky: false | ||||
|   }); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| function clientHasAlreadyRegistered(){ // Has the client already registered for emails on this?
 | ||||
|   // Given a specific AuthorID do we have an email address in the database?
 | ||||
|   // Given that email address is it registered to this pad?
 | ||||
|   // need to pass the server a message to check
 | ||||
|   var userId = pad.getUserId(); | ||||
|   var message = {}; | ||||
|   message.type = 'USERINFO_AUTHOR_EMAIL_IS_REGISTERED_TO_PAD'; | ||||
|   message.userInfo = {}; | ||||
|   message.userInfo.userId = userId; | ||||
|   pad.collabClient.sendMessage(message); | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| function askClientToEnterEmail(){ | ||||
|   $.gritter.add({ | ||||
|     // (string | mandatory) the heading of the notification
 | ||||
|     title: "Recieve Email notifications for this pad", | ||||
|     title: "Email notifications for this pad", | ||||
|     // (string | mandatory) the text inside the notification
 | ||||
|     text: "<form id='ep_email_form'><label for='ep_email'><input type=text id='ep_email'><input type=submit></form>", | ||||
|     text: "<form id='ep_email_form'><label for='ep_email'><input id='ep_email' placeholder='your@email.com' value='foo@bar.com' type=email><input type=submit></form>", | ||||
|     // (bool | optional) if you want it to fade out on its own or just sit there
 | ||||
|     sticky: true, | ||||
|     // (int | optional) the time you want it to be alive for before fading out
 | ||||
|  | @ -38,7 +73,7 @@ function sendEmailToServer(){ | |||
|   var message = {}; | ||||
|   message.type = 'USERINFO_UPDATE'; | ||||
|   message.userInfo = {}; | ||||
| //  message.userInfo.colorId = "#0000";
 | ||||
|   message.padId = pad.getPadId(); | ||||
|   message.userInfo.email = email; | ||||
|   message.userInfo.userId = userId; | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										69
									
								
								update.js
									
										
									
									
									
								
							
							
						
						
									
										69
									
								
								update.js
									
										
									
									
									
								
							|  | @ -1,4 +1,4 @@ | |||
|  var  db = require('../../src/node/db/DB').db; | ||||
|  var  db = require('../../src/node/db/DB').db, | ||||
|      API = require('../../src/node/db/API.js'), | ||||
|    async = require('../../src/node_modules/async'), | ||||
| settings = require('../../src/node/utils/Settings'); | ||||
|  | @ -10,25 +10,69 @@ var timers = {}; | |||
| 
 | ||||
| // When a new message comes in from the client
 | ||||
| exports.handleMessage = function(hook_name, context, callback){ | ||||
|   console.warn(context); | ||||
|   if (context.message && context.message.data){ | ||||
|     if (context.message.data.type == 'USERINFO_UPDATE' ) { // if it smells okay..
 | ||||
|     if (context.message.data.type == 'USERINFO_UPDATE' ) { // if it's a request to update an authors email
 | ||||
|       if (context.message.data.userInfo){ | ||||
| console.warn("foo",context.message.data.userInfo); | ||||
|         console.debug("userInfo",context.message.data.userInfo); | ||||
|         if(context.message.data.userInfo.email){ // it contains email
 | ||||
|           exports.setAuthorEmail( | ||||
|             context.message.data.userInfo.userId,  | ||||
|             context.message.data.userInfo.email, callback); | ||||
|           // console.warn(context.message.data.userInfo.userId);
 | ||||
| 
 | ||||
|           console.debug(context.message); | ||||
| 
 | ||||
|           db.get("emailSubscription:"+context.message.data.padId, function(err, userIds){ // does email Subscription already exist for this user?
 | ||||
| 
 | ||||
|             console.debug("UserIds subscribed by email to this pad:", userIds); | ||||
| 
 | ||||
|             if(userIds){ //  THIS NEEDS TO BE AN OBJECT :: TODO
 | ||||
|               // This user ID is already assigned to this padId so don't do anything except tell the user they are already subscribed somehow..
 | ||||
| 
 | ||||
|               context.client.json.send({ type: "COLLABROOM", | ||||
|                 data:{ | ||||
|                   type: email_subscription_success, | ||||
|                   payload: false | ||||
|                 } | ||||
|               }); | ||||
| 
 | ||||
|             }else{ | ||||
| 
 | ||||
|               // console.warn ("WRITE MY GOODNESS TO THE DATABASE!",context.message.data.userInfo.email);
 | ||||
| 
 | ||||
|               exports.setAuthorEmail( | ||||
|                 context.message.data.userInfo.userId,  | ||||
|                 context.message.data.userInfo.email, callback | ||||
|               ); | ||||
| 
 | ||||
|               exports.setAuthorEmailRegistered( | ||||
|                 context.message.data.userInfo.userId, | ||||
|                 context.message.data.padId, callback | ||||
|               ); | ||||
|   | ||||
|               context.client.json.send({ type: "COLLABROOM", | ||||
|                 data:{ | ||||
|                   type: email_subscription_success, | ||||
|                   payload: true | ||||
|                 } | ||||
|               }); | ||||
| 
 | ||||
|             } | ||||
|           }); | ||||
| 
 | ||||
|           callback(null); // don't run onto passing colorId or anything else to the message handler
 | ||||
| 
 | ||||
|           console.warn ("WRITE MY GOODNESS TO THE DATABASE!",context.message.data.userInfo.email); | ||||
|         } | ||||
|       } | ||||
|       console.warn ("LORDAMERCI!"); | ||||
|     } | ||||
|   } | ||||
|   callback(); | ||||
| } | ||||
| 
 | ||||
| exports.doesPadIdEmailAssociationAlreadyExist = function (padId, email){ | ||||
|   var found = false; | ||||
|   db.get("emailSubscription:"+padId, function(err, value){ | ||||
|     return value; | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| exports.padUpdate = function (hook_name, _pad) { | ||||
| 
 | ||||
|   var pad = _pad.pad; | ||||
|  | @ -122,8 +166,11 @@ exports.createInterval = function(padId){ | |||
| } | ||||
| 
 | ||||
| // Updates the database with the email record
 | ||||
| exports.setAuthorEmail = function (author, email, callback) | ||||
| { | ||||
| exports.setAuthorEmail = function (author, email, callback){ | ||||
|   db.setSub("globalAuthor:" + author, ["email"], email, callback); | ||||
| } | ||||
| 
 | ||||
| // Write email and padId to the database
 | ||||
| exports.setAuthorEmailRegistered = function(author, padId, callback){ | ||||
|   db.set("emailSubscription:" + padId, author); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John McLear
						John McLear