| 1 |
|
| 2 |
|
| 3 |
require 'mui/cairo_sub_parts_message_base' |
| 4 |
|
| 5 |
class Gdk::SubPartsQuote < Gdk::SubPartsMessageBase |
| 6 |
EDGE_ABSENT_SIZE = 2 |
| 7 |
EDGE_PRESENT_SIZE = 8 |
| 8 |
|
| 9 |
register |
| 10 |
|
| 11 |
def messages |
| 12 |
@messages end |
| 13 |
|
| 14 |
def on_click(e, message) |
| 15 |
case e.button |
| 16 |
when 1 |
| 17 |
case UserConfig[:quote_clicked_action] |
| 18 |
when :open |
| 19 |
Plugin.call(:open, message) |
| 20 |
when :smartthread |
| 21 |
Plugin.call(:open_smartthread, [message]) end |
| 22 |
end end |
| 23 |
|
| 24 |
def initialize(*args) |
| 25 |
super |
| 26 |
@edge = show_edge? ? EDGE_PRESENT_SIZE : EDGE_ABSENT_SIZE |
| 27 |
promise_list = helper.score.select{ |note| |
| 28 |
note.respond_to?(:reference) |
| 29 |
}.map{ |note| |
| 30 |
note.reference&.uri || note.uri |
| 31 |
}.select{ |u| |
| 32 |
u.is_a?(Diva::URI) |
| 33 |
}.map{ |target_uri| |
| 34 |
model_class = Plugin.collect(:model_of_uri, target_uri).lazy.map{ |model_slug| |
| 35 |
Diva::Model(model_slug) |
| 36 |
}.find{ |mc| |
| 37 |
mc.spec.timeline |
| 38 |
} |
| 39 |
Delayer.Deferred.new{ model_class.find_by_uri(target_uri) } if model_class |
| 40 |
}.compact |
| 41 |
if !promise_list.empty? |
| 42 |
Delayer::Deferred.when(promise_list).next{ |quoting| |
| 43 |
quoting = quoting.compact |
| 44 |
if !quoting.empty? |
| 45 |
@messages = quoting.freeze |
| 46 |
render_messages |
| 47 |
end |
| 48 |
}.terminate('コメント付きリツイート描画中にエラーが発生しました') |
| 49 |
end |
| 50 |
end |
| 51 |
|
| 52 |
def edge |
| 53 |
if show_edge? |
| 54 |
unless @edge == EDGE_PRESENT_SIZE |
| 55 |
@edge = EDGE_PRESENT_SIZE |
| 56 |
helper.reset_height |
| 57 |
end |
| 58 |
else |
| 59 |
unless @edge == EDGE_ABSENT_SIZE |
| 60 |
@edge = EDGE_ABSENT_SIZE |
| 61 |
helper.reset_height |
| 62 |
end |
| 63 |
end |
| 64 |
Gdk.scale(@edge) |
| 65 |
end |
| 66 |
|
| 67 |
def badge(_message) |
| 68 |
Skin[:quote].pixbuf(width: badge_radius*2, height: badge_radius*2) end |
| 69 |
|
| 70 |
def background_color(message) |
| 71 |
color = Plugin.filtering(:subparts_quote_background_color, message, UserConfig[:quote_background_color]).last |
| 72 |
rgb(color || WHITE) |
| 73 |
end |
| 74 |
|
| 75 |
def main_text_color(message) |
| 76 |
rgb(UserConfig[:quote_text_color] || super) |
| 77 |
end |
| 78 |
|
| 79 |
def main_text_font(message) |
| 80 |
helper.font_description(UserConfig[:quote_text_font]) |
| 81 |
end |
| 82 |
|
| 83 |
def header_left_content(*args) |
| 84 |
if show_header? |
| 85 |
super end end |
| 86 |
|
| 87 |
def header_right_content(*args) |
| 88 |
if show_header? |
| 89 |
super end end |
| 90 |
|
| 91 |
def icon_size |
| 92 |
if show_icon? |
| 93 |
if UserConfig[:quote_icon_size] |
| 94 |
size = Gdk.scale(UserConfig[:quote_icon_size]) |
| 95 |
Gdk::Rectangle.new(0, 0, size, size) |
| 96 |
else |
| 97 |
super end end end |
| 98 |
|
| 99 |
def text_max_line_count(message) |
| 100 |
UserConfig[:quote_text_max_line_count] || super end |
| 101 |
|
| 102 |
def render_outline(message, context, base_y) |
| 103 |
return unless show_edge? |
| 104 |
case UserConfig[:quote_edge] |
| 105 |
when :floating |
| 106 |
render_outline_floating(message, context, base_y) |
| 107 |
when :solid |
| 108 |
render_outline_solid(message, context, base_y) |
| 109 |
when :flat |
| 110 |
render_outline_flat(message, context, base_y) end end |
| 111 |
|
| 112 |
def render_badge(message, context) |
| 113 |
return unless show_edge? |
| 114 |
case UserConfig[:quote_edge] |
| 115 |
when :floating |
| 116 |
render_badge_floating(message, context) |
| 117 |
when :solid |
| 118 |
render_badge_solid(message, context) |
| 119 |
when :flat |
| 120 |
render_badge_flat(message, context) end end |
| 121 |
|
| 122 |
def show_header? |
| 123 |
(UserConfig[:quote_present_policy] || []).include?(:header) end |
| 124 |
|
| 125 |
def show_icon? |
| 126 |
(UserConfig[:quote_present_policy] || []).include?(:icon) end |
| 127 |
|
| 128 |
def show_edge? |
| 129 |
(UserConfig[:quote_present_policy] || []).include?(:edge) end |
| 130 |
end |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|