Class: Ayadn::View

Inherits:
Object show all
Defined in:
lib/ayadn/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(status = Status.new, workers = nil) ⇒ View

Returns a new instance of View.



5
6
7
8
# File 'lib/ayadn/view.rb', line 5

def initialize status = Status.new, workers = nil
  @status = status
  @workers = workers.nil? ? Workers.new(status) : workers
end

Instance Method Details



346
347
348
# File 'lib/ayadn/view.rb', line 346

def all_hashtag_links(stream, hashtag)
  all_links(stream, "hashtag", hashtag)
end


350
351
352
# File 'lib/ayadn/view.rb', line 350

def all_search_links(stream, words)
  all_links(stream, "search", hashtag)
end


354
355
356
# File 'lib/ayadn/view.rb', line 354

def all_stars_links(stream)
  all_links(stream, "starred")
end

#big_separatorObject



387
388
389
# File 'lib/ayadn/view.rb', line 387

def big_separator
  "----------\n\n\n"
end

#clear_screenObject



327
328
329
# File 'lib/ayadn/view.rb', line 327

def clear_screen
  puts "\e[H\e[2J"
end

#downloading(options = {}) ⇒ Object



362
363
364
365
366
367
# File 'lib/ayadn/view.rb', line 362

def downloading(options = {})
  unless options[:raw]
    clear_screen()
    @status.downloading
  end
end

#get(data, options = {}, niceranks = {}) ⇒ Object



318
319
320
321
322
323
324
325
# File 'lib/ayadn/view.rb', line 318

def get(data, options = {}, niceranks = {})
  clear_screen()
  if options[:index]
    show_posts_with_index(data, options, niceranks)
  else
    show_posts(data, options, niceranks)
  end
end

#hide_cursorObject



14
15
16
# File 'lib/ayadn/view.rb', line 14

def hide_cursor
  puts "\e[?25l"
end

#if_raw(what, options) ⇒ Object



34
35
36
37
38
39
# File 'lib/ayadn/view.rb', line 34

def if_raw what, options
  if options[:raw]
    show_raw(what, options)
    exit
  end
end

#infos(stream, token) ⇒ Object



358
359
360
# File 'lib/ayadn/view.rb', line 358

def infos(stream, token)
  show_userinfos(stream, token, true)
end

#list(what, list, target, options = {}) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/ayadn/view.rb', line 369

def list(what, list, target, options = {})
  clear_screen()
  case what
  when :whoreposted
    show_list_reposted(list, target)
  when :whostarred
    show_list_starred(list, target)
  when :followings
    show_list_followings(list, target, options)
  when :followers
    show_list_followers(list, target, options)
  when :muted
    show_list_muted(list, options)
  when :blocked
    show_list_blocked(list, options)
  end
end

#page(msg) ⇒ Object



331
332
333
334
335
336
# File 'lib/ayadn/view.rb', line 331

def page msg
  # clear_screen
  puts "\n"
  puts msg
  puts "\n"
end

#render(stream, options = {}, niceranks = {}) ⇒ Object



310
311
312
313
314
315
316
# File 'lib/ayadn/view.rb', line 310

def render(stream, options = {}, niceranks = {})
  unless options[:raw]
    get(stream, options, niceranks)
  else
    show_raw(stream)
  end
end

#show_channels(stream, options = {}) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/ayadn/view.rb', line 204

