Sha256: 9c44f581d534bdfcdb1c0fa2d167238ed889c5366b5e2b8a1f9206b4a1a5a211

Contents?: true

Size: 780 Bytes

Versions: 5

Compression:

Stored size: 780 Bytes

Contents

require 'appscript'
require 'model/participant'

class Chat
	attr_accessor :chat_number, :updated, :participants

	def initialize(chat_number, updated, participants)
		self.chat_number = chat_number
		self.updated = updated
		self.participants = participants
	end

	def to_s
		participants.map(&:name).join(", ")
	end

	def self.fetch_all
		ascript_chats.map.with_index(1){ |chat, i| from_ascript_chat(chat, i) }
	end

	def self.ascript_chats
		Appscript.app("Messages").chats.get()
	end

	def self.from_ascript_chat(chat, chat_number)
		new(chat_number, chat.updated.get(), participants_from_ascript_chat(chat))
	end

	def self.participants_from_ascript_chat(chat)
		chat.participants.get().map do |participant|
			Participant.from_ascript_participant(participant)
		end
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
imsg-0.0.9 lib/model/chat.rb
imsg-0.0.8 lib/model/chat.rb
imsg-0.0.7 lib/model/chat.rb
imsg-0.0.6 lib/model/chat.rb
imsg-0.0.5 lib/model/chat.rb