lib/talkbird/entity/channel.rb in talkbird-0.0.3 vs lib/talkbird/entity/channel.rb in talkbird-0.0.4

- old
+ new

@@ -11,10 +11,16 @@ }.freeze class << self def find(from, to) + # The only way to find a conversation with another person is to search + # through all the conversations with some rather strict parameters + # and pick the best match. + # + # In this case, the order is based on the latest last message as it + # makes more sense to have the result = Client.request( :get, "users/#{from}/my_group_channels", params: { members_exactly_in: to, @@ -24,11 +30,13 @@ show_member: true, limit: 1 } ) - if result.is_a?(Result::Success) + # Since this is the result of a search, the response can be an empty + # array, in which case the result should also be false. + if result.is_a?(Result::Success) && !result.body[:channels].empty? Channel.build(result.body[:channels].first) else false end end @@ -94,10 +102,10 @@ body: body ) end def to_s - "#<Talkbird::Entity::Channel id=#{id}>" + "#<Talkbird::Entity::Channel id=#{id} name=#>" end end end end