def show_channels(stream, options = {})
  view = ""
  bucket = @workers.build_channels(stream, options)

  bucket.reverse.each do |ch|
    if options[:broadcasts]
      next if ch.type != "net.app.core.broadcast"
    end
    if options[:"no-broadcasts"]
      next if ch.type == "net.app.core.broadcast"
    end
    if options[:messages]
      next if ch.type != "net.app.core.pm"
    end
    if options[:"no-messages"]
      next if ch.type == "net.app.core.pm"
    end
    if options[:patter]
      next if ch.type != "net.patter-app.room"
    end
    if options[:"no-patter"]
      next if ch.type == "net.patter-app.room"
    end
    if options[:other]
      case ch.type
      when "net.app.core.pm", "net.app.core.broadcast", "net.patter-app.room"
        next
      end
    end
    if options[:"no-other"]
      next if ch.type != "net.app.core.pm" || ch.type != "net.app.core.broadcast" || ch.type != "net.patter-app.room"
    end
    view << "\n"
    view << "ID: ".color(:cyan)
    view << "#{ch.id}".color(color_id)
    view << "\n"
    ch_alias = Databases.get_alias_from_id(ch.id)
    unless ch_alias.nil?
      view << "Alias: ".color(:cyan)
      view << "#{ch_alias}".color(color_username)
      view << "\n"
    end
    view << "Messages: ".color(:cyan)
    view << "#{ch.num_messages}".color(color_symbols)
    view << "\n"
    if ch.owner
      view << "Owner: ".color(:cyan)
      view << "@#{ch.owner.username}".color(color_username)
      view << "\n"
    end
    unless options[:channels] # unless the request comes from Search
      view << "Writers: ".color(:cyan)
      view << "#{ch.writers}".color(color_name)
      view << "\n"
    end
    view << "Type: ".color(:cyan)
    view << "#{ch.type}".color(color_index)
    view << "\n"
    if ch.type == "net.patter-app.room"
      ann = ch.annotations.select {|a| a.type == "net.patter-app.settings"}
      view << "Name: ".color(:cyan)
      view << "#{ann[0].value['name']}".color(color_link)
      view << "\n"
      view << "Description: ".color(:cyan)
      view << "#{ann[0].value['blurb']}".color(color_username)
      view << "\n"
      ann = ch.annotations.select {|a| a.type == "net.app.core.fallback_url"}
      view << "URL: ".color(:cyan)
      view << "#{ann[0].value['url']}".color(color_link)
      view << "\n"
    end
    if ch.type == "net.app.core.broadcast"
      ann = ch.annotations.select {|a| a.type == "net.app.core.broadcast.metadata"}
      view << "Title: ".color(:cyan)
      view << "#{ann[0].value['title']}".color(color_link)
      view << "\n"
      view << "Description: ".color(:cyan)
      view << "#{ann[0].value['description']}".color(color_username)
      view << "\n"
      ann = ch.annotations.select {|a| a.type == "net.app.core.fallback_url"}
      view << "URL: ".color(:cyan)
      view << "#{ann[0].value['url']}".color(color_link)
      view << "\n"
    end
    unless ch.recent_message.nil?
      unless ch.recent_message.text.nil?
        view << "Most recent message (#{@workers.parsed_time(ch.recent_message.created_at)}): ".color(:cyan)
        view << "\n"
        view << "---\n#{ch.recent_message.text}\n---"
      end
    end
    if ch.type == "net.paste-app.clips"
      ann = ch.recent_message.annotations.select {|a| a.type == "net.paste-app.clip"}
      view << "\n\n"
      view << ann[0].value['content']
      view << "\n"
    end
    view << "\n\n"
  end
  puts view
  unless options[:channels] || options[:id]
    @status.info("info", "your account is currently linked to #{bucket.length} channels", "cyan")
    puts "\n"
  end
end

#show_cursorObject



10
11
12
# File 'lib/ayadn/view.rb', line 10

def show_cursor
  puts "\e[?25h"
end

#show_direct_raw(stream, options = {}) ⇒ Object



49
50
51
# File 'lib/ayadn/view.rb', line 49

def show_direct_raw(stream, options = {})
  jj stream
end

#show_files_list(list) ⇒ Object



103
104
105
# File 'lib/ayadn/view.rb', line 103

def show_files_list(list)
  puts build_files_list(list)
end

#show_interactions(stream) ⇒ Object



98
99
100
101
# File 'lib/ayadn/view.rb', line 98

def show_interactions(stream)
  #puts "\n"
  puts build_interactions_stream(stream)
end


342
343
344
# File 'lib/ayadn/view.rb', line 342

def show_links(links)
  links.each {|l| puts "#{l}".color(color_link)}
end

#show_list_blocked(list, options = {}) ⇒ Object



93
94
95
96
# File 'lib/ayadn/view.rb', line 93

def show_list_blocked(list, options = {})
  puts @workers.build_blocked_list(list, options)
  puts "\n"
end

#show_list_followers(list, target, options = {}) ⇒ Object



83
84
85
86
# File 'lib/ayadn/view.rb', line 83

def show_list_followers(list, target, options = {})
  puts @workers.build_followers_list(list, target, options)
  puts "\n"
end

#show_list_followings(list, target, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/ayadn/view.rb', line 74

def show_list_followings(list, target, options = {})
  if options["lastpost"]
    show_list_with_lastpost(list, target, options)
  else
    puts @workers.build_followings_list(list, target, options)
    puts "\n"
  end
end

#show_list_muted(list, options = {}) ⇒ Object



88
89
90
91
# File 'lib/ayadn/view.rb', line 88

def show_list_muted(list, options = {})
  puts @workers.build_muted_list(list, options)
  puts "\n"
end

#show_list_reposted(list, target) ⇒ Object



62
63
64
65
66
# File 'lib/ayadn/view.rb', line 62

def show_list_reposted(list, target)
  users_list, table = @workers.build_reposted_list(list, target)
  puts @workers.build_users_list(users_list, table)
  puts "\n"
end

#show_list_starred(list, target) ⇒ Object



68
69
70
71
72
# File 'lib/ayadn/view.rb', line 68

def show_list_starred(list, target)
  users_list, table = @workers.build_starred_list(list, target)
  puts @workers.build_users_list(users_list, table)
  puts "\n"
end

#show_messages(messages) ⇒ Object



29
30
31
32
# File 'lib/ayadn/view.rb', line 29

def show_messages messages
  resp = build_stream_without_index(messages, {}, {})
  puts resp unless resp == ""
end

#show_posted(resp) ⇒ Object



57
58
59
60
# File 'lib/ayadn/view.rb', line 57

def show_posted(resp)
  show_simple_post([PostObject.new(resp['data'])], {})
  puts "\n" if timeline_is_compact
end

#show_posts(data, options = {}, niceranks = {}) ⇒ Object



24
25
26
27
# File 'lib/ayadn/view.rb', line 24

def show_posts(data, options = {}, niceranks = {})
  resp = build_stream_without_index(data.posts, options, niceranks)
  puts resp unless resp == ""
end

#show_posts_with_index(data, options = {}, niceranks = {}) ⇒ Object



18
19
20
21
22
# File 'lib/ayadn/view.rb', line 18

def show_posts_with_index(data, options = {}, niceranks = {})
  posts, view = build_stream_with_index(data.posts, options, niceranks)
  puts view unless view == ""
  Databases.save_indexed_posts(posts)
end

#show_raw(stream, options = {}) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ayadn/view.rb', line 41

def show_raw(stream, options = {})
  if stream.is_a? Hash
    show_direct_raw stream
  else
    jj stream.input
  end
end

#show_settingsObject



107
108
109
110
111
# File 'lib/ayadn/view.rb', line 107

def show_settings
  clear_screen()
  puts Settings.options.to_table
  puts "\n"
end

#show_simple_post(post, options = {}) ⇒ Object



53
54
55
# File 'lib/ayadn/view.rb', line 53

def show_simple_post(post, options = {})
  puts build_stream_without_index(post, options, {})
end

#show_userinfos(user, token, show_ranks = false) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ayadn/view.rb', line 113

def show_userinfos(user, token, show_ranks = false)
  if timeline_is_compact
    padding = "\n"
    view = "\n"
  else
    padding = "\n\n"
    view = ""
  end

  if !user.name.blank?
    view << "Name\t\t\t".color(:cyan) + user.name.color(color_name)
  else
    view << "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
  end

  view << "#{padding}Username\t\t".color(:cyan) + "@#{user.username}".color(color_username)

  view << "#{padding}ID\t\t\t".color(:cyan) + user.id.color(color_id)

  view << "#{padding}URL\t\t\t".color(:cyan) + user.canonical_url.color(color_link)

  unless user.verified_domain.nil?
    if user.verified_domain =~ (/http/ || /https/)
       domain = user.verified_domain
    else
      domain = "http://#{user.verified_domain}"
    end
    view << "\nVerified domain\t\t".color(:cyan) + domain.color(color_link)
  end


  view << "#{padding}Account creation\t".color(:cyan) + @workers.parsed_time(user.created_at).color(color_excerpt)
  view << "#{padding}TimeZone\t\t".color(:cyan) + user.timezone.color(color_excerpt)
  view << "\nLocale\t\t\t".color(:cyan) + user.locale.color(color_excerpt)

  view << "#{padding}Posts\t\t\t".color(:cyan) + user.counts.posts.to_s.color(color_excerpt)

  view << "#{padding}Following\t\t".color(:cyan) + user.counts.following.to_s.color(color_excerpt)
  view << "\nFollowers\t\t".color(:cyan) + user.counts.followers.to_s.color(color_excerpt)

  if user.username == Settings.config.identity.username && !token.nil?
    view << "#{padding}Storage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(color_excerpt)
    view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(color_excerpt)
  end

  unless user.username == Settings.config.identity.username
    if user.you_follow
      view << "#{padding}You follow ".color(:cyan) + "@#{user.username}".color(color_username)
    else
      view << "#{padding}You don't follow ".color(:cyan) + "@#{user.username}".color(color_username)
    end
    if user.follows_you
      view << "\n" + "@#{user.username}".color(color_username) + " follows you".color(:cyan)
    else
      view << "\n" + "@#{user.username}".color(color_username) + " doesn't follow you".color(:cyan)
    end
    if user.you_muted
      view << "\nYou muted " + "@#{user.username}".color(color_username)
    end
    if user.you_blocked
      view << "\nYou blocked " + "@#{user.username}".color(color_username)
    end
  end

  unless user.annotations.empty?
    view << "\n" unless timeline_is_compact
  end
  user.annotations.each do |anno|
    case anno.type
    when "net.app.core.directory.blog"
      view << "\nBlog\t\t\t".color(:cyan) + "#{anno.value['url']}".color(color_link)
    when "net.app.core.directory.twitter"
      view << "\nTwitter\t\t\t".color(:cyan) + "#{anno.value['username']}".color(:green)
    when "com.appnetizens.userinput.birthday"
      view << "\nBirthday\t\t".color(:cyan) + "#{anno.value['birthday']}".color(:green)
    end
  end

  if !user.description.blank?
    mentions = user.description.entities.mentions.map {|m| "@#{m.name}"}
    hashtags = user.description.entities.hashtags.map {|m| m.name}
    view << "#{padding}#{@workers.colorize_text(user.description.text, mentions, hashtags)}\n"
    view << "\n" unless timeline_is_compact
  end

  view << "\n" if timeline_is_compact

  puts view

end

#winsizeObject



338
339
340
# File 'lib/ayadn/view.rb', line 338

def winsize
  IO.console.winsize
end