예제 #1
0
 public GroupService(XueLeMeContext context, NotificationService notificationService, IHubContext <NotificationHub> hubContext, IConnectionService connectionService)
 {
     Context             = context;
     NotificationService = notificationService;
     HubContext          = hubContext;
     ConnectionService   = connectionService;
 }
예제 #2
0
 public MailAccountService(XueLeMeContext context, IMailService mailService, ISecurityService securityService, IConfiguration configuration)
 {
     Context         = context;
     MailService     = mailService;
     SecurityService = securityService;
     Configuration   = configuration;
 }
예제 #3
0
 public NotificationService(
     IConnectionService connectionService,
     XueLeMeContext context,
     IHubContext <NotificationHub> hubContext
     )
 {
     ConnectionService = connectionService;
     Context           = context;
     HubContext        = hubContext;
 }
예제 #4
0
        public async Task <string> SendMessage(int groupId, int type, string content)
        {
            bool hasUserId = ConnectionIdToUserId.TryGetValue(Context.ConnectionId, out int userId);

            if (!hasUserId)
            {
                return("当前未确客户端用户身份");
            }
            if (type == (int)ChatMessage.MessageTypeEnum.Image && !CheckImageExist(content))
            {
                return("找不到消息的图片资源,请先上传图片资源");
            }
            var group = await GroupService.GroupFromId(groupId);

            if (group.State != ServiceResultEnum.Exist)
            {
                return(group.Detail);
            }
            var user = await AccountService.UserFromId(userId);

            if (user.State != ServiceResultEnum.Exist)
            {
                return(user.Detail);
            }
            var userInGroup = await GroupService.HasMemberShip(user.ExtraData, group.ExtraData);

            if (!userInGroup.ExtraData)
            {
                return(userInGroup.Detail);
            }
            var targets = Clients.Group(groupId.ToString());
            var message = new ChatMessage
            {
                MessageOrImageKey = content,
                Type = (ChatMessage.MessageTypeEnum)type
            };
            ChatRecord chatRecord = new ChatRecord
            {
                Sender      = user.ExtraData,
                CreatedTime = DateTime.Now,
                Group       = group.ExtraData,
                Message     = message
            };

            XueLeMeContext.ChatMessages.Add(message);
            XueLeMeContext.ChatRecords.Add(chatRecord);
            await XueLeMeContext.SaveChangesAsync();

            await targets.SendAsync("OnReceiveMessage", userId, groupId, type, content, chatRecord.CreatedTime);

            return("发送成功");
        }
 public DbFileService(XueLeMeContext xueLeMeContext, MD5Service mD5Service, ILogger <DbFileService> logger)
 {
     Context    = xueLeMeContext;
     MD5Service = mD5Service;
     Logger     = logger;
 }
예제 #6
0
 public TagService(XueLeMeContext context)
 {
     Context = context;
 }
 public TopicService(XueLeMeContext context, TagService tagService, NotificationService notificationService)
 {
     Context             = context;
     TagService          = tagService;
     NotificationService = notificationService;
 }
예제 #8
0
 public AccountService(XueLeMeContext context)
 {
     Context = context;
 }
예제 #9
0
 public WeatherForecastController(IMailService mainService, XueLeMeContext context, IHubContext <ChatHub> hubContext)
 {
     MainService = mainService;
     Context     = context;
     HubContext  = hubContext;
 }
예제 #10
0
 public ChatHub(XueLeMeContext xueLeMeContext, GroupService groupService, AccountService accountService)
 {
     XueLeMeContext = xueLeMeContext;
     GroupService   = groupService;
     AccountService = accountService;
 }
예제 #11
0
 public ChatRecordService(XueLeMeContext context)
 {
     Context = context;
 }
 public NotificationHub(IConnectionService connectionService, XueLeMeContext xueLeMeContext, ILogger <NotificationHub> logger)
 {
     ConnectionService = connectionService;
     XueLeMeContext    = xueLeMeContext;
     Logger            = logger;
 }