lib/ayadn/action.rb in ayadn-2.1 vs lib/ayadn/action.rb in ayadn-3.0
- old
+ new
@@ -4,15 +4,16 @@
##
# This class is the main initializer + dispatcher
# It responds to the CLI commands dispatcher, app.rb
+ require_relative "stream"
+
def initialize
@api = API.new
@view = View.new
@workers = Workers.new
- @thor = Thor::Shell::Color.new
@status = Status.new
@check = Check.new
Settings.load_config
Settings.get_token
Settings.init_config
@@ -464,17 +465,23 @@
end
@view.clear_screen
response = details.call
@check.no_post(response, post_id)
resp = response['data']
+
+ if resp["is_deleted"] == true
+ @status.user_404(resp["id"])
+ Errors.global_error({error: "user 404", caller: caller, data: [post_id, options]})
+ end
+
response = @api.get_user("@#{resp['user']['username']}")
@check.no_user(response, response['data']['username'])
stream = response['data']
@status.post_info
@view.show_simple_post([resp], options)
puts "\n" if Settings.options[:timeline][:compact] == true
- @thor.say_status "info", "author", "cyan"
+ @status.say_info "author"
puts "\n" unless Settings.options[:timeline][:compact] == true
if response['data']['username'] == Settings.config[:identity][:username]
@view.show_userinfos(stream, @api.get_token_info['data'], true)
else
@view.show_userinfos(stream, nil, true)
@@ -554,11 +561,11 @@
Settings.options[:timeline][:compact] = true if options[:compact] == true
if options[:silent]
Settings.options[:marker][:messages] = false
end
puts "\n"
- @thor.say_status :searching, "channels with unread PMs"
+ @status.say_nocolor :searching, "channels with unread PMs"
response = @api.get_channels
unread_channels = []
response['data'].map do |ch|
if ch['type'] == "net.app.core.pm" && ch['has_unread'] == true
unread_channels << ch['id']
@@ -568,11 +575,11 @@
@status.no_new_messages
exit
end
unread_messages = {}
unread_channels.reverse.each do |id|
- @thor.say_status :downloading, "messages from channel #{id}"
+ @status.say_nocolor :downloading, "messages from channel #{id}"
since = Databases.find_last_id_from("channel:#{id}")
unless since.nil?
api_options = {count: 20, since_id: since}
else
api_options = {count: 20}
@@ -591,13 +598,13 @@
name = "channel:#{k}"
Databases.pagination_insert(name, v[1])
resp = @api.update_marker(name, v[1])
res = JSON.parse(resp)
if res['meta']['code'] != 200
- @thor.say_status :error, "couldn't update channel #{k} as read", :red
+ @status.say_error "couldn't update channel #{k} as read"
else
- @thor.say_status :updated, "channel #{k} as read", :green
+ @status.say_green :updated, "channel #{k} as read"
end
end
end
@view.clear_screen
unread_messages.each do |k,v|
@@ -890,17 +897,9 @@
Settings.options[:timeline][:compact] = true if options[:compact] == true
stream = Stream.new(@api, @view, @workers)
stream.random_posts(options)
rescue => e
Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
- end
- end
-
- def version
- begin
- @status.version
- rescue => e
- Errors.global_error({error: e, caller: caller, data: []})
end
end
private