Skip to content
This repository was archived by the owner on Oct 6, 2021. It is now read-only.

Commit 51b4319

Browse files
committed
Merge pull request #21 from harukasan/feature/brand-new-idobata
Adopt to brand-new Idobata(TM)
2 parents 600d2e8 + d3ab873 commit 51b4319

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

Gemfile.lock

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
CFPropertyList (2.2.8)
5-
activesupport (3.2.19)
6-
i18n (~> 0.6, >= 0.6.4)
7-
multi_json (~> 1.0)
4+
activesupport (4.2.1)
5+
i18n (~> 0.7)
6+
json (~> 1.7, >= 1.7.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
810
bubble-wrap (1.5.0)
911
colored (1.2)
10-
i18n (0.6.11)
11-
ib (0.4.9)
12+
i18n (0.7.0)
13+
ib (0.7.2)
1214
thor (~> 0.15.4)
1315
tilt (~> 1.4.1)
1416
xcodeproj (~> 0.17)
15-
multi_json (1.10.1)
16-
rake (10.3.2)
17+
json (1.8.2)
18+
minitest (5.5.1)
19+
rake (10.4.2)
1720
thor (0.15.4)
21+
thread_safe (0.3.5)
1822
tilt (1.4.1)
19-
xcodeproj (0.18.0)
20-
CFPropertyList (~> 2.2)
21-
activesupport (~> 3.0)
23+
tzinfo (1.2.2)
24+
thread_safe (~> 0.1)
25+
xcodeproj (0.23.1)
26+
activesupport (>= 3)
2227
colored (~> 1.2)
2328

2429
PLATFORMS

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Motion::Project::App.setup do |app|
1919
app.name = 'Butter'
2020
app.icon = 'icon.icns'
2121
app.identifier = 'jp.harukasan.butter'
22-
app.version = '0.1.5'
22+
app.version = '0.2.0'
2323
app.frameworks << 'WebKit'
2424
end
2525

app/main_controller.rb

+29-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def initWebView
5252
@web_view.setUIDelegate self
5353
@web_view.setPolicyDelegate self
5454

55-
url = NSURL.URLWithString "https://idobata.io/users/sign_in"
55+
url = NSURL.URLWithString "https://idobata.io/#/"
5656
request = NSURLRequest.requestWithURL url
5757
@web_view.mainFrame.loadRequest request
5858
end
@@ -61,20 +61,16 @@ def notify(data)
6161
data = BW::JSON.parse data.to_s.dataUsingEncoding(NSUTF8StringEncoding)
6262

6363
notification = NSUserNotification.alloc.init.tap do |n|
64-
n.title = "#{data['sender_name']} \u25b8 #{data['room_name']}"
65-
n.informativeText = data['body_plain']
64+
n.title = "#{data['sender']} \u25b8 #{data['roomName']}"
65+
n.informativeText = data['text']
6666
n.soundName = NSUserNotificationDefaultSoundName
67-
keys = [
68-
"organization_slug",
69-
"room_name",
70-
]
71-
n.userInfo = data.select {|key, val| keys.include? key }
67+
n.userInfo = { "url" => data['url'] }
7268
end
7369

74-
sender_icon_url = data['sender_icon_url']
75-
if sender_icon_url.length > 0
76-
notification.contentImage = fetchIconImage sender_icon_url
77-
end
70+
sender_icon_url = data['iconUrl']
71+
if sender_icon_url
72+
notification.contentImage = fetchIconImage sender_icon_url
73+
end
7874

7975
NSUserNotificationCenter.defaultUserNotificationCenter.tap do |center|
8076
center.delegate = self
@@ -113,19 +109,19 @@ def fetchIconImage(url)
113109
return image
114110
end
115111

116-
def locateToRoom(organization, room_name)
112+
def locateTo(url)
117113
window_object = @web_view.windowScriptObject
118114
window_object.evaluateWebScript <<-CODE
119-
location.href = "#/organization/#{organization}/room/#{room_name}";
115+
location.href = '#{url}';
120116
CODE
121117
@web_view.display
122118
end
123119

124120
# called when frame loading finished
125-
def webView(sender, didFinishLoadForFrame:frame)
121+
def webView(sender, didStartProvisionalLoadForFrame:frame)
126122
sender.windowScriptObject.evaluateWebScript <<-CODE
127123
(function(){
128-
var onMessageCreated = function(user) {
124+
var onMessageCreated = function(user, store, router) {
129125
return function(data){
130126
var notify = false;
131127
var mode = window.butter.notificationMode();
@@ -137,7 +133,18 @@ def webView(sender, didFinishLoadForFrame:frame)
137133
}
138134
}
139135
if (notify) {
140-
butter.notify(JSON.stringify(data.message));
136+
store.find('message', data.message.id).then(function(message) {
137+
var roomUrl = '/' + router.generate('room.index', message.get('room'));
138+
var roomName = message.get('room.organization.name').toString() + ' / ' + message.get('room.name').toString();
139+
var payload = {
140+
sender: data.message.senderName,
141+
roomName: roomName,
142+
text: data.message.bodyPlain,
143+
iconUrl: data.message.senderIconUrl,
144+
url: roomUrl
145+
};
146+
window.butter.notify(JSON.stringify(payload));
147+
});
141148
}
142149
};
143150
};
@@ -151,8 +158,10 @@ def webView(sender, didFinishLoadForFrame:frame)
151158
152159
var pusher = container.lookup('pusher:main');
153160
var user = container.lookup('service:session').get('user');
161+
var store = container.lookup('store:main');
162+
var router = container.lookup('router:main');
154163
155-
pusher.bind('message:created', onMessageCreated(user));
164+
pusher.bind('message:created', onMessageCreated(user, store, router));
156165
user.addObserver('totalUnreadMessagesCount', onUnreadCountUpdated);
157166
onUnreadCountUpdated.apply(user);
158167
});
@@ -188,7 +197,7 @@ def webView(sender, decidePolicyForNewWindowAction:info, request:request, frame:
188197

189198
def webView(sender, runJavaScriptAlertPanelWithMessage:message, initiatedByFrame:frame)
190199
puts "ALERT: #{message}"
191-
NSRunAlertPanel "alert", message, "OK", nil, nil
200+
# NSRunAlertPanel "alert", message, "OK", nil, nil
192201
end
193202

194203
def webView(sender, runJavaScriptConfirmPanelWithMessage:message, initiatedByFrame:frame)
@@ -216,7 +225,7 @@ def userNotificationCenter(center, shouldPresentNotification:notification)
216225

217226
def userNotificationCenter(center, didActivateNotification:notification)
218227
info = notification.userInfo
219-
locateToRoom info["organization_slug"], info["room_name"]
228+
locateTo info['url']
220229
center.removeDeliveredNotification notification
221230
end
222231
end

0 commit comments

Comments
 (0)