コード例 #1
0
        public Message(NewMessageNotification message)
        {
            Id             = message.fields.args[0]._id;
            RoomId         = message.fields.args[0].rid;
            MessageContent = message.fields.args[0].msg;
            Timestamp      = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            double seconds = double.Parse(message.fields.args[0].ts.date);

            Timestamp = Timestamp.AddMilliseconds(seconds).ToLocalTime();
            User      = new User {
                Id = message.fields.args[0].u._id, Username = message.fields.args[0].u.username
            };
            if (message.fields.args[0].file != null)
            {
                File = new MessageFile(message.fields.args[0].file);
            }
            if (message.fields.args[0].attachments != null)
            {
                Attachments = new Attachment[message.fields.args[0].attachments.Length];
                for (int i = 0; i < Attachments.Length; i++)
                {
                    Attachments[i] = new Attachment(message.fields.args[0].attachments[i]);
                }
            }
        }
コード例 #2
0
        private async void NewMessageHandler(NewMessageNotification obj)
        {
            var message = new Message(obj);

            if (message.Attachments != null && message.Attachments.Length != 0 && message.Attachments[0].IsImage)
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    message.Attachments[0].ImagePreview = await message.Attachments[0].Base64ToBitmapImage(message.Attachments[0].ImagePreviewString);
                    message.Attachments[0].ImagePreview = await rocketChatRest.GetImage(message.Attachments[0].ImageUrl);
                });
            }
            message.User = Users.FirstOrDefault(x => x.Id == message.User.Id);
            if (SelectedChannel != null && SelectedChannel.Id == obj.fields.args[0].rid)
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Messages.Add(message);
                });
            }
            else
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (Channels.Any(x => x.Id == message.RoomId))
                    {
                        Channels.FirstOrDefault(x => x.Id == message.RoomId).HasUnreadedMessages = true;
                        Channels.FirstOrDefault(x => x.Id == message.RoomId).ChannelFontWeight   = FontWeights.Bold;
                        if (message.Attachments != null && message.Attachments[0].IsImage)
                        {
                            notificationService.ShowNewMessageToastNotification(message, Channels.FirstOrDefault(x => x.Id == message.RoomId), true);
                        }
                        else
                        {
                            notificationService.ShowNewMessageToastNotification(message, Channels.FirstOrDefault(x => x.Id == message.RoomId));
                        }
                    }
                    if (Discussions.Any(x => x.Id == message.RoomId))
                    {
                        Discussions.FirstOrDefault(x => x.Id == message.RoomId).HasUnreadedMessages = true;
                        Discussions.FirstOrDefault(x => x.Id == message.RoomId).ChannelFontWeight   = FontWeights.Bold;
                        if (obj.fields.args[0].t == null || obj.fields.args[0].t != "discussion-created")
                        {
                            if (message.Attachments != null && message.Attachments[0].IsImage)
                            {
                                notificationService.ShowNewMessageToastNotification(message, Discussions.FirstOrDefault(x => x.Id == message.RoomId), true);
                            }
                            else
                            {
                                notificationService.ShowNewMessageToastNotification(message, Discussions.FirstOrDefault(x => x.Id == message.RoomId));
                            }
                        }
                    }
                    if (DirectConversations.Any(x => x.Id == message.RoomId))
                    {
                        DirectConversations.FirstOrDefault(x => x.Id == message.RoomId).HasUnreadedMessages = true;
                        DirectConversations.FirstOrDefault(x => x.Id == message.RoomId).ChannelFontWeight   = FontWeights.Bold;
                        if (message.Attachments != null && message.Attachments[0].IsImage)
                        {
                            notificationService.ShowNewMessageToastNotification(message, DirectConversations.FirstOrDefault(x => x.Id == message.RoomId), true);
                        }
                        else
                        {
                            notificationService.ShowNewMessageToastNotification(message, DirectConversations.FirstOrDefault(x => x.Id == message.RoomId));
                        }
                    }
                    if (PrivateGroups.Any(x => x.Id == message.RoomId))
                    {
                        PrivateGroups.FirstOrDefault(x => x.Id == message.RoomId).HasUnreadedMessages = true;
                        PrivateGroups.FirstOrDefault(x => x.Id == message.RoomId).ChannelFontWeight   = FontWeights.Bold;
                    }
                });
            }
        }