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

Commit 600d2e8

Browse files
committed
Merge pull request #19 from ursm/next
Adapt to brand-new Idobata™
2 parents 75df260 + 54725be commit 600d2e8

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

app/main_controller.rb

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,47 +125,37 @@ def locateToRoom(organization, room_name)
125125
def webView(sender, didFinishLoadForFrame:frame)
126126
sender.windowScriptObject.evaluateWebScript <<-CODE
127127
(function(){
128-
var onMessageCreated = function(data){
129-
var notify = false;
130-
var mode = window.butter.notificationMode();
131-
if (mode == "all") {
132-
notify = true;
133-
} else if (mode == "mention") {
134-
if (data.message.mentions.indexOf(parseInt(window.Idobata.user.id)) >= 0) {
128+
var onMessageCreated = function(user) {
129+
return function(data){
130+
var notify = false;
131+
var mode = window.butter.notificationMode();
132+
if (mode == "all") {
135133
notify = true;
134+
} else if (mode == "mention") {
135+
if (data.message.mentions.indexOf(parseInt(user.get('id'))) >= 0) {
136+
notify = true;
137+
}
136138
}
137-
}
138-
if (notify) {
139-
butter.notify(JSON.stringify(data.message));
140-
}
139+
if (notify) {
140+
butter.notify(JSON.stringify(data.message));
141+
}
142+
};
141143
};
142144
143145
var onUnreadCountUpdated = function() {
144-
var totalUnreadCount = this.get('rooms').reduce(function(acc, room) {
145-
return acc + room.get('unreadMessagesCount');
146-
}, 0);
147-
window.butter.setBadge(totalUnreadCount);
146+
window.butter.setBadge(this.get('totalUnreadMessagesCount'));
148147
}
149148
150-
var bindEvent = function(){
151-
if (!window.Idobata.pusher) {
152-
return false;
153-
}
154-
if (!window.Idobata.user) {
155-
return false;
156-
}
157-
window.Idobata.pusher.bind('message_created', onMessageCreated);
158-
window.Idobata.user.addObserver('[email protected]', onUnreadCountUpdated);
159-
onUnreadCountUpdated.apply(window.Idobata.user);
160-
161-
return true;
162-
};
149+
window.addEventListener('ready.idobata', function(e) {
150+
var container = e.detail.container;
151+
152+
var pusher = container.lookup('pusher:main');
153+
var user = container.lookup('service:session').get('user');
163154
164-
setTimeout(function setBind(){
165-
if (!bindEvent()) {
166-
setTimeout(setBind, 100);
167-
}
168-
}, 100);
155+
pusher.bind('message:created', onMessageCreated(user));
156+
user.addObserver('totalUnreadMessagesCount', onUnreadCountUpdated);
157+
onUnreadCountUpdated.apply(user);
158+
});
169159
})();
170160
CODE
171161
end

0 commit comments

Comments
 (0)