Skip to content

Commit 45759b4

Browse files
Merge branch 'master' into fix-positioning
2 parents 5f557e2 + f94748c commit 45759b4

File tree

6 files changed

+59
-7
lines changed

6 files changed

+59
-7
lines changed

images/notifications/commit.png

5.57 KB
Loading

images/notifications/gitify.png

6.54 KB
Loading

images/notifications/issue.png

5.97 KB
Loading
5.71 KB
Loading

src/js/__tests__/stores/sound-notification.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,44 @@ describe('Tests for SoundNotificationStore', function () {
7171
}];
7272

7373
SoundNotificationStore.onIsNewNotification(payload);
74-
7574
expect(SoundNotificationStore.showNotification).toHaveBeenCalled();
7675

7776
});
7877

78+
it('Should test notifications type/icon', function () {
79+
80+
spyOn(SoundNotificationStore, 'newNotification');
81+
82+
var latestNotification = {
83+
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'Commit'
84+
};
85+
SoundNotificationStore.showNotification(1, latestNotification);
86+
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();
87+
88+
var latestNotification = {
89+
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'Issue'
90+
};
91+
SoundNotificationStore.showNotification(1, latestNotification);
92+
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();
93+
94+
var latestNotification = {
95+
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'PullRequest'
96+
};
97+
SoundNotificationStore.showNotification(1, latestNotification);
98+
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();
99+
100+
var latestNotification = {
101+
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'AnotherType'
102+
};
103+
SoundNotificationStore.showNotification(1, latestNotification);
104+
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();
105+
106+
var latestNotification = {};
107+
SoundNotificationStore.showNotification(2, latestNotification);
108+
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();
109+
110+
});
111+
79112
it('Should reopen gitify when a notification is clicked', function () {
80113
var nativeNotification = SoundNotificationStore.newNotification('Test', 'Hello, world!');
81114

src/js/stores/sound-notification.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,42 @@ var SoundNotificationStore = Reflux.createStore({
1818
audio.play();
1919
},
2020

21-
newNotification: function (title, body) {
21+
newNotification: function (title, body, icon) {
2222
var nativeNotification = new Notification(title, {
23-
body: body
23+
body: body,
24+
icon: icon || false
2425
});
2526
nativeNotification.onclick = function () {
2627
ipcRenderer.send('reopen-window');
2728
};
2829
return nativeNotification;
2930
},
3031

31-
showNotification: function (countNew, response, latestNotification) {
32+
showNotification: function (countNew, latestNotification) {
3233
var title = (countNew == 1 ?
3334
'Gitify - ' + latestNotification.full_name :
3435
'Gitify');
3536
var body = (countNew == 1 ?
3637
latestNotification.subject :
3738
'You\'ve got ' + countNew + ' notifications.');
38-
this.newNotification(title, body);
39+
40+
var icon;
41+
if (countNew == 1) {
42+
switch (latestNotification.type) {
43+
case 'Issue':
44+
icon = 'images/notifications/issue.png';
45+
break;
46+
case 'Commit':
47+
icon = 'images/notifications/commit.png';
48+
break;
49+
case 'PullRequest':
50+
icon = 'images/notifications/pull-request.png';
51+
break;
52+
default:
53+
icon = 'images/notifications/gitify.png';
54+
}
55+
}
56+
this.newNotification(title, body, icon);
3957
},
4058

4159
onIsNewNotification: function (response) {
@@ -56,9 +74,10 @@ var SoundNotificationStore = Reflux.createStore({
5674
self.playSound();
5775
}
5876
if (showNotifications) {
59-
this.showNotification(newNotifications.length, response, {
77+
this.showNotification(newNotifications.length, {
6078
full_name: newNotifications[0].repository.full_name,
61-
subject: newNotifications[0].subject.title
79+
subject: newNotifications[0].subject.title,
80+
type: newNotifications[0].subject.type
6281
});
6382
}
6483
}

0 commit comments

Comments
 (0)