Class: MatrixSdk::User

Inherits:
Object show all
Defined in:
lib/matrix_sdk/user.rb

Overview

A class for tracking information about a user on Matrix

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, id, data = {}) ⇒ User

Returns a new instance of User.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/matrix_sdk/user.rb', line 19

def initialize(client, id, data = {})
  @client = client
  @id = id

  @display_name = nil
  @avatar_url = nil

  data.each do |k, v|
    instance_variable_set("@#{k}", v) if instance_variable_defined? "@#{k}"
  end
end

Instance Attribute Details

#avatar_urlObject



51
52
53
# File 'lib/matrix_sdk/user.rb', line 51

def avatar_url
  @avatar_url ||= client.api.get_avatar_url(id)[:avatar_url]
end

#clientObject (readonly)

Returns the value of attribute client.



10
# File 'lib/matrix_sdk/user.rb', line 10

attr_reader :id, :client

#display_nameString

Returns the display name.

Returns:

  • (String)

    the display name



33
34
35
# File 'lib/matrix_sdk/user.rb', line 33

def display_name
  @display_name ||= client.api.get_display_name(id)[:displayname]
end

#idString (readonly) Also known as: user_id

Returns the MXID of the user.

Returns:

  • (String)

    the MXID of the user



10
11
12
# File 'lib/matrix_sdk/user.rb', line 10

def id
  @id
end

Instance Method Details

#device_keysObject



61
62
63
64
65
# File 'lib/matrix_sdk/user.rb', line 61

def device_keys
  @device_keys ||= client.api.keys_query(device_keys: { id => [] }).yield_self do |resp|
    resp[:device_keys][id.to_sym]
  end
end

#friendly_nameString

Gets a friendly name of the user

Returns:

  • (String)

    either the display name or MXID if unset



46
47
48
# File 'lib/matrix_sdk/user.rb', line 46

def friendly_name
  display_name || id
end

#inspectString

An inspect method that skips a handful of instance variables to avoid flooding the terminal with debug data.

Returns:

  • (String)

    a regular inspect string without the data for some variables



17
# File 'lib/matrix_sdk/user.rb', line 17

ignore_inspect :client