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.



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

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



53
54
55
# File 'lib/matrix_sdk/user.rb', line 53

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

#clientObject (readonly)

Returns the value of attribute client.



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

attr_reader :id, :client

#display_nameString

Returns the display name.

Returns:

  • (String)

    the display name



35
36
37
# File 'lib/matrix_sdk/user.rb', line 35

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



12
13
14
# File 'lib/matrix_sdk/user.rb', line 12

def id
  @id
end

Instance Method Details

#device_keysObject



63
64
65
66
67
# File 'lib/matrix_sdk/user.rb', line 63

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



48
49
50
# File 'lib/matrix_sdk/user.rb', line 48

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



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

ignore_inspect :client