Skip to content

Commit 3ef00e0

Browse files
committedApr 10, 2012
Seperates publishing for messages and uploads
Signed-off-by: Akash Manohar J <akash@akash.im>
1 parent 7b88b88 commit 3ef00e0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed
 

‎app/models/activity_observer.rb

+26-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@ class ActivityObserver < ActiveRecord::Observer
22

33
def after_save(activity)
44
if activity.action == "message" || activity.action == "upload"
5-
faye_channel = "/channels/#{activity.channel.to_param}"
6-
broadcast_data = activity.attributes.merge({
7-
:user => activity.user.attributes,
8-
:channel => activity.channel.attributes
9-
})
5+
faye_channel, broadcast_data = self.send "#{activity.action}_broadcast_data", activity
106
Kandan::Config.broadcaster.broadcast(faye_channel, broadcast_data)
117
end
128
end
9+
10+
private
11+
def message_broadcast_data(activity)
12+
faye_channel = "/channels/#{activity.channel.to_param}"
13+
broadcast_data = activity.attributes.merge({
14+
:user => activity.user.attributes,
15+
:channel => activity.channel.attributes
16+
})
17+
[faye_channel, broadcast_data]
18+
end
19+
20+
def upload_broadcast_data(activity)
21+
faye_channel = "/app/activities"
22+
broadcast_data = {
23+
:event => "attachment#upload",
24+
:entity => activity.attributes.merge({
25+
:user => activity.user.attributes,
26+
:channel => activity.channel.attributes
27+
}),
28+
:extra => {
29+
:attachments => activity.channel.attachments.as_json(:methods => :url)
30+
}
31+
}
32+
[faye_channel, broadcast_data]
33+
end
1334
end

0 commit comments

Comments
 (0)