Class: Telegram::TelegramChat

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

Overview

Telegram Chat Model

See Also:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from TelegramBase

#client, #id

Instance Method Summary collapse

Methods inherited from TelegramBase

#fail_back, pick_or_new, #send_image, #send_image_url, #send_message, #send_sticker, #send_typing, #send_typing_abort, #send_video, #targetize

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(client, chat) ⇒ TelegramChat

Create a new chat instance

Parameters:

  • client (Client)

    Root client instance

  • chat (Integer)

    Raw chat data

Since:

  • 0.1.0


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/telegram/models.rb', line 162

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

  @id = chat['peer_id']
  @name = @title = chat.has_key?('title') ? chat['title'] : chat['print_name']
  @type = chat['peer_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

#membersArray<TelegramContact> (readonly)

Returns The members of the chat.

Returns:

Since:

  • 0.1.0


152
153
154
# File 'lib/telegram/models.rb', line 152

def members
  @members
end

#nameString (readonly)

Returns The name of the chat.

Returns:

  • (String)

    The name of the chat

Since:

  • 0.1.0


149
150
151
# File 'lib/telegram/models.rb', line 149

def name
  @name
end

#typeString (readonly)

Returns The type of the chat (chat, encr_chat, user and etc).

Returns:

  • (String)

    The type of the chat (chat, encr_chat, user and etc)

Since:

  • 0.1.0


155
156
157
# File 'lib/telegram/models.rb', line 155

def type
  @type
end

Instance Method Details

#leave!Object

Leave from current chat

Since:

  • 0.1.0


183
184
185
# File 'lib/telegram/models.rb', line 183

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

#to_sString

Convert Event instance to the string format

Returns:

Since:

  • 0.1.0


195
196
197
# File 'lib/telegram/models.rb', line 195

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

#to_tgString

Returns A chat identifier formatted with type.

Returns:

  • (String)

    A chat identifier formatted with type

Since:

  • 0.1.0


188
189
190
# File 'lib/telegram/models.rb', line 188

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