Skip to content

Commit 1eadbbd

Browse files
committed
2 parents d526da8 + 3b39026 commit 1eadbbd

19 files changed

+71
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Kandan.Helpers.Avatars
2+
@urlFor: (a, options) ->
3+
size = options.size || 30
4+
fallback = options.fallback || Kandan.options.avatarFallback || 'mm'
5+
avatarHash = a.gravatar_hash || a.get('user').gravatar_hash || a.get('gravatarHash')
6+
Kandan.options.avatarUrl.replace(/%{hash}/, avatarHash).
7+
replace(/%{size}/, size).
8+
replace(/%{fallback}/, fallback)

app/assets/javascripts/backbone/helpers/channels.js.coffee

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Kandan.Helpers.Channels
6262
@getChannelIdByTabIndex: (tabIndex)->
6363
$("#kandan .ui-tabs-panel")
6464
.eq(tabIndex)
65-
.data("channel-id")
65+
.data("channel-id")
6666

6767
@getTabIndexByChannelId: (channelId)->
6868
$("#channels-#{channelId}").prevAll("div").length
@@ -92,11 +92,11 @@ class Kandan.Helpers.Channels
9292
$createTab = $("#create_channel").parents("li").detach()
9393
$("#kandan").tabs("add", channelArea, "#{channel.get("name")}", totalTabs)
9494
$createTab.appendTo("ul.ui-tabs-nav")
95+
$('#ui-tabs-1').remove()
9596
view = new Kandan.Views.ChannelPane({channel: channel})
96-
view.render $(channelArea)
97-
$(channelArea).data("channel_id", channel.get("id"))
98-
99-
97+
$newChannel = $(channelArea)
98+
view.render $newChannel
99+
$newChannel.addClass('ui-tabs-panel')
100100

101101
@newActivityView: (activityAttributes)->
102102
activity = new Kandan.Models.Activity(activityAttributes)
@@ -135,7 +135,7 @@ class Kandan.Helpers.Channels
135135

136136
if not local and @getActiveChannelId() == activityAttributes.channel_id and activityAttributes.action == "message" and Kandan.Helpers.Utils.browserTabFocused != true
137137
Kandan.Helpers.Utils.notifyInTitle()
138-
Kandan.Plugins.Notifications.playAudioNotification()
138+
Kandan.Plugins.Notifications.playAudioNotification('channel')
139139
Kandan.Plugins.Notifications.displayNotification(activityAttributes.user.username || activityAttributes.user.email, activityAttributes.content)
140140

141141
@setPaginationData(activityAttributes.channel_id)

app/assets/javascripts/backbone/kandan.js.coffee.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ window.Kandan =
2121
perPage : <%= Kandan::Config.options[:per_page] %>
2222
nowThreshold: 3000
2323
timestampRefreshInterval: 2000
24+
avatarUrl: "<%= Kandan::Config.options[:avatar_url] %>"
25+
avatarFallback: "<%= Kandan::Config.options[:avatar_fallback] %>"
2426

2527

2628
# TODO this is a helper method to register plugins
@@ -88,7 +90,8 @@ window.Kandan =
8890
add: (event, ui) ->
8991
$('.header .ui-tabs-panel:last').detach().appendTo('#channels')
9092
$('#kandan').tabs('option', 'disabled', [])
91-
$('.header ul a').delegate('cite.close_channel', 'click', window.tabViewGlobal.deleteChannel)
93+
$('.header ul a').undelegate('cite.close_channel','click').
94+
delegate('cite.close_channel', 'click', window.tabViewGlobal.deleteChannel)
9295
})
9396

9497
$("#kandan").tabs 'option', 'tabTemplate', '''

app/assets/javascripts/backbone/plugins/music_player.js.coffee

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class Kandan.Plugins.MusicPlayer
77
@stopRegex: /^&#x2F;stop/
88
@resumeRegex: /^&#x2F;resume/
99
@localSongData: false
10-
10+
@sounds: {
11+
channel: 'ding.wav'
12+
attention: 'gong.mp3'
13+
}
1114

1215
@playTemplate: _.template('<strong><a class="audio-play">playing</a> <a target="_blank" href="<%- url %>"><%- url %></a></strong>')
1316
@stopTemplate: _.template('<strong><a class="audio-play">stopping</a> the music.')
@@ -170,8 +173,9 @@ class Kandan.Plugins.MusicPlayer
170173
if @audioChannel(channelId)?
171174
@unmute(channelId)
172175

173-
@playAudioNotice: ->
174-
url = @localFileUrl('ding.wav')
176+
@playAudioNotice: (type)->
177+
sound = @sounds[type] || 'ding.wav'
178+
url = @localFileUrl(sound)
175179
player = $('.audio_private')[0]
176180
player.setAttribute('src', url)
177181
player.play()

app/assets/javascripts/backbone/plugins/notifications.js.coffee

+8-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Kandan.Plugins.Notifications
7676
@onPopupNotificationsEnabled: ()->
7777
if @webkitNotificationsEnabled()
7878
@enablePopupNotifications()
79-
79+
8080
return
8181

8282
# If you are wondering why the kandan icon is not displayed on OS X this is the reason:
@@ -108,7 +108,7 @@ class Kandan.Plugins.Notifications
108108
@sound_notifications_enabled = true
109109
$(".sound-notifications .enable-sound-notifications").remove()
110110
$(".notification.sound-notifications").append(@disable_sound_notifications_template())
111-
111+
112112
return
113113

114114
@disableSoundNotifications: ()->
@@ -118,7 +118,9 @@ class Kandan.Plugins.Notifications
118118
$(".notification.sound-notifications").append(@enable_sound_notifications_template())
119119
return
120120

121-
@playAudioNotification: ()->
122-
if @sound_notifications_enabled
123-
Kandan.Plugins.MusicPlayer.playAudioNotice()
124-
return
121+
@playAudioNotification: (type)->
122+
if @sound_notifications_enabled and not @isPlaying
123+
@isPlaying = true
124+
setTimeout (=> @isPlaying = false), 1000
125+
Kandan.Plugins.MusicPlayer.playAudioNotice(type)
126+
return

app/assets/javascripts/backbone/plugins/user_list.js.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Kandan.Plugins.UserList
66

77
@template: _.template '''
88
<div class="user clearfix">
9-
<img class="avatar" src="http://gravatar.com/avatar/<%= gravatarHash %>?s=25"/>
9+
<img class="avatar" src="<%= avatarUrl %>"/>
1010
<span class="name"><%= name %></span>
1111
</div>
1212
'''
@@ -22,7 +22,7 @@ class Kandan.Plugins.UserList
2222

2323
$users.append @template({
2424
name: displayName,
25-
gravatarHash: user.gravatar_hash
25+
avatarUrl: Kandan.Helpers.Avatars.urlFor(user, {size: 25})
2626
})
2727
$el.html($users)
2828

app/assets/javascripts/backbone/views/show_activity.js.coffee

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Kandan.Views.ShowActivity extends Backbone.View
66
render: ()->
77
activity = @options.activity.toJSON()
88
activity.content = _.escape(activity.content)
9+
activity.avatarUrl = Kandan.Helpers.Avatars.urlFor(@options.activity, {size: 30})
910
if activity.action != "message"
1011
@compiledTemplate = JST['user_notification']({activity: activity})
1112
else
@@ -20,12 +21,13 @@ class Kandan.Views.ShowActivity extends Backbone.View
2021

2122
user_mention_regex = new RegExp("@#{Kandan.Helpers.Users.currentUser().username}\\b")
2223
all_mention_regex = new RegExp("@all")
23-
24+
2425
if activity.user.id == Kandan.Helpers.Users.currentUser().id
2526
$(@el).addClass("current_user")
26-
27+
2728
if user_mention_regex.test(@compiledTemplate) || all_mention_regex.test(@compiledTemplate)
2829
$(@el).addClass("mentioned_user")
30+
Kandan.Plugins.Notifications?.playAudioNotification('attention')
2931

3032
if activity.id == undefined
3133
$(@el).attr("id", "activity-c#{activity.cid}")

app/assets/templates/activity_base.jst.eco

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<span class="posted_at">
22
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
33
</span>
4-
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
4+
<img class="avatar" src="<%= @activity.avatarUrl %>"/>
55

66
<div class="readable">
77
<div class="content">

app/assets/templates/channel_tabs.jst.eco

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<span class="tab_left"></span>
66
<span class="tab_content">
77
<cite><%= channel.get('name') %></cite>
8-
<cite class="close_channel" title="close channel">x</cite>
8+
<% unless channel.get('id') == 1: %>
9+
<cite class="close_channel" title="close channel">x</cite>
10+
<% end %>
911
</span>
1012
</a>
1113
</li>

app/assets/templates/current_user.jst.eco

-2
This file was deleted.

app/assets/templates/message.jst.eco

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<span class="posted_at">
22
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
33
</span>
4-
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
4+
<img class="avatar" src="<%= @activity.avatarUrl %>"/>
55

66
<div class="readable">
77
<span class="user">

app/assets/templates/user_notification.jst.eco

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<span class="posted_at">
22
<%= new Date(@activity.created_at).toRelativeTime(Kandan.options.nowThreshold) %>
33
</span>
4-
<img class="avatar" src="http://gravatar.com/avatar/<%= @activity.user.gravatar_hash %>?s=30"/>
4+
<img class="avatar" src="<%= @activity.avatarUrl %>"/>
55

66
<div class="readable">
77
<span class="user">Kandan bot</span>

app/helpers/application_helper.rb

+11
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
module ApplicationHelper
2+
def current_user_data
3+
current_user_data = {
4+
:id => current_user.id,
5+
:first_name => current_user.first_name,
6+
:last_name => current_user.last_name,
7+
:email => current_user.email,
8+
:username => current_user.username,
9+
:auth_token => current_user.authentication_token,
10+
:gravatar_hash => current_user.gravatar_hash
11+
}
12+
end
213
end

app/helpers/avatar_helper.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module AvatarHelper
2+
def avatar_url_for(user, options = {})
3+
Kandan::Config.options[:avatar_url].gsub(/%{hash}/, user.gravatar_hash).
4+
gsub(/%{size}/, (options[:size] || 30).to_s).
5+
gsub(/%{fallback}/, options[:fallback] || Kandan::Config.options[:avatar_fallback] || 'mm')
6+
end
7+
end

app/views/layouts/application.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<a href="#" class="user_menu_link">
2323
<cite class="user_flag"></cite>
2424
<div class="user">
25-
<img src="http://gravatar.com/avatar/<%= current_user.gravatar_hash %>?s=25"/>
25+
<img src="<%= avatar_url_for(current_user, :size => 25) %>"/>
2626
<span><%= current_user.full_name_or_username %></span>
2727
</div>
2828
</a>

app/views/main/index.html.erb

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010

1111
<%= javascript_tag do %>
1212
<%- if user_signed_in? %>
13-
<%- current_user_data = {
14-
:id => current_user.id,
15-
:first_name => current_user.first_name,
16-
:last_name => current_user.last_name,
17-
:email => current_user.email,
18-
:username => current_user.username,
19-
:auth_token => current_user.authentication_token,
20-
:gravatar_hash => current_user.gravatar_hash
21-
}
22-
%>
2313
$.data(document, "current-user", <%= current_user_data.to_json.html_safe %>);
2414
<%- end %>
2515
$(document).data("active-users", [])
@@ -63,4 +53,4 @@
6353

6454
window._cloudfuji_help = <%= cloudfuji_help_vars.to_json.html_safe %>;
6555
<%- end %>
66-
<%- end %>
56+
<%- end %>

app/views/main/search.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<%= javascript_tag do %>
2+
$.data(document, "current-user", <%= current_user_data.to_json.html_safe %>);
3+
24
$(document).ready(function(){
35
Kandan.Plugins.initAll()
46
activities = <%= @activities.to_json(:include => :user).html_safe %>;

config/kandan_settings.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
:max_rooms: 99
1414

1515
:public_site: true
16+
17+
:avatar_url: http://gravatar.com/avatar/%{hash}?s=%{size}&d=%{fallback}
18+
:avatar_fallback: identicon

lib/tasks/git.rake

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace :git do
1212
'fusion94' => 'git://github.com/fusion94/kandan.git',
1313
'SpencerCooley' => 'git://github.com/SpencerCooley/kandan.git',
1414
'jrgifford' => 'git://github.com/jrgifford/kandan.git',
15+
'mjtko' => 'git://github.com/mjtko/kandan.git',
1516
}
1617

1718
def get_remotes

0 commit comments

Comments
 (0)