Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ダイレクトメッセージを受信したときのイベントハンドラが欲しい #AzureaScript
// @author http://c4se.sakura.ne.jp/profile/ne.html
// @date 20110413
// @license Public Domain
(function(k){function h(){var c,d,b,a;f.callRefresh();c=f.getItemByOrder(0);if(!(!c||c.id===e)){c=f.items;a=false;if(e){d=0;for(b=c.length;d<b;++d)if(c[d].id===e){a=true;break}}for(e=a?c[d].id:c[0].id;d--;){b=c[d].status;a=g.receiveMessage;for(var i=a.length;i--;)a[i](b)}j(h,3E5)}}var j=System.setTimeout,f=System.views.getView(2),e=0,g={receiveMessage:[]};j(h,5E3);k.DirectMessage={addEventListener:function(c,d){var b=g[c],a;if(b){for(a=b.length;a--;)b[a]===d&&b.splice(a,1);b.push(d)}},removeEventListener:function(c,
d){var b=g[c],a;if(b)for(a=b.length;a--;)if(b[a]===d){b.splice(a,1);break}}}})(this);
// @author http://c4se.sakura.ne.jp/profile/ne.html
// @date 20110413
// @license Public Domain
// [目安箱/32 - Azurea Wiki]( http://azurea.refy.net/ja/wiki/index.php?%E7%9B%AE%E5%AE%89%E7%AE%B1%2F32 ,"ダイレクトメッセージを受信したときのイベントハンドラが欲しい")
(function(_scope) {
var setTimeout = System.setTimeout,
dm_view = System.views.getView(2),
last_dm = 0,
events_lists = {
receiveMessage: []
};
function addEventListener(eventname, // @param String:
// receiveMessage
callback) { // @param Function: callback(Status Object)
var events_list = events_lists[eventname],
i;
if (events_list) {
i = events_list.length;
while (i--) {
if (events_list[i] === callback) {
events_list.splice(i, 1);
}
}
events_list.push(callback);
}
}
function removeEventListener(eventname, // @param String:
// receiveMessage
callback) { // @param Function:
var events_list = events_lists[eventname],
i;
if (events_list) {
i = events_list.length;
while (i--) {
if (events_list[i] === callback) {
events_list.splice(i, 1);
break;
}
}
}
}
function runReseiveMessageEventListener(status) { // @param Status Object:
var events_list = events_lists.receiveMessage,
i = events_list.length;
while (i--) {
events_list[i](status);
}
}
function checkDM() {
var first_dm_item, items, i, len, has_last_dm;
dm_view.callRefresh();
first_dm_item = dm_view.getItemByOrder(0);
if (!first_dm_item || first_dm_item.id === last_dm) {
return void 0;
}
items = dm_view.items;
has_last_dm = false;
if (last_dm) {
for (i = 0, len = items.length; i < len; ++i) {
if (items[i].id === last_dm) {
has_last_dm = true;
break;
}
}
}
if (has_last_dm) {
last_dm = items[i].id;
} else {
last_dm = items[0].id;
}
while (i--) {
runReseiveMessageEventListener(items[i].status);
}
setTimeout(checkDM, 300000);
}
setTimeout(checkDM, 5000);
_scope.DirectMessage = {
addEventListener: addEventListener,
removeEventListener: removeEventListener
};
}(this));
@ne-sachirou

This comment has been minimized.

Copy link
Owner Author

@ne-sachirou ne-sachirou commented Apr 13, 2011

cf. [目安箱/32 - Azurea Wiki](http://azurea.refy.net/ja/wiki/index.php?%E7%9B%AE%E5%AE%89%E7%AE%B1%2F32 ,"ダイレクトメッセージを受信したときのイベントハンドラが欲しい")

@ne-sachirou

This comment has been minimized.

Copy link
Owner Author

@ne-sachirou ne-sachirou commented Apr 18, 2011

Beta16で追加された、TwitterStream.userStreamを使って下さい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment