|  | @@ -15,16 +15,16 @@ Router.route("/", function () {
 | 
											
												
													
														|  |  // specify a route that allows the current user to chat to another users
 |  |  // specify a route that allows the current user to chat to another users
 | 
											
												
													
														|  |  Router.route("/chat/:_id", {
 |  |  Router.route("/chat/:_id", {
 | 
											
												
													
														|  |    subscriptions: function () {
 |  |    subscriptions: function () {
 | 
											
												
													
														|  | -    Meteor._debug('subscriptions', arguments);
 |  | 
 | 
											
												
													
														|  | 
 |  | +    Meteor._debug("Subscriptions");
 | 
											
												
													
														|  |      return Meteor.subscribe("chats");
 |  |      return Meteor.subscribe("chats");
 | 
											
												
													
														|  |    },
 |  |    },
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  action: function () {
 |  | 
 | 
											
												
													
														|  | -    Meteor._debug('action', arguments);
 |  | 
 | 
											
												
													
														|  | 
 |  | +  action: function (req, wtf, func) {
 | 
											
												
													
														|  | 
 |  | +    Meteor._debug("Action", req.url);
 | 
											
												
													
														|  |      if (this.ready()) {
 |  |      if (this.ready()) {
 | 
											
												
													
														|  | -      Meteor._debug("Ready");
 |  | 
 | 
											
												
													
														|  | -      // the user they want to chat to has id equal to
 |  | 
 | 
											
												
													
														|  | -      // the id sent in after /chat/...
 |  | 
 | 
											
												
													
														|  | 
 |  | +      console.log("- Now ready");
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +      // The user they want to chat to has id equal to the id sent in after /chat/...
 | 
											
												
													
														|  |        const otherUserId = this.params._id;
 |  |        const otherUserId = this.params._id;
 | 
											
												
													
														|  |        // find a chat that has two users that match current user id
 |  |        // find a chat that has two users that match current user id
 | 
											
												
													
														|  |        // and the requested user id
 |  |        // and the requested user id
 | 
											
										
											
												
													
														|  | @@ -41,7 +41,8 @@ Router.route("/chat/:_id", {
 | 
											
												
													
														|  |          ]
 |  |          ]
 | 
											
												
													
														|  |        };
 |  |        };
 | 
											
												
													
														|  |        const chat = Chats.findOne(filter);
 |  |        const chat = Chats.findOne(filter);
 | 
											
												
													
														|  | -      Meteor._debug(filter, chat);
 |  | 
 | 
											
												
													
														|  | 
 |  | +      // Meteor._debug(filter, chat);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |        // No chat matching the filter - need to insert a new one.
 |  |        // No chat matching the filter - need to insert a new one.
 | 
											
												
													
														|  |        let chatId;
 |  |        let chatId;
 | 
											
												
													
														|  |        if (!chat) {
 |  |        if (!chat) {
 | 
											
										
											
												
													
														|  | @@ -49,22 +50,31 @@ Router.route("/chat/:_id", {
 | 
											
												
													
														|  |            user1Id: Meteor.userId(),
 |  |            user1Id: Meteor.userId(),
 | 
											
												
													
														|  |            user2Id: otherUserId
 |  |            user2Id: otherUserId
 | 
											
												
													
														|  |          });
 |  |          });
 | 
											
												
													
														|  | -        Meteor._debug("No chat found between " + Meteor.userId() + " and " + otherUserId + ". Created " + chatId);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        console.log("--- No chat found between " + Meteor.userId() + " and " + otherUserId + ". Created " + chatId);
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |        // There is a chat going already - use that.
 |  |        // There is a chat going already - use that.
 | 
											
												
													
														|  |        else {
 |  |        else {
 | 
											
												
													
														|  |          chatId = chat._id;
 |  |          chatId = chat._id;
 | 
											
												
													
														|  | -        Meteor._debug("Chat " + chatId + " found between " + Meteor.userId() + " and " + otherUserId + ".");
 |  | 
 | 
											
												
													
														|  | 
 |  | +        console.log("--- Chat " + chatId + " found between " + Meteor.userId() + " and " + otherUserId + ".");
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |        // Looking good, save the id to the session.
 |  |        // Looking good, save the id to the session.
 | 
											
												
													
														|  |        if (chatId) {
 |  |        if (chatId) {
 | 
											
												
													
														|  |          Session.set("chatId", chatId);
 |  |          Session.set("chatId", chatId);
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  |        this.render("navbar", { to: "header" });
 |  |        this.render("navbar", { to: "header" });
 | 
											
												
													
														|  | -      this.render("chat_page", { to: "main" });
 |  | 
 | 
											
												
													
														|  | 
 |  | +      this.render("chat_page", {
 | 
											
												
													
														|  | 
 |  | +        to: "main",
 | 
											
												
													
														|  | 
 |  | +        data: function () {
 | 
											
												
													
														|  | 
 |  | +          const other = Meteor.users.findOne({ _id: otherUserId });
 | 
											
												
													
														|  | 
 |  | +          console.log("--- Routing data, other: " + (other ? other.profile.username : "not available"));
 | 
											
												
													
														|  | 
 |  | +          return {
 | 
											
												
													
														|  | 
 |  | +            other: other
 | 
											
												
													
														|  | 
 |  | +          };
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +      });
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      else {
 |  |      else {
 | 
											
												
													
														|  | -      Meteor._debug('not ready');
 |  | 
 | 
											
												
													
														|  | 
 |  | +      console.log("- Not yet ready");
 | 
											
												
													
														|  |        this.render("Loading");
 |  |        this.render("Loading");
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |    }
 |  |    }
 |