Class: MatrixSdk::User

Inherits:
Object show all
Extended by:
Extensions
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

Methods included from Extensions

events, ignore_inspect

Constructor Details

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

Returns a new instance of User.



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

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



55
56
57
# File 'lib/matrix_sdk/user.rb', line 55

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

#clientObject (readonly)

Returns the value of attribute client.



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

attr_reader :id, :client

#display_nameString

Returns the display name.

Returns:

  • (String)

    the display name



37
38
39
# File 'lib/matrix_sdk/user.rb', line 37

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



14
15
16
# File 'lib/matrix_sdk/user.rb', line 14

def id
  @id
end

Instance Method Details

#device_keysObject



65
66
67
68
69
# File 'lib/matrix_sdk/user.rb', line 65

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



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

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



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

ignore_inspect :client