Beispiel #1
0
        public async Task <dynamic> UserConnected(string PeerId)
        {
            var langs  = Context.Request.Headers["Accept-Language"];
            var status = await PrivateChatContext.UserConnected((new NotificationHub()).HubIdentity, HubIdentity, PeerId, UserId, Context.ConnectionId, langs);

            if (status != null)
            {
                switch (status.status)
                {
                case PeerStatus.Connected:
                    Clients.Client(status.peer.ConnectionID).sendMessage("Hello");
                    return(new { status = status.status.ToString(), msg = "" });

                case PeerStatus.Notifiable:
                {
                    var nhub = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();
                    nhub.Clients.Client(status.peerNotifier.ConnectionID).serverNotifications(3, status.noticeMsg, new dynamic[] { });
                }
                    return(new { status = status.status.ToString(), msg = "" });

                case PeerStatus.MessageSent:
                    return(new { status = status.status.ToString(), msg = "" });
                }
                return(new { status = status.status.ToString(), msg = "" });
            }
            else
            {
                return(new { status = "???", msg = "Member is not found" });
            }
        }
Beispiel #2
0
        public async Task ConnectAck(string peerId)
        {
            var peer = await PrivateChatContext.FindPeer(HubIdentity, Context.Request.User.Identity.GetUserId(), peerId);

            if (peer != null)
            {
                Clients.Client(peer.ConnectionID).onConnectAck();
            }
        }
Beispiel #3
0
        public async Task SyncRecordState(string peerId, bool record)
        {
            var peer = await PrivateChatContext.FindPeer(HubIdentity, Context.Request.User.Identity.GetUserId(), peerId);

            if (peer != null)
            {
                Clients.Client(peer.ConnectionID).onSyncRecordState(record);
            }
        }
        public async Task LeaveSimpleMessage(string peerId, string replyId, dynamic msgObj)
        {
            var id = Context.Request.User.Identity;

            try
            {
                string msgbody = msgObj.body;
                await PrivateChatContext.LeaveUserMessage(HubIdentity, id.GetUserId(), peerId, replyId, msgbody);
            }
            catch (Exception ex)
            {
                Clients.Caller.sendError(ex.Message);
            }
        }
        public async Task UserCancelInteraction(string PeerId)
        {
            var langs  = Context.Request.Headers["Accept-Language"];
            var status = await PrivateChatContext.UserCancelInteraction(
                HubIdentity,
                (new PrivateChatHub()).HubIdentity,
                PeerId,
                UserId,
                Context.ConnectionId,
                langs);

            if (status != null && status.peerNotifier != null)
            {
                var nhub = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();
                nhub.Clients.Client(status.peerNotifier.ConnectionID).serverNotifications(3, status.noticeMsg, new dynamic[] { });
            }
        }
Beispiel #6
0
        public async Task SendSimpleMessage(string peerId, string replyId, dynamic msgObj, bool record)
        {
            var id = Context.Request.User.Identity;

            try
            {
                string msgbody = msgObj.body;
                var    msg     = await PrivateChatContext.AddUserMessage(HubIdentity, id.GetUserId(), peerId, replyId, msgbody, record);

                if (msg.peer != null)
                {
                    Clients.Client(msg.peer.ConnectionID).messageReceived(id.Name, msg.msg);
                }
                Clients.Caller.messageReceived(id.Name, msg.msg);
            }
            catch (Exception ex)
            {
                Clients.Caller.sendError(ex.Message);
            }
        }
Beispiel #7
0
        public async Task <ActionResult> ChatPopup(string toId)
        {
            if (string.IsNullOrEmpty(toId))
            {
                return(new HttpStatusCodeResult(404, "Not Found"));
            }
            else
            {
                string approot = VirtualPathUtility.ToAbsolute("~/");
                ViewBag.AppName = Startup.App.Name;
                ViewBag.UserID  = User.Identity.GetUserId();
                ViewBag.User    = await PrivateChatContext.LoadUserInfo(ViewBag.UserID, approot) + ";";

                ViewBag.PeerID = toId;
                ViewBag.Peer   = await PrivateChatContext.LoadUserInfo(toId, approot) + ";";

                ViewBag.ListStyle      = "popup-message-list";
                ViewBag.ReplyListStyle = "popup-reply-message-list";
                return(View());
            }
        }
Beispiel #8
0
        public async Task UserConnectResponse(int respType, string peerId, string connectionId, string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                var peer = await PrivateChatContext.LoadUser(peerId);

                var langs = peer.AcceptLanguages;
                switch (respType)
                {
                case 2:
                    msg = ResourceUtils.GetString("e5f5f73658abf8cf2c8d4ddc3d0a4466", "Hi, please wait ...", langs);
                    break;

                case 3:
                    msg = ResourceUtils.GetString("fc65af46674fd2f882b51de00db14b2c", "Sorry, I am busy now ...", langs);
                    break;

                case 4:
                    msg = ResourceUtils.GetString("a68bbf8eb735652404926659b3284b47", "Sorry, I would rather not talking to you now ...", langs);
                    break;
                }
            }
            Clients.Client(connectionId).peerConnectResponse(new { status = respType, msg = msg, connectId = Context.ConnectionId });
        }
Beispiel #9
0
        public async Task <ActionResult> LoadMessages(string toId, bool?seq)
        {
            var msgs = await PrivateChatContext.LoadMessages(toId, User.Identity.GetUserId(), MaxInitMsgs, !seq.HasValue || !seq.Value);

            return(Json(msgs, JsonRequestBehavior.AllowGet));
        }
 public async Task TogglePeerStatus(int statusType, string peerId)
 {
     await PrivateChatContext.TogglePeerStatus(statusType, Context.Request.User.Identity.GetUserId(), peerId);
 }
Beispiel #11
0
 public PrivatePrayerRequestService(PrivateChatContext context) : base(context)
 {
 }