Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription audio notification #5366

Merged
merged 26 commits into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63a1901
Add audio notification choices to subscriptions
marceloschmidt Dec 27, 2016
6def9c7
Add user preferences for default new message sound;
marceloschmidt Dec 27, 2016
6eae556
Subscription preference first, then user preferences, then default
marceloschmidt Dec 27, 2016
736e520
Custom Sounds admin sections
marceloschmidt Dec 27, 2016
8219f13
Admin section for managing sounds
marceloschmidt Dec 28, 2016
06fa160
Add default sounds
marceloschmidt Dec 29, 2016
b3094dc
Remove chime as it is default everytime
marceloschmidt Dec 29, 2016
a58f364
Use audio#id to play audios.
marceloschmidt Dec 29, 2016
4eec964
New room sound preferences
marceloschmidt Dec 29, 2016
28a96ab
Change name of settings; add migration
marceloschmidt Dec 29, 2016
8c04163
Merge branch 'develop' into subscription-audio-notification
marceloschmidt Dec 29, 2016
19d2461
Revert migration 77
marceloschmidt Dec 29, 2016
fb3ff0d
Remove unused variable
marceloschmidt Dec 29, 2016
838b364
Fix less eslint
marceloschmidt Dec 29, 2016
155861b
Fix sound notification playing current opened room sound
marceloschmidt Jan 25, 2017
5320944
Merge branch 'develop'
marceloschmidt Jan 26, 2017
aba3043
Corrected migration number
marceloschmidt Jan 26, 2017
bb7d360
Merge branch 'develop' into subscription-audio-notification
marceloschmidt Jan 31, 2017
8249b96
Merge branch 'develop' into subscription-audio-notification
marceloschmidt Feb 6, 2017
2adfbf2
Fix codacy issues
marceloschmidt Feb 6, 2017
880292d
Merge branch 'develop' into subscription-audio-notification
marceloschmidt Feb 7, 2017
03ad5bc
Merge branch 'develop' into subscription-audio-notification
marceloschmidt Feb 7, 2017
dae3d5c
Fix tabbar of admin sounds
rodrigok Feb 7, 2017
4d6850c
Filter admin sound input to audio/mp3 only
rodrigok Feb 7, 2017
120d47e
Remove uncessary brackets
rodrigok Feb 8, 2017
e1c4214
Remove all uncessary `isSetNotNull`
rodrigok Feb 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rocketchat:channel-settings-mail-messages
rocketchat:colors
rocketchat:crowd
rocketchat:custom-oauth
rocketchat:custom-sounds
rocketchat:emoji
rocketchat:emoji-custom
rocketchat:emoji-emojione
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand Down
4 changes: 2 additions & 2 deletions client/notifications/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Meteor.startup(function() {
if (RocketChat.Layout.isEmbedded()) {
if (!hasFocus && messageIsInOpenedRoom) {
// Play a sound and show a notification.
KonchatNotification.newMessage();
KonchatNotification.newMessage(notification.payload.rid);
KonchatNotification.showDesktop(notification);
}
} else if (!(hasFocus && messageIsInOpenedRoom)) {
// Play a sound and show a notification.
KonchatNotification.newMessage();
KonchatNotification.newMessage(notification.payload.rid);
KonchatNotification.showDesktop(notification);
}
});
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-custom-sounds/admin/adminSoundEdit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="adminSoundEdit">
<div class="content">
<div class="sound-view">
{{> soundEdit .}}
</div>
</div>
</template>
7 changes: 7 additions & 0 deletions packages/rocketchat-custom-sounds/admin/adminSoundInfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="adminSoundInfo">
<div class="content">
<div class="sound-view">
{{> soundInfo .}}
</div>
</div>
</template>
48 changes: 48 additions & 0 deletions packages/rocketchat-custom-sounds/admin/adminSounds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template name="adminSounds">
<div class="main-content-flex">
<section class="page-container page-list flex-tab-main-content">
<header class="fixed-title">
{{> burger}}
<h2>
<span class="room-title">{{_ "Custom_Sounds"}}</span>
</h2>
</header>
<div class="content">
{{#requiresPermission 'manage-sounds'}}
<form class="search-form" role="form">
<div class="input-line search">
<input type="text" id="sound-filter" placeholder="{{_ "Search"}}" dir="auto">
<i class="icon-search"></i>
{{#unless isReady}}<i class="icon-spin"></i>{{/unless}}
</div>
</form>
<div class="results">
{{{_ "Showing_results" customsounds.length}}}
</div>
<div class="list">
<table>
<thead>
<tr>
<th width="100%">{{_ "Name"}}</th>
</tr>
</thead>
<tbody>
{{#each customsounds}}
<tr class="sound-info row-link">
<td>{{name}}&nbsp;<i class="icon-play-circled"></i></td>
</tr>
{{/each}}
</tbody>
</table>
{{#if hasMore}}
<button class="button secondary load-more {{isLoading}}">{{_ "Load_more"}}</button>
{{/if}}
</div>
{{/requiresPermission}}
</div>
</section>
{{#with flexData}}
{{> flexTabBar}}
{{/with}}
</div>
</template>
132 changes: 132 additions & 0 deletions packages/rocketchat-custom-sounds/admin/adminSounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* globals isSetNotNull, RocketChatTabBar */
Template.adminSounds.helpers({
isReady() {
if (isSetNotNull(() => Template.instance().ready)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for use this isSetNotNull?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CTRL+C, CTRL+V from adminEmoji :( should I remove it?

return Template.instance().ready.get();
}
return undefined;
},
customsounds() {
return Template.instance().customsounds();
},
isLoading() {
if (isSetNotNull(() => Template.instance().ready)) {
if (!Template.instance().ready.get()) {
return 'btn-loading';
}
}
},
hasMore() {
if (isSetNotNull(() => Template.instance().limit)) {
if (typeof Template.instance().customsounds === 'function') {
return Template.instance().limit.get() === Template.instance().customsounds().length;
}
}
return false;
},
flexData() {
return {
tabBar: Template.instance().tabBar,
data: Template.instance().tabBarData.get()
};
}
});

Template.adminSounds.onCreated(function() {
const instance = this;
this.limit = new ReactiveVar(50);
this.filter = new ReactiveVar('');
this.ready = new ReactiveVar(false);

this.tabBar = new RocketChatTabBar();
this.tabBar.showGroup(FlowRouter.current().route.name);
this.tabBarData = new ReactiveVar();

RocketChat.TabBar.addButton({
groups: ['custom-sounds', 'custom-sounds-selected'],
id: 'add-sound',
i18nTitle: 'Custom_Sound_Add',
icon: 'icon-plus',
template: 'adminSoundEdit',
openClick(/*e, t*/) {
instance.tabBarData.set();
return true;
},
order: 1
});

RocketChat.TabBar.addButton({
groups: ['custom-sounds-selected'],
id: 'admin-sound-info',
i18nTitle: 'Custom_Sound_Info',
icon: 'icon-cog',
template: 'adminSoundInfo',
order: 2
});

this.autorun(function() {
const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0;
const subscription = instance.subscribe('customSounds', '', limit);
instance.ready.set(subscription.ready());
});

this.customsounds = function() {
const filter = (isSetNotNull(() => instance.filter))? _.trim(instance.filter.get()) : '';

let query = {};

if (filter) {
const filterReg = new RegExp(s.escapeRegExp(filter), 'i');
query = { name: filterReg };
}

const limit = (isSetNotNull(() => instance.limit))? instance.limit.get() : 0;

return RocketChat.models.CustomSounds.find(query, { limit: limit, sort: { name: 1 }}).fetch();
};
});

Template.adminSounds.onRendered(() =>
Tracker.afterFlush(function() {
SideNav.setFlex('adminFlex');
SideNav.openFlex();
})
);

Template.adminSounds.events({
['keydown #sound-filter'](e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the selector is between brackets?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise above

//stop enter key
if (e.which === 13) {
e.stopPropagation();
e.preventDefault();
}
},

['keyup #sound-filter'](e, t) {
e.stopPropagation();
e.preventDefault();
t.filter.set(e.currentTarget.value);
},

['click .sound-info'](e, instance) {
e.preventDefault();
instance.tabBarData.set(RocketChat.models.CustomSounds.findOne({_id: this._id}));
instance.tabBar.showGroup('custom-sounds-selected');
instance.tabBar.open('admin-sound-info');
},

['click .load-more'](e, t) {
e.preventDefault();
e.stopPropagation();
t.limit.set(t.limit.get() + 50);
},

['click .icon-play-circled'](e) {
e.preventDefault();
e.stopPropagation();
const $audio = $('audio#' + this._id);
if ($audio && $audio[0] && $audio[0].play) {
$audio[0].play();
}
}
});
9 changes: 9 additions & 0 deletions packages/rocketchat-custom-sounds/admin/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FlowRouter.route('/admin/custom-sounds', {
name: 'custom-sounds',
subscriptions(/*params, queryParams*/) {
this.register('customSounds', Meteor.subscribe('customSounds'));
},
action(/*params*/) {
BlazeLayout.render('main', {center: 'adminSounds'});
}
});
25 changes: 25 additions & 0 deletions packages/rocketchat-custom-sounds/admin/soundEdit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template name="soundEdit">
{{#requiresPermission 'manage-sounds'}}
<div class="about clearfix">
<form class="edit-form" autocomplete="off">
{{#if sound}}
<h3>{{sound.name}}</h3>
{{else}}
<h3>{{_ "Custom_Sound_Add"}}</h3>
{{/if}}
<div class="input-line">
<label for="name">{{_ "Name"}}</label>
<input type="text" id="name" autocomplete="off" value="{{sound.name}}">
</div>
<div class="input-line">
<label for="image">{{_ "Sound_File_mp3"}}</label>
<input id="image" type="file" accept="audio/mp3"/>
</div>
<nav>
<button class='button button-block cancel' type="button"><span>{{_ "Cancel"}}</span></button>
<button class='button button-block primary save'><span>{{_ "Save"}}</span></button>
</nav>
</form>
</div>
{{/requiresPermission}}
</template>
Loading