Commit ccebeb2

mo <mo.khan@gmail.com>
2018-05-10 03:22:09
remove rooms.
1 parent 7f1d639
lib/del/configuration.rb
@@ -9,7 +9,6 @@ module Del
     attr_accessor :muc_domain
     attr_accessor :name
     attr_accessor :password
-    attr_accessor :rooms
     attr_accessor :router
     attr_accessor :users
     attr_accessor :socket_file
@@ -23,7 +22,6 @@ module Del
       @muc_domain = settings.fetch(:muc_domain, "conf.hipchat.com")
       @name = settings.fetch(:full_name)
       @password = settings.fetch(:password)
-      @rooms = Repository.new
       @router = DefaultRouter.new
       @socket_file = settings.fetch(:socket_file, SOCKET_FILE)
       @users = Repository.new
lib/del/connection.rb
@@ -1,11 +1,9 @@
 module Del
   class Connection
-    attr_reader :configuration, :rooms, :users
+    attr_reader :configuration
 
     def initialize(configuration:)
       @configuration = configuration
-      @rooms = configuration.rooms
-      @users = configuration.users
       @mucs = {}
     end
 
@@ -19,7 +17,7 @@ module Del
       client.auth(configuration.password)
       roster = Jabber::Roster::Helper.new(client, false)
       roster.add_update_callback do |old_item, item|
-        users.upsert(item['jid'], item.attributes) if item
+        configuration.users.upsert(item['jid'], item.attributes) if item
       end
       roster.get_roster
       roster.wait_for_roster
@@ -44,9 +42,9 @@ module Del
         end
         muc.join(room_jid)
       end
-      list_rooms(configuration.muc_domain).each do |room|
-        rooms.upsert(room)
-      end
+      #list_rooms(configuration.muc_domain).each do |room|
+        #rooms.upsert(room)
+      #end
     end
 
     def deliver(jid, message)
@@ -77,11 +75,11 @@ module Del
       @jid ||= jid_for(configuration.jid, "chat.hipchat.com", "bot")
     end
 
-    def list_rooms(muc_domain)
-      Jabber::MUC::MUCBrowser.new(client).muc_rooms(muc_domain).map do |jid, name|
-        jid.to_s
-      end
-    end
+    #def list_rooms(muc_domain)
+      #Jabber::MUC::MUCBrowser.new(client).muc_rooms(muc_domain).map do |jid, name|
+        #jid.to_s
+      #end
+    #end
 
     def encode_string(s)
       s.to_s.encode("UTF-8", invalid: :replace, undef: :replace)
lib/del/repository.rb
@@ -10,7 +10,9 @@ module Del
     end
 
     def find_by(id)
-      @lock.synchronize { Del::User.new(id, @storage[id.to_s]) }
+      @lock.synchronize do
+        Del::User.new(id, @storage[id.to_s])
+      end
     end
 
     def find_all
lib/del/user.rb
@@ -10,5 +10,9 @@ module Del
     def mention_name
       attributes[:mention_name]
     end
+
+    def to_s
+      YAML.dump(attributes)
+    end
   end
 end