public JsonResult MessageDelivered(int message_id) { Conversation convo = null; using (var db = new Models.ChatContext()) { convo = db.Conversations.FirstOrDefault(c => c.id == message_id); if (convo != null) { convo.status = Conversation.messageStatus.Delivered; db.Entry(convo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } string socket_id = Request.Form["socket_id"]; var conversationChannel = getConvoChannel(convo.sender_id, convo.receiver_id); pusher.TriggerAsync( conversationChannel, "message_delivered", convo, new TriggerOptions() { SocketId = socket_id }); return(Json(convo)); }
public ActionResult Login() { string user_name = Request.Form["username"]; if (user_name.Trim() == "") { return(Redirect("/")); } using (var db = new Models.ChatContext()) { User user = db.Users.FirstOrDefault(u => u.Name == user_name); if (user == null) { user = new User { Name = user_name, CreatedAt = DateTime.Now }; db.Users.Add(user); db.SaveChanges(); } Session["user"] = user; } return(Redirect("/chat")); }
public JsonResult SendMessage() { if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (User)Session["user"]; var contact = Convert.ToInt32(Request.Form["contact"]); string socket_id = Request.Form["socket_id"]; Conversation convo = new Conversation { sender_id = currentUser.id, message = Request.Form["message"], receiver_id = contact }; using (var db = new Models.ChatContext()) { db.Conversations.Add(convo); db.SaveChanges(); } var conversationChannel = getConvoChannel(currentUser.id, contact); pusher.TriggerAsync( conversationChannel, "new_message", convo, new TriggerOptions() { SocketId = socket_id }); return(Json(convo)); }
public JsonResult SendMessage() { if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (User)Session["user"]; string socket_id = Request.Form["socket_id"]; Conversation convo = new Conversation { sender_id = currentUser.id, message = Request.Form["message"], receiver_id = Convert.ToInt32(Request.Form["contact"]) }; using (var db = new Models.ChatContext()) { db.Conversations.Add(convo); db.SaveChanges(); } return(Json(convo)); }
public ActionResult DeleteAll() { using (var db = new Models.ChatContext()) { Console.WriteLine("DELETE ALL MOFOS"); db.Users.RemoveRange(db.Users); db.Conversations.RemoveRange(db.Conversations); db.SaveChanges(); } return(Json(new { status = "success" }, JsonRequestBehavior.AllowGet)); }
public JsonResult SendMessage() { if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (User)Session["user"]; string socket_id = Request.Form["socket_id"]; Conversation convo = new Conversation { sender_id = currentUser.id, message = Request.Form["message"], receiver_id = Convert.ToInt32(Request.Form["contact"]) }; using (var db = new Models.ChatContext()) { db.Conversations.Add(convo); db.SaveChanges(); } var options = new PusherOptions(); options.Cluster = "PUSHER_APP_CLUSTER"; var pusher = new Pusher( "PUSHER_APP_ID", "PUSHER_APP_KEY", "PUSHER_APP_SECRET", options); pusher.TriggerAsync( "presence-chat", "new_message", convo, new TriggerOptions() { SocketId = socket_id }); return(Json(convo)); }
public JsonResult MessageDelivered(int message_id) { Conversation convo = null; using (var db = new Models.ChatContext()) { convo = db.Conversations.FirstOrDefault(c => c.id == message_id); if (convo != null) { convo.status = Conversation.messageStatus.Delivered; db.Entry(convo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } string socket_id = Request.Form["socket_id"]; var options = new PusherOptions(); options.Cluster = "PUSHER_APP_CLUSTER"; var pusher = new Pusher( "PUSHER_APP_ID", "PUSHER_APP_KEY", "PUSHER_APP_SECRET", options); pusher.TriggerAsync( "presence-chat", "message_delivered", convo, new TriggerOptions() { SocketId = socket_id }); return(Json(convo)); }