Пример #1
0
        /// <summary>
        /// 拒绝添加好友
        /// </summary>
        public async Task RejectFriend(string friendId)
        {
            var model = FriendNotificationRepository.Find(f => f.Id == new Guid(friendId)).FirstOrDefault();

            string userId = string.Empty;
            string connId = string.Empty;
            string to     = model.ToUserId.ToString().ToLower();

            if (UserIdByClient.ContainsKey(Context.ConnectionId))
            {
                userId = UserIdByClient[Context.ConnectionId];
            }

            if (ClientByUserId.ContainsKey(to))
            {
                connId = ClientByUserId[to];
            }

            model.State = 2;
            UserGroupRelationshipRepository.SaveChanges();

            if (!string.IsNullOrEmpty(connId))
            {
                await Clients.Client(connId).SendAsync("ReceiveRejectFriendByFromUser", "对方拒绝添加你为好友");
            }
        }
Пример #2
0
        /// <summary>
        /// 同意成为好友
        /// </summary>
        public async Task AgreeFriend(string friendId)
        {
            var model = FriendNotificationRepository.Find(f => f.Id == new Guid(friendId)).FirstOrDefault();

            string userId = string.Empty;
            string connId = string.Empty;
            string to     = model.ToUserId.ToString().ToLower();

            if (UserIdByClient.ContainsKey(Context.ConnectionId))
            {
                userId = UserIdByClient[Context.ConnectionId];
            }

            if (ClientByUserId.ContainsKey(to))
            {
                connId = ClientByUserId[to];
            }

            //发起人添加关联
            UserGroupRelationship fromUgp = new UserGroupRelationship();

            fromUgp.Id      = Guid.NewGuid();
            fromUgp.UserId  = model.ToUserId;
            fromUgp.GroupId = model.FromUser.GroupList[0].Id;
            UserGroupRelationshipRepository.Add(fromUgp);

            //接收人添加关联
            UserGroupRelationship toUgp = new UserGroupRelationship();

            toUgp.Id      = Guid.NewGuid();
            toUgp.UserId  = model.FromUserId;
            toUgp.GroupId = model.ToUser.GroupList[0].Id;
            UserGroupRelationshipRepository.Add(toUgp);

            model.State = 3;

            UserGroupRelationshipRepository.SaveChanges();

            if (!string.IsNullOrEmpty(connId))
            {
                await Clients.Client(connId).SendAsync("ReceiveAgreeFriendByFromUser", "对方同意添加你为好友");
            }

            await Clients.Client(Context.ConnectionId).SendAsync("ReceiveAgreeFriendByToUser", "同意成为好友");
        }