예제 #1
0
        public IActionResult PushMessage(PushMessageAddressModel model)
        {
            //Ensure app
            var appid = _tokenManager.ValidateAccessToken(model.AccessToken);
            //Ensure channel
            var channel = _memoryContext.GetChannelsUnderApp(appid).SingleOrDefault(t => t.Id == model.ChannelId);

            if (channel == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"We can not find your channel with id: '{model.ChannelId}'!"));
            }
            //Create Message
            var message = new Message
            {
                Id        = _counter.GetUniqueNo(),
                ChannelId = channel.Id,
                Content   = model.MessageContent
            };

            channel.Push(message);
            return(Ok(new AiurProtocol
            {
                Code = ErrorType.Success,
                Message = $"You have successfully pushed a new message to channel: {channel.Id}!"
            }));
        }
예제 #2
0
        public async Task <IActionResult> PushMessage(PushMessageAddressModel model)
        {
            var token = await _dbContext.AccessTokens.Include(t => t.ApplyApp).SingleOrDefaultAsync(t => t.Value == model.AccessToken);

            if (token == null || token.ApplyApp == null)
            {
                return(this.Protocol(ErrorType.Unauthorized, "Invalid accesstoken!"));
            }
            //Ensure channel
            var channel = await _dbContext.Channels.SingleOrDefaultAsync(t => t.Id == model.ChannelId);

            if (channel == null)
            {
                return(this.Protocol(ErrorType.NotFound, "We can not find your channel!"));
            }
            if (channel.AppId != token.ApplyAppId)
            {
                return(this.Protocol(ErrorType.Unauthorized, "The channel you wanna create message is not your app's channel!"));
            }
            //Create Message
            var message = new Message
            {
                Id        = Startup.MessageIdCounter.GetUniqueNo(),
                ChannelId = channel.Id,
                Content   = model.MessageContent
            };

            MqMemoryContext.Messages.Add(message);

            return(this.Protocol(ErrorType.Success, $"You have successfully created a message at channel:{channel.Id}!"));
        }
예제 #3
0
        public async Task <IActionResult> PushMessage(PushMessageAddressModel model)
        {
            //Ensure app
            var appid = _tokenManager.ValidateAccessToken(model.AccessToken);
            //Ensure channel
            var channel = await _dbContext.Channels.SingleOrDefaultAsync(t => t.Id == model.ChannelId && t.AppId == appid);

            if (channel == null)
            {
                return(Json(new AiurProtocol
                {
                    Code = ErrorType.NotFound,
                    Message = "We can not find your channel!"
                }));
            }
            //Create Message
            var message = new Message
            {
                Id        = _counter.GetUniqueNo,
                ChannelId = channel.Id,
                Content   = model.MessageContent
            };

            _memoryContext.Messages.Add(message);
            return(Json(new AiurProtocol
            {
                Code = ErrorType.Success,
                Message = $"You have successfully pushed a new message to channel: {channel.Id}!"
            }));
        }
예제 #4
0
        public async Task <IActionResult> PushMessage(PushMessageAddressModel model)
        {
            //Ensure app is created
            var app = await ApiService.ValidateAccessTokenAsync(model.AccessToken);

            var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.Id == app.AppId);

            if (appLocal == null)
            {
                appLocal = new StargateApp
                {
                    Id       = app.AppId,
                    Channels = new List <Channel>()
                };
                _dbContext.Apps.Add(appLocal);
                await _dbContext.SaveChangesAsync();
            }
            //Ensure channel
            var channel = await _dbContext.Channels.SingleOrDefaultAsync(t => t.Id == model.ChannelId);

            if (channel == null)
            {
                return(Json(new AiurProtocal
                {
                    code = ErrorType.NotFound,
                    message = "We can not find your channel!"
                }));
            }
            if (channel.AppId != app.AppId)
            {
                return(Json(new AiurProtocal
                {
                    code = ErrorType.Unauthorized,
                    message = "The channel you wanna create message is not your app's channel!"
                }));
            }
            //Create Message
            var message = new Message
            {
                Id        = Startup.MessageIdCounter.GetUniqueNo,
                ChannelId = channel.Id,
                Content   = model.MessageContent
            };

            StargateMemory.Messages.Add(message);
            return(Json(new AiurProtocal
            {
                code = ErrorType.Success,
                message = $"You have successfully created a message at channel:{channel.Id}!"
            }));
        }