Class: Telegram::TelegramChat

Inherits:
TelegramBase show all
Defined in:
lib/telegram/models.rb

Instance Attribute Summary collapse

Attributes inherited from TelegramBase

#client, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TelegramBase

#send_image, #send_image_url, #send_message, #send_sticker

Constructor Details

#initialize(client, chat) ⇒ TelegramChat



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/telegram/models.rb', line 40

def initialize(client, chat)
  @client = client
  @chat = chat

  @id = chat['id']
  @title = chat.has_key?('title') ? chat['title'] : chat['print_name']
  @type = chat['type']

  @members = []
  if chat.has_key?('members')
    chat['members'].each { |user|
      @members << TelegramContact.pick_or_new(client, user)
    }
  elsif @type == 'user' and chat['user']
    @members << TelegramContact.pick_or_new(client, chat)
  end
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



31
32
33
# File 'lib/telegram/models.rb', line 31

def members
  @members
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/telegram/models.rb', line 30

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



32
33
34
# File 'lib/telegram/models.rb', line 32

def type
  @type
end

Class Method Details

.pick_or_new(client, chat) ⇒ Object



34
35
36
37
38
# File 'lib/telegram/models.rb', line 34

def self.pick_or_new(client, chat)
  ct = client.chats.find { |c| c.id == chat['id'] }
  return ct unless ct.nil?
  TelegramChat.new(client, chat)
end

Instance Method Details

#leave!Object



58
59
60
# File 'lib/telegram/models.rb', line 58

def leave!
  @client.chat_del_user(self, @client.profile)
end

#to_sObject



66
67
68
# File 'lib/telegram/models.rb', line 66

def to_s
  "<TelegramChat #{@title}(#{@type}\##{@id}) members=#{@members.size}>"
end

#to_tgObject



62
63
64
# File 'lib/telegram/models.rb', line 62

def to_tg
  "#{@type}\##{@id}"
end