コード例 #1
0
ファイル: MainTests.cs プロジェクト: nmetulev/Modern-Gitter
 public RoomViewModel CreateRoomViewModel(Room room)
 {
     return new RoomViewModel(room,
         _gitterApiService,
         _localNotificationService,
         _progressIndicatorService,
         _eventService,
         _telemetryService,
         _mainViewModel);
 }
        private async Task CreateNotificationAsync(Room room)
        {
            // Retrieve id of messages that contains a mention
            string userId = _applicationStorageService.Retrieve(StorageConstants.UserId) as string;
            var unreadItems = await _gitterApiService.RetrieveUnreadChatMessagesAsync(userId, room.Id);

            // Retrieve each message that contains mentions
            foreach (string mention in unreadItems.Mentions)
            {
                var message = await _gitterApiService.GetSingleRoomMessageAsync(room.Id, mention);

                string id = $"{room.Name}_mention_{message.Id}";
                if (!_applicationStorageService.Exists(id))
                {
                    // Show notifications (toast notifications)
                    string notificationContent = $"{message.User.Username} mentioned you";
                    _localNotificationService.SendNotification(room.Name, notificationContent, id, room.Name);
                    _applicationStorageService.Save(id, room.UnreadMentions);
                }
            }
        }
コード例 #3
0
        private async Task CreateNotificationAsync(Room room)
        {
            string id = room.Name;

            // Detect if there is no new notification to launch (no unread messages)
            if (_applicationStorageService.Exists(id))
            {
                // Reset notification id for the future
                if (room.UnreadItems == 0)
                    _applicationStorageService.Remove(id);

                return;
            }

            if (room.UnreadItems > 0)
            {
                // Show notifications (toast notifications)
                string notificationContent = $"You have {room.UnreadItems} unread messages";
                _localNotificationService.SendNotification(room.Name, notificationContent, id, room.Name);
                _applicationStorageService.Save(id, room.UnreadItems);
            }
        }
コード例 #4
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;
        }
コード例 #5
0
 protected abstract Task CreateNotificationAsync(Room room);
コード例 #6
0
        public Task<Room> JoinRoomAsync(string roomName)
        {
            JoinedRooms++;
            var room = new Room
            {
                Name = roomName
            };

            return Task.FromResult(room);
        }
コード例 #7
0
ファイル: MainTests.cs プロジェクト: nmetulev/Modern-Gitter
        public void SelectingRoomForTheFirstTime_Should_LoadIt()
        {
            // Arrange
            TestInitialize();

            var room = new Room
            {
                Id = "123456",
                Name = "Room",
                UnreadItems = 14
            };

            var roomViewModel = CreateRoomViewModel(room);

            // Assert (before)
            Assert.False(roomViewModel.IsLoaded);

            // Act
            _mainViewModel.SelectRoomCommand.Execute(roomViewModel);

            // Assert (after)
            Assert.Same(roomViewModel, _mainViewModel.SelectedRoom);
            Assert.Equal(1, _telemetryService.EventsTracked);
            Assert.True(roomViewModel.IsLoaded);
        }
コード例 #8
0
ファイル: MainTests.cs プロジェクト: nmetulev/Modern-Gitter
        public async Task ChatWithUsOnAlreadyJoinedRoom_Should_SelectRoom()
        {
            // Arrange
            TestInitialize();
            _mainViewModel.CurrentUser = await _gitterApiService.GetCurrentUserAsync();

            var room = new Room
            {
                Id = "1",
                Name = "Odonno/Modern-Gitter"
            };
            var roomViewModel = CreateRoomViewModel(room);
            _mainViewModel.Rooms.Add(roomViewModel);

            // Act
            _mainViewModel.ChatWithUsCommand.Execute(null);
            await Task.Delay(100);

            // Assert
            Assert.Equal(0, _gitterApiService.JoinedRooms);
            Assert.Equal(2, _telemetryService.EventsTracked);
            Assert.NotNull(_mainViewModel.SelectedRoom);
            Assert.Equal("Odonno/Modern-Gitter", _mainViewModel.SelectedRoom.Room.Name);
        }
コード例 #9
0
ファイル: MainTests.cs プロジェクト: nmetulev/Modern-Gitter
        public void SelectingRoomAndThenUnselectIt_Should_UnselectRoom()
        {
            // Arrange
            TestInitialize();

            var room = new Room
            {
                Id = "123456",
                Name = "Room",
                UnreadItems = 14
            };
            var roomViewModel = CreateRoomViewModel(room);

            _mainViewModel.SelectRoomCommand.Execute(roomViewModel);

            // Act
            _mainViewModel.SelectRoomCommand.Execute(null);

            // Assert
            Assert.Null(_mainViewModel.SelectedRoom);
            Assert.Equal(1, _telemetryService.EventsTracked);
        }