matrix_sdk 1.5.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,6 @@ module MatrixSdk
7
7
  class User
8
8
  extend MatrixSdk::Extensions
9
9
 
10
- # @!attribute [r] id
11
- # @return [String] the MXID of the user
12
- # @!attribute [r] client
13
- # @return [Client] the client for the user
14
10
  attr_reader :id, :client
15
11
  alias user_id :id
16
12
 
@@ -32,14 +28,14 @@ module MatrixSdk
32
28
  end
33
29
  end
34
30
 
35
- # @!attribute [r] display_name
36
31
  # @return [String] the display name
32
+ # @see MatrixSdk::Protocols::CS#get_display_name
37
33
  def display_name
38
34
  @display_name ||= client.api.get_display_name(id)[:displayname]
39
35
  end
40
36
 
41
- # @!attribute [w] display_name
42
37
  # @param name [String] the display name to set
38
+ # @see MatrixSdk::Protocols::CS#set_display_name
43
39
  def display_name=(name)
44
40
  client.api.set_display_name(id, name)
45
41
  @display_name = name
@@ -51,21 +47,92 @@ module MatrixSdk
51
47
  display_name || id
52
48
  end
53
49
 
54
- # @!attribute [r] avatar_url
50
+ # Gets the avatar for the user
51
+ #
52
+ # @see MatrixSdk::Protocols::CS#get_avatar_url
55
53
  def avatar_url
56
54
  @avatar_url ||= client.api.get_avatar_url(id)[:avatar_url]
57
55
  end
58
56
 
59
- # @!attribute [w] avatar_url
57
+ # Set a new avatar for the user
58
+ #
59
+ # Only works for the current user object, as requested by
60
+ # client.get_user(:self)
61
+ #
62
+ # @param url [String,URI::MATRIX] the new avatar URL
63
+ # @note Requires a mxc:// URL, check example on
64
+ # {MatrixSdk::Protocols::CS#set_avatar_url} for how this can be done
65
+ # @see MatrixSdk::Protocols::CS#set_avatar_url
60
66
  def avatar_url=(url)
61
67
  client.api.set_avatar_url(id, url)
62
68
  @avatar_url = url
63
69
  end
64
70
 
71
+ # Get the user's current presence status
72
+ #
73
+ # @return [Symbol] One of :online, :offline, :unavailable
74
+ # @see MatrixSdk::Protocols::CS#get_presence_status
75
+ # @note This information is not cached in the abstraction layer
76
+ def presence
77
+ raw_presence[:presence].to_sym
78
+ end
79
+
80
+ # Sets the user's current presence status
81
+ # Should be one of :online, :offline, or :unavailable
82
+ #
83
+ # @param new_presence [:online,:offline,:unavailable] The new presence status to set
84
+ # @see MatrixSdk::Protocols::CS#set_presence_status
85
+ def presence=(new_presence)
86
+ raise ArgumentError, 'Presence must be one of :online, :offline, :unavailable' unless %i[online offline unavailable].include?(presence)
87
+
88
+ client.api.set_presence_status(id, new_presence)
89
+ end
90
+
91
+ # @return [Boolean] if the user is currently active
92
+ # @note This information is not cached in the abstraction layer
93
+ def active?
94
+ raw_presence[:currently_active] == true
95
+ end
96
+
97
+ # Gets the user-specified status message - if any
98
+ #
99
+ # @see MatrixSdk::Protocols::CS#get_presence_status
100
+ # @note This information is not cached in the abstraction layer
101
+ def status_msg
102
+ raw_presence[:status_msg]
103
+ end
104
+
105
+ # Sets the user-specified status message
106
+ #
107
+ # @param message [String,nil] The message to set, or nil for no message
108
+ # @see MatrixSdk::Protocols::CS#set_presence_status
109
+ def status_msg=(message)
110
+ client.api.set_presence_status(id, presence, message: message)
111
+ end
112
+
113
+ # Gets the last time the user was active at, from the server's side
114
+ #
115
+ # @return [Time] when the user was last active
116
+ # @see MatrixSdk::Protocols::CS#get_presence_status
117
+ # @note This information is not cached in the abstraction layer
118
+ def last_active
119
+ since = raw_presence[:last_active_ago]
120
+ return unless since
121
+
122
+ Time.now - (since / 1000)
123
+ end
124
+
125
+ # Returns all the current device keys for the user, retrieving them if necessary
65
126
  def device_keys
66
127
  @device_keys ||= client.api.keys_query(device_keys: { id => [] }).yield_self do |resp|
67
128
  resp[:device_keys][id.to_sym]
68
129
  end
69
130
  end
131
+
132
+ private
133
+
134
+ def raw_presence
135
+ client.api.get_presence_status(id).tap { |h| h.delete :user_id }
136
+ end
70
137
  end
71
138
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MatrixSdk
4
- VERSION = '1.5.0'
4
+ VERSION = '2.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matrix_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha
@@ -103,6 +103,7 @@ files:
103
103
  - lib/matrix_sdk/protocols/as.rb
104
104
  - lib/matrix_sdk/protocols/cs.rb
105
105
  - lib/matrix_sdk/protocols/is.rb
106
+ - lib/matrix_sdk/protocols/msc.rb
106
107
  - lib/matrix_sdk/protocols/ss.rb
107
108
  - lib/matrix_sdk/response.rb
108
109
  - lib/matrix_sdk/room.rb
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubygems_version: 3.0.6
131
+ rubygems_version: 3.1.2
131
132
  signing_key:
132
133
  specification_version: 4
133
134
  summary: SDK for applications using the Matrix protocol