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

Add user settings for sound + disabling chat #261

Merged
merged 3 commits into from
Aug 6, 2018
Merged
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions app/models/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Search
module FilterChats
def execute
super.tap { @results.posts.reject! { |p| p.archetype == Archetype.chat } }
end
end
prepend FilterChats
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ class ::User
.where.not(id: post.user_id)
}

register_custom_field_type 'babble_disabled', :boolean
register_custom_field_type 'babble_sound', :boolean

module HideChatNotifications
def unread_notifications
@unread_notifications ||= begin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default Ember.Component.extend({
actions: {
toggleChat() {
this.user.save(['custom_fields'])
}
}
})

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{babble-user-preferences user=model}}
8 changes: 5 additions & 3 deletions assets/javascripts/discourse/lib/babble.js.es6
Original file line number Diff line number Diff line change
@@ -17,7 +17,9 @@ export default Ember.Object.create({
summary: {},

disabled() {
return !Discourse.User.current() || !Discourse.SiteSettings.babble_enabled
return !User.current() ||
User.currentProp('custom_fields.babble_disabled') ||
!Discourse.SiteSettings.babble_enabled
},

bindById(component, topicId) {
@@ -313,13 +315,13 @@ export default Ember.Object.create({
},

handleTyping(topic, data) {
if (User.current() && data.id == User.current().id) { return }
if (data.id == User.currentProp('id')) { return }
topic.typing[data.username] = { user: data, lastTyped: moment() }
rerender(topic)
},

handleOnline(topic, data) {
if (User.current() && data.id == User.current().id) { return }
if (data.id == User.currentProp('id')) { return }
topic.online[data.username] = { user: data, lastSeen: moment() }
rerender(topic)
},
5 changes: 3 additions & 2 deletions assets/javascripts/discourse/lib/chat-element-utils.js.es6
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import autosize from 'discourse/lib/autosize'
import lastVisibleElement from '../lib/last-visible-element'
import { syncWithPostStream } from '../lib/chat-topic-utils'
import { rerender } from '../lib/chat-component-utils'
import User from 'discourse/models/user'
import Babble from '../lib/babble'

let visibleInWindow = function(selector) {
@@ -116,7 +117,7 @@ let setupComposer = function(topic, opts = { emojis: true, mentions: true }) {
term: term,
topicId: topic.id,
includeGroups: true,
exclude: [Discourse.User.current().get('username')]
exclude: [User.currentProp('username')]
})
},

@@ -175,7 +176,7 @@ let setupChannelAutocomplete = function(opts = {}) {
}

let playNotification = function() {
if (!Discourse.SiteSettings.babble_notification_sound) { return }
if (!User.currentProp('custom_fields.babble_sound')) { return }
const $audio = $('audio#babble-notification')[0]
if (!$audio || !$audio.play) { return }
$audio.play()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<label class="control-label">{{i18n 'babble.preferences.title'}}</label>
{{inline-edit-checkbox action="toggleChat" labelKey="babble.preferences.babble_disabled" checked=user.custom_fields.babble_disabled}}
{{inline-edit-checkbox action="toggleChat" labelKey="babble.preferences.babble_sound" checked=user.custom_fields.babble_sound}}

This file was deleted.

4 changes: 4 additions & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
en:
js:
babble:
preferences:
title: Babble
babble_disabled: Disable Babble chat completely
babble_sound: Enable browser sound for new chat notifications
position_left: Left
position_right: Right
placeholder: "Say something..."
4 changes: 4 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ def babble_require(path)
babble_require 'models/guardian'
babble_require 'models/group'
babble_require 'models/notification'
babble_require 'models/search'
babble_require 'models/topic_query'
babble_require 'models/topic'
babble_require 'models/user'
@@ -60,6 +61,9 @@ def babble_require(path)
babble_require 'jobs/regular/babble_post_alert'
babble_require 'jobs/scheduled/babble_prune_history'

DiscoursePluginRegistry.serialized_current_user_fields << 'babble_disabled'
DiscoursePluginRegistry.serialized_current_user_fields << 'babble_sound'

on :post_created do |post, opts, user|
if post.topic&.archetype == Archetype.chat
TopicUser.update_last_read(user, post.topic_id, post.post_number, post.post_number, PostTiming::MAX_READ_TIME_PER_BATCH)