Exemplo n.º 1
0
        public async Task NewMessageEvent(KahlaUser receiver, Conversation conversation, string content, KahlaUser sender, bool alert)
        {
            var token = await _appsContainer.AccessToken();

            var channel         = receiver.CurrentChannel;
            var newMessageEvent = new NewMessageEvent
            {
                ConversationId = conversation.Id,
                Sender         = sender,
                Content        = content,
                AESKey         = conversation.AESKey,
                Muted          = !alert
            };
            var pushTasks = new List <Task>();

            if (channel != -1)
            {
                pushTasks.Add(_stargatePushService.PushMessageAsync(token, channel, _Serialize(newMessageEvent), true));
            }
            if (alert && receiver.Id != sender.Id)
            {
                pushTasks.Add(_thirdPartyPushService.PushAsync(receiver.Id, sender.Email, _Serialize(newMessageEvent)));
            }
            await Task.WhenAll(pushTasks);
        }
        public async Task NewMessageEvent(ApplicationUser reciever, Conversation conversation, string content, ApplicationUser sender, bool alert)
        {
            var token = await _appsContainer.AccessToken();

            var channel  = reciever.CurrentChannel;
            var newEvent = new NewMessageEvent
            {
                Type           = EventType.NewMessage,
                ConversationId = conversation.Id,
                Sender         = sender,
                Content        = content,
                AESKey         = conversation.AESKey,
                Muted          = !alert,
                SentByMe       = reciever.Id == sender.Id
            };

            if (channel != -1)
            {
                await _stargatePushService.PushMessageAsync(token, channel, _Serialize(newEvent), true);
            }
            if (alert)
            {
                await _thirdPartyPushService.PushAsync(reciever.Id, sender.Email, _Serialize(newEvent));
            }
        }
Exemplo n.º 3
0
 public async Task<IActionResult> PushTestMessage()
 {
     var user = await GetKahlaUser();
     _dbContext.Entry(user)
         .Collection(b => b.HisDevices)
         .Load();
     var messageEvent = new NewMessageEvent
     {
         Message = new Message
         {
             ConversationId = -1,
             Sender = new KahlaUser
             {
                 IconFilePath = "kahla-user-icon/logo.png",
                 NickName = "Aiursoft Push System",
             },
             SenderId = "<Example user>",
             Content = "U2FsdGVkX1+6kWGFqiSsjuPWX2iS7occQbqXm+PCNDLleTdk5p2UVQgQpu8J4XAYSpz/NT6N5mJMUQIUrNt6Ow==",
             SendTime = DateTime.UtcNow,
         },
         AESKey = "37316f609ebc4e79bd7812a5f2ab37b8",
         Muted = false,
         Mentioned = false
     };
     var payload = JsonConvert.SerializeObject(messageEvent, Formatting.Indented, new JsonSerializerSettings
     {
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     });
     var token = await _appsContainer.AccessToken();
     await _thirdPartyPushService.PushAsync(user.HisDevices, "*****@*****.**", payload);
     await _stargatePushService.PushMessageAsync(token, user.CurrentChannel, payload);
     return this.Protocol(ErrorType.Success, "Successfully sent you a test message to all your devices.");
 }
        public async Task NewMessageEvent(string recieverId, int conversationId, string Content, KahlaUser sender)
        {
            var token = AppsContainer.AccessToken();
            var user  = await _dbContext.Users.FindAsync(recieverId);

            var channel = user.CurrentChannel;
            var nevent  = new NewMessageEvent
            {
                Type           = EventType.NewMessage,
                ConversationId = conversationId,
                Sender         = sender,
                Content        = Content
            };

            if (channel != -1)
            {
                await _pushMessageService.PushMessageAsync(await token(), channel, _CammalSer(nevent), true);
            }
        }
Exemplo n.º 5
0
        public async Task SendDebuggingMessages(string accessToken, int channelId)
        {
            var random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                await _messageService.PushMessageAsync(accessToken, channelId, Guid.NewGuid().ToString("N"));

                await Task.Delay(10);
            }
        }
Exemplo n.º 6
0
        public async Task SendDebuggingMessages(string AccessToken, int ChannelId)
        {
            var random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                await _messageService.PushMessageAsync(AccessToken, ChannelId, DateTime.Now + StringOperation.RandomString(10));

                await Task.Delay(10);
            }
        }
Exemplo n.º 7
0
        public async Task SendDebuggingMessages(string accessToken, int channelId)
        {
            for (int i = 0; i < 1000; i++)
            {
                await _messageService.PushMessageAsync(accessToken, channelId, new
                {
                    Guid = Guid.NewGuid().ToString("N"),
                    Time = DateTime.UtcNow,
                    Id   = i
                });

                await Task.Delay(10);
            }
        }
Exemplo n.º 8
0
        public async Task NewMessageEvent(int stargateChannel, IEnumerable <Device> devices, Conversation conversation, Message message, string lastMessageId, bool pushAlert, bool mentioned)
        {
            var token = await _appsContainer.AccessToken();

            var newMessageEvent = new NewMessageEvent
            {
                AESKey            = conversation.AESKey,
                Muted             = !pushAlert,
                Mentioned         = mentioned,
                Message           = message,
                PreviousMessageId = lastMessageId
            };
            var pushTasks = new List <Task>();

            if (stargateChannel != -1)
            {
                pushTasks.Add(_stargatePushService.PushMessageAsync(token, stargateChannel, JsonConvert.SerializeObject(newMessageEvent), true));
            }
            if (pushAlert)
            {
                pushTasks.Add(_thirdPartyPushService.PushAsync(devices, message.Sender.Email, JsonConvert.SerializeObject(newMessageEvent)));
            }
            await Task.WhenAll(pushTasks);
        }
Exemplo n.º 9
0
        public async Task <AiurProtocol> PushMessageAsync(string accessToken, int channelId, object eventObject)
        {
            try
            {
                return(await _pushMessageService.PushMessageAsync(accessToken, channelId, eventObject));
            }
            catch (AiurUnexpectedResponse e) when(e.Code == ErrorType.NotFound)
            {
                var referenced = _kahlaDbContext.Users.Where(t => t.CurrentChannel == channelId);

                foreach (var user in referenced)
                {
                    user.CurrentChannel = 0;
                    _kahlaDbContext.Users.Update(user);
                }
                await _kahlaDbContext.SaveChangesAsync();

                throw;
            }
        }