@@ -2,12 +2,33 @@ class ActivityObserver < ActiveRecord::Observer
2
2
3
3
def after_save ( activity )
4
4
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
10
6
Kandan ::Config . broadcaster . broadcast ( faye_channel , broadcast_data )
11
7
end
12
8
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
13
34
end
0 commit comments