chatrix 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba2375aa13d58ebfd71dd9b5638ece86b117ab7c
4
- data.tar.gz: b1af2a00d81f14c65cb431a7e2dd5cda2c64f131
3
+ metadata.gz: 5fdbaf53540d109264fd47203f5bf8371b7a0e0d
4
+ data.tar.gz: e618549b57e588e22fe091b3f7538053088a97e3
5
5
  SHA512:
6
- metadata.gz: d024ab9abac227ab99042caa3a3a30659c892f4f1345d7c304905c59df88c06aaf39ca00557d43863833da8ae4ef68a656ee84bd60e21355358177110b5e1a9a
7
- data.tar.gz: 58b18862a142eb30a0c366dbe0a085d4c5a8519129da9615c63c04aa624cfa92ebea37ee421b4264a807ad201598a242f09b11514402ffe9d8180a0f7978fdbe
6
+ metadata.gz: 2ea913a13a9257f27fdccdf36a4a013360bbc2d0c7c0756978f633152351c33aaa7e9e574ae177e050d438f7d3997db41f5d64f2a726dc43e460c5db60188261
7
+ data.tar.gz: ccf53b6718e921aa22fc1a6354997155de119baa19a75bb594b8c380e159bfbc7b2a57673e61c48e50645be2badb2d35a26b53cbd1ae1636b6909b3587b09bd2
@@ -34,6 +34,7 @@ module Chatrix
34
34
 
35
35
  @rooms.on(:added) do |room|
36
36
  broadcast(:room_added, room)
37
+ room.on(:invited) { |s, i| broadcast(:invited, room, s, i) }
37
38
  room.timeline.on(:message) { |r, m| broadcast(:room_message, r, m) }
38
39
  end
39
40
  end
@@ -46,14 +47,28 @@ module Chatrix
46
47
  # @see #sync! See the documentation for {#sync!} for more information
47
48
  # and what happens in case of an error during sync.
48
49
  def start_syncing
49
- @sync_thread ||= Thread.new { loop { sync! } }
50
+ @sync_thread ||= Thread.new do
51
+ begin
52
+ loop { sync! }
53
+ rescue => e
54
+ broadcast(:connection_error, e)
55
+ ensure
56
+ stop_syncing
57
+ broadcast(:disconnected)
58
+ end
59
+ end
50
60
  end
51
61
 
52
62
  # Stops syncing against the homeserver.
53
63
  def stop_syncing
54
64
  return unless @sync_thread.is_a? Thread
65
+
55
66
  @sync_thread.exit
56
67
  @sync_thread.join
68
+
69
+ rescue => e
70
+ broadcast(:stop_error, e)
71
+ ensure
57
72
  @sync_thread = nil
58
73
  end
59
74
 
@@ -73,6 +88,13 @@ module Chatrix
73
88
  @rooms[id]
74
89
  end
75
90
 
91
+ # Joins the room with the specified ID.
92
+ # @param id [String] The room ID to join.
93
+ # @return [Room] The Room instance for the joined room.
94
+ def join_room(id)
95
+ @rooms.join id
96
+ end
97
+
76
98
  private
77
99
 
78
100
  # Syncs against the server.
@@ -30,31 +30,28 @@ module Chatrix
30
30
 
31
31
  # Kicks a user from the room.
32
32
  #
33
- # @param user [User,String] The user to kick, can be either a User
34
- # object or a String (user ID).
33
+ # @param user [User] The user to kick.
35
34
  # @param reason [String] The reason for the kick.
36
35
  # @return [Boolean] `true` if the user was kicked, otherwise `false`.
37
36
  def kick(user, reason)
38
- @matrix.rooms.actions.kick @room.id, user, reason
37
+ @matrix.rooms.actions.kick @room.id, user.id, reason
39
38
  end
40
39
 
41
40
  # Bans a user from the room.
42
41
  #
43
- # @param user [User,String] The user to kick, can be either a User
44
- # object or a String (user ID).
42
+ # @param user [User] The user to kick.
45
43
  # @param reason [String] The reason for the ban.
46
44
  # @return [Boolean] `true` if the user was kicked, otherwise `false`.
47
45
  def ban(user, reason)
48
- @matrix.rooms.actions.ban @room.id, user, reason
46
+ @matrix.rooms.actions.ban @room.id, user.id, reason
49
47
  end
50
48
 
51
49
  # Unbans a user from the room.
52
50
  #
53
- # @param user [User,String] The user to unban, can be either a User
54
- # objec or a String (user ID).
51
+ # @param user [User] The user to unban.
55
52
  # @return [Boolean] `true` if the user was unbanned, otherwise `false`.
56
53
  def unban(user)
57
- @matrix.rooms.actions.unban @room.id, user
54
+ @matrix.rooms.actions.unban @room.id, user.id
58
55
  end
59
56
  end
60
57
  end
@@ -31,7 +31,7 @@ module Chatrix
31
31
  return @rooms[id] if id.start_with? '!'
32
32
 
33
33
  if id.start_with? '#'
34
- res = @rooms.find { |_, r| r.alias == id }
34
+ res = @rooms.find { |_, r| r.canonical_alias == id }
35
35
  return res.last if res.respond_to? :last
36
36
  end
37
37
 
@@ -39,6 +39,15 @@ module Chatrix
39
39
  res.last if res.respond_to? :last
40
40
  end
41
41
 
42
+ # Attempts to join the specified room.
43
+ # @param id [String] The room ID to join.
44
+ # @return [Room] The Room instance for the joined room.
45
+ # @raise [ForbiddenError] Raised if the user does not have sufficient
46
+ # permissions to join the room.
47
+ def join(id)
48
+ get_room(id).tap(&:join)
49
+ end
50
+
42
51
  # Processes a list of room events from syncs.
43
52
  #
44
53
  # @param events [Hash] A hash of room events as returned from the server.
@@ -3,5 +3,5 @@
3
3
 
4
4
  module Chatrix
5
5
  # The current version of this gem.
6
- VERSION = '1.2.0'.freeze
6
+ VERSION = '1.3.0'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hellberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-06 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty