| 1 |
|
| 2 |
|
| 3 |
require 'gtk3' |
| 4 |
|
| 5 |
|
| 6 |
クト用のメソッド集 |
| 7 |
をinclude元に要求する |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
module Gtk::TimeLineUtils |
| 12 |
|
| 13 |
include Enumerable |
| 14 |
|
| 15 |
def self.included(obj) |
| 16 |
class << obj |
| 17 |
|
| 18 |
イムラインを全て返す |
| 19 |
def timelines |
| 20 |
@timelines = (@timelines || []).select{ |tl| not tl.destroyed? }.freeze end |
| 21 |
|
| 22 |
def get_active_mumbles |
| 23 |
Set.new end |
| 24 |
|
| 25 |
alias :old_new_Ak6FV :new |
| 26 |
def new(*args) |
| 27 |
result = old_new_Ak6FV(*args) |
| 28 |
@timelines = MIKU::Cons.new(result, @timelines || nil).freeze |
| 29 |
result end |
| 30 |
|
| 31 |
def wayofopenlink |
| 32 |
@wayofopenlink ||= MIKU::Cons.list([URI.regexp(['http','https']), lambda{ |url, cancel| |
| 33 |
Gtk.openurl(url) }].freeze).freeze end |
| 34 |
|
| 35 |
def addopenway(condition, &open) |
| 36 |
if(type_check(condition => :===, open => :call)) |
| 37 |
@wayofopenlink = MIKU::Cons.new([condition, open].freeze, wayofopenlink).freeze |
| 38 |
true end end |
| 39 |
|
| 40 |
def openurl(url) |
| 41 |
gen_openurl_proc(url).call |
| 42 |
false end |
| 43 |
|
| 44 |
def gen_openurl_proc(url, way_of_open_link = wayofopenlink) |
| 45 |
way_of_open_link.freeze |
| 46 |
expanded = (Plugin.filtering(:expand_url, [url]).first.first rescue url) |
| 47 |
lambda{ |
| 48 |
way_of_open_link.each_with_index{ |way, index| |
| 49 |
condition, open = *way |
| 50 |
if(condition === expanded) |
| 51 |
open.call(url, gen_openurl_proc(url, way_of_open_link[(index+1)..(way_of_open_link.size)])) |
| 52 |
break end } } end |
| 53 |
|
| 54 |
def addwidgetrule(reg, &proc) |
| 55 |
end end end |
| 56 |
|
| 57 |
るメッセージの最大数。超えれば古いものから捨てられる。 |
| 58 |
attr_accessor :timeline_max |
| 59 |
|
| 60 |
に入りに追加された時に呼ばれる |
| 61 |
def favorite(user, message) |
| 62 |
mumble = get_mumble_by(message) |
| 63 |
mumble.on_favorited(user) if mumble |
| 64 |
self |
| 65 |
end |
| 66 |
|
| 67 |
りから削除された時に呼ばれる |
| 68 |
def unfavorite(user, message) |
| 69 |
mumble = get_mumble_by(message) |
| 70 |
mumble.on_unfavorited(user) if mumble |
| 71 |
self |
| 72 |
end |
| 73 |
|
| 74 |
れた時に呼ばれる |
| 75 |
def modified(message) |
| 76 |
end |
| 77 |
|
| 78 |
のMessageオブジェクトを渡すこともできる。 |
| 79 |
def add(message) |
| 80 |
if message.is_a?(Enumerable) |
| 81 |
self.block_add_all(Plugin.filtering(:show_filter, message).first) |
| 82 |
else |
| 83 |
m = Plugin.filtering(:show_filter, [message]).first.first |
| 84 |
self.block_add(m) if m.is_a?(Message) end |
| 85 |
self end |
| 86 |
|
| 87 |
削除されたときに呼ばれる |
| 88 |
def remove_if_exists_all(msgs) |
| 89 |
end |
| 90 |
|
| 91 |
信したときにそれを引数に呼ばれる |
| 92 |
def add_retweets(messages) |
| 93 |
end |
| 94 |
|
| 95 |
protected |
| 96 |
|
| 97 |
ジェクトを受け取って適切に処理する。 |
| 98 |
び、リツイートだった場合は _add_retweets_ を呼ぶ。 |
| 99 |
def block_add_all(messages) |
| 100 |
removes, appends = *messages.partition{ |m| m[:rule] == :destroy } |
| 101 |
remove_if_exists_all(removes) |
| 102 |
retweets, appends = *messages.partition{ |m| m[:retweet] } |
| 103 |
add_retweets(retweets) |
| 104 |
appends.each(&method(:block_add)) |
| 105 |
end |
| 106 |
end |