コード例 #1
0
        public Task<IEnumerable<Message>> GetRoomMessagesAsync(string roomId, int limit = 50, string beforeId = null, string afterId = null, int skip = 0)
        {
            var suprememoocow = new User
            {
                Id = "53307831c3599d1de448e19a",
                Username = "******",
                DisplayName = "Andrew Newdigate",
                Url = "/suprememoocow,",
                SmallAvatarUrl = "https://avatars.githubusercontent.com/u/594566?",
                MediumAvatarUrl = "https://avatars.githubusercontent.com/u/594566?"
            };

            var messages = new List<Message>
            {
                new Message
                {
                    Id = "1",
                    User = suprememoocow,
                    Text = "first message"
                },
                new Message
                {
                    Id = "2",
                    User = suprememoocow,
                    Text = "second message"
                }
            };

            return Task.FromResult<IEnumerable<Message>>(messages);
        }
コード例 #2
0
 public Task<User> GetCurrentUserAsync()
 {
     var user = new User
     {
         Id = "53307734c3599d1de448e192",
         Username = "******",
         DisplayName = "Mauro Pompilio",
         Url = "/malditogeek",
         SmallAvatarUrl = "https://avatars.githubusercontent.com/u/14751?",
         MediumAvatarUrl = "https://avatars.githubusercontent.com/u/14751?"
     };
     return Task.FromResult(user);
 }
コード例 #3
0
        public void Message_Should_HaveAuthor()
        {
            // Arrange
            var user = new User
            {
                Id = "abcdef",
                Username = "******"
            };
            var message = new Message
            {
                User = user
            };
            var messageViewModel = new MessageViewModel(message);

            // Act

            // Assert
            Assert.NotNull(messageViewModel.User);
            Assert.Same(user, messageViewModel.User);
        }
コード例 #4
0
        public MainViewModel(IGitterApiService gitterApiService,
            ILocalNotificationService localNotificationService,
            IApplicationStorageService applicationStorageService,
            IProgressIndicatorService progressIndicatorService,
            IPasswordStorageService passwordStorageService,
            IEventService eventService,
            ITelemetryService telemetryService,
            INavigationService navigationService)
        {
            // Services
            _gitterApiService = gitterApiService;
            _localNotificationService = localNotificationService;
            _applicationStorageService = applicationStorageService;
            _progressIndicatorService = progressIndicatorService;
            _passwordStorageService = passwordStorageService;
            _eventService = eventService;
            _navigationService = navigationService;
            _telemetryService = telemetryService;

            // Commands
            SelectRoomCommand = new RelayCommand<IRoomViewModel>(SelectRoom);
            ChatWithUsCommand = new RelayCommand(ChatWithUs, CanChatWithUs);
            GoToAboutPageCommand = new RelayCommand(GoToAboutPage);
            RefreshCommand = new RelayCommand(Refresh, () => !IsRefreshing);
            ToggleSearchCommand = new RelayCommand<bool>(ToggleSearch);

            // Properties
            CurrentDateTime = DateTime.Now;

            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.

                CurrentUser = new User
                {
                    Id = "53307734c3599d1de448e192",
                    Username = "******",
                    DisplayName = "Mauro Pompilio",
                    Url = "/malditogeek",
                    SmallAvatarUrl = "https://avatars.githubusercontent.com/u/14751?",
                    MediumAvatarUrl = "https://avatars.githubusercontent.com/u/14751?"
                };

                var suprememoocow = new User
                {
                    Id = "53307831c3599d1de448e19a",
                    Username = "******",
                    DisplayName = "Andrew Newdigate",
                    Url = "/suprememoocow,",
                    SmallAvatarUrl = "https://avatars.githubusercontent.com/u/594566?",
                    MediumAvatarUrl = "https://avatars.githubusercontent.com/u/594566?"
                };

                Rooms.Add(new RoomViewModel(new Room
                {
                    Id = "53307860c3599d1de448e19d",
                    Name = "Andrew Newdigate",
                    Topic = string.Empty,
                    OneToOne = true,
                    Users = new[] { suprememoocow },
                    UnreadItems = 52,
                    UnreadMentions = 0,
                    DisabledNotifications = false,
                    Type = "ONETOONE"
                }, gitterApiService, localNotificationService, progressIndicatorService, eventService, telemetryService, this));

                Rooms.Add(new RoomViewModel(new Room
                {
                    Id = "5330777dc3599d1de448e194",
                    Name = "gitterHQ",
                    Topic = "Gitter",
                    Url = "gitterHQ",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 0,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 22, 28),
                    DisabledNotifications = false,
                    Type = "ORG",
                    Version = 1
                }, gitterApiService, localNotificationService, progressIndicatorService, eventService, telemetryService, this));

                Rooms.Add(new RoomViewModel(new Room
                {
                    Id = "5330780dc3599d1de448e198",
                    Name = "gitterHQ/devops",
                    Topic = string.Empty,
                    Url = "gitterHQ/devops",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 3,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 23, 10),
                    DisabledNotifications = false,
                    Type = "ORG_CHANNEL",
                    Version = 1
                }, gitterApiService, localNotificationService, progressIndicatorService, eventService, telemetryService, this));

                Rooms.Add(new RoomViewModel(new Room
                {
                    Id = "53307793c3599d1de448e196",
                    Name = "malditogeek/vmux",
                    Topic = "VMUX - Plugin-free video calls in your browser using WebRTC",
                    Url = "gitterHQ/devops",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 42,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 21, 08),
                    DisabledNotifications = false,
                    Type = "REPO",
                    Version = 1
                }, gitterApiService, localNotificationService, progressIndicatorService, eventService, telemetryService, this));

                SelectedRoom = Rooms.FirstOrDefault();

                foreach (var room in Rooms)
                    SearchedRooms.Add(room);
            }
            else
            {
                // Code runs "for real"

                // Events
                _eventService.ReadRoom
                    .Subscribe(room =>
                    {
                        HtmlToXaml.HtmlToXaml.RoomName = room.Room.Name;
                    });

                HtmlToXaml.HtmlToXaml.ImageTapped += (sender, args) =>
                {
                    var image = sender as Image;
                    var bitmapImage = image.Source as BitmapImage;

                    ViewModelLocator.FullImage.Source = bitmapImage.UriSource.OriginalString;
                    _navigationService.NavigateTo("FullImage");
                };

                // Retrieve access token to use in the app
                string token = _passwordStorageService.Retrieve("token");
                _gitterApiService.SetToken(token);

                // Add event that will update READ new messages
                _currentSelectedRoomUnreadMessages = _eventService.NotifyUnreadMessages
                    .Subscribe(async unreadMessages => await NotifyReadMessages(unreadMessages));
            }
        }
コード例 #5
0
        private async void ViewProfile(User user)
        {
#if WINDOWS_PHONE_APP
            await Windows.System.Launcher.LaunchUriAsync(new Uri(user.GitHubUrl));
#endif
        }
コード例 #6
0
 private void RespondTo(User user)
 {
     TextMessage += $"@{user.Username} ";
 }
コード例 #7
0
        public RoomViewModel(Room room,
            IGitterApiService gitterApiService,
            ILocalNotificationService localNotificationService,
            IProgressIndicatorService progressIndicatorService,
            IEventService eventService,
            ITelemetryService telemetryService,
            IMainViewModel mainViewModel)
        {
            // Properties
            Room = room;

            // View Models
            _mainViewModel = mainViewModel;

            // Commands
            SendMessageCommand = new RelayCommand(SendMessage, CanSendMessage);
            SendMessageWithParamCommand = new RelayCommand<bool>(SendMessageWithParam);
            RemoveMessageCommand = new RelayCommand<IMessageViewModel>(RemoveMessage, CanRemoveMessage);
            CopyMessageCommand = new RelayCommand<IMessageViewModel>(CopyMessage);
            RespondToCommand = new RelayCommand<User>(RespondTo);
            ViewProfileCommand = new RelayCommand<User>(ViewProfile);
            TalkCommand = new RelayCommand(Talk);
            RefreshCommand = new RelayCommand(Refresh);

            // Inject Services
            _gitterApiService = gitterApiService;
            _localNotificationService = localNotificationService;
            _progressIndicatorService = progressIndicatorService;
            _eventService = eventService;
            _telemetryService = telemetryService;


            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.

                var malditogeek = new User
                {
                    Id = "53307734c3599d1de448e192",
                    Username = "******",
                    DisplayName = "Mauro Pompilio",
                    Url = "/malditogeek",
                    SmallAvatarUrl = "https://avatars.githubusercontent.com/u/14751?",
                    MediumAvatarUrl = "https://avatars.githubusercontent.com/u/14751?"
                };

                var suprememoocow = new User
                {
                    Id = "53307831c3599d1de448e19a",
                    Username = "******",
                    DisplayName = "Andrew Newdigate",
                    Url = "/suprememoocow,",
                    SmallAvatarUrl = "https://avatars.githubusercontent.com/u/594566?",
                    MediumAvatarUrl = "https://avatars.githubusercontent.com/u/594566?"
                };


                Messages = new MessagesIncrementalLoadingCollection("123456", gitterApiService, eventService, mainViewModel)
                {
                    new MessageViewModel(new Message
                    {
                        Id = "53316dc47bfc1a000000000f",
                        Text = "Hi @suprememoocow !",
                        Html =
                            "Hi <span data-link-type=\"mention\" data-screen-name=\"suprememoocow\" class=\"mention\">@suprememoocow</span> !",
                        SentDate = new DateTime(2014, 3, 25, 11, 51, 32),
                        EditedDate = null,
                        User = malditogeek,
                        UnreadByCurrent = false,
                        ReadCount = 0,
                        Urls = new List<MessageUrl>(),
                        Mentions = new List<Mention>
                        {
                            new Mention
                            {
                                ScreenName = "suprememoocow",
                                UserId = "53307831c3599d1de448e19a"
                            }
                        },
                        Issues = new List<Issue>(),
                        Version = 1
                    }),
                    new MessageViewModel(new Message
                    {
                        Id = "53316ec37bfc1a0000000011",
                        Text = "I've been working on #11, it'll be ready to ship soon",
                        Html =
                            "I&#39;ve been working on <span data-link-type=\"issue\" data-issue=\"11\" class=\"issue\">#11</span>, it&#39;ll be ready to ship soon",
                        SentDate = new DateTime(2014, 3, 25, 11, 55, 47),
                        EditedDate = null,
                        User = malditogeek,
                        UnreadByCurrent = false,
                        ReadCount = 0,
                        Urls = new List<MessageUrl>(),
                        Mentions = new List<Mention>(),
                        Issues = new List<Issue>
                        {
                            new Issue {Number = "11"}
                        },
                        Version = 1
                    }),
                    new MessageViewModel(new Message
                    {
                        Id = "53316ec37bfc1a0000000012",
                        Text = "This is a test message",
                        Html = "This is a test message",
                        SentDate = new DateTime(2014, 3, 25, 11, 55, 47),
                        EditedDate = null,
                        User = suprememoocow,
                        UnreadByCurrent = false,
                        ReadCount = 0,
                        Urls = new List<MessageUrl>(),
                        Mentions = new List<Mention>(),
                        Issues = new List<Issue>(),
                        Version = 1
                    }),
                    new MessageViewModel(new Message
                    {
                        Id = "53316ec37bfc1a0000000013",
                        Text = "Another long long ............... message",
                        Html = "Another long long ............... message",
                        SentDate = new DateTime(2014, 3, 25, 11, 55, 47),
                        EditedDate = null,
                        User = malditogeek,
                        UnreadByCurrent = false,
                        ReadCount = 0,
                        Urls = new List<MessageUrl>(),
                        Mentions = new List<Mention>(),
                        Issues = new List<Issue>(),
                        Version = 1
                    })
                };
            }
            else
            {
                // Code runs "for real"

                Messages = new MessagesIncrementalLoadingCollection(Room.Id, gitterApiService, eventService, mainViewModel);
                OpenRealtimeStream();
            }

            // Update count of unread messages
            UnreadMessagesCount = Room.UnreadItems;
        }
コード例 #8
0
        public Task<IEnumerable<Room>> GetRoomsAsync()
        {
            var suprememoocow = new User
            {
                Id = "53307831c3599d1de448e19a",
                Username = "******",
                DisplayName = "Andrew Newdigate",
                Url = "/suprememoocow,",
                SmallAvatarUrl = "https://avatars.githubusercontent.com/u/594566?",
                MediumAvatarUrl = "https://avatars.githubusercontent.com/u/594566?"
            };

            IEnumerable<Room> rooms = new List<Room>
            {
                new Room
                {
                    Id = "53307860c3599d1de448e19d",
                    Name = "Andrew Newdigate",
                    Topic = string.Empty,
                    OneToOne = true,
                    Users = new[] { suprememoocow },
                    UnreadItems = 52,
                    UnreadMentions = 0,
                    DisabledNotifications = false,
                    Type = "ONETOONE"
                },
                new Room
                {
                    Id = "5330777dc3599d1de448e194",
                    Name = "gitterHQ",
                    Topic = "Gitter",
                    Url = "gitterHQ",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 0,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 22, 28),
                    DisabledNotifications = false,
                    Type = "ORG",
                    Version = 1
                },
                new Room
                {
                    Id = "5330780dc3599d1de448e198",
                    Name = "gitterHQ/devops",
                    Topic = string.Empty,
                    Url = "gitterHQ/devops",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 3,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 23, 10),
                    DisabledNotifications = false,
                    Type = "ORG_CHANNEL",
                    Version = 1
                },
                new Room
                {
                    Id = "53307793c3599d1de448e196",
                    Name = "malditogeek/vmux",
                    Topic = "VMUX - Plugin-free video calls in your browser using WebRTC",
                    Url = "gitterHQ/devops",
                    OneToOne = false,
                    UserCount = 2,
                    UnreadItems = 42,
                    UnreadMentions = 0,
                    LastAccessTime = new DateTime(2014, 3, 24, 18, 21, 08),
                    DisabledNotifications = false,
                    Type = "REPO",
                    Version = 1
                }
            };
            return Task.FromResult(rooms);
        }