5 Achegas 7e02804736 ... 996a518362

Autor SHA1 Mensaxe Data
  Endes 996a518362 Major fixes %!s(int64=6) %!d(string=hai) anos
  Endes e595ad81ba Implemented third party invite and updated the readme. %!s(int64=6) %!d(string=hai) anos
  Endes fe93f5186a implemented guest access, room previews, room tags, client config, direct messaging, %!s(int64=6) %!d(string=hai) anos
  Endes cf90fc8888 Implmented room events for rooms preview %!s(int64=6) %!d(string=hai) anos
  Endes edd0fd2529 Implemented device management %!s(int64=6) %!d(string=hai) anos

+ 1 - 1
README.md

@@ -31,7 +31,7 @@ con.session.logout(function() : Void {
 For more examples see the `Test_client` class in *test/beartek/matrix_im/client* and for more info see [Matrix Client-Server API docs](https://matrix.org/docs/spec/client_server/r0.3.0.html) (This library does not implement the API equal than described in the matrix docs).
 
 ## TODO
-- Implement [modules](https://matrix.org/docs/spec/client_server/r0.3.0.html#modules).
+- Implement some [modules](https://matrix.org/docs/spec/client_server/r0.3.0.html#modules): Push Notifications, End-to-End Encryption, Send-to-Device messaging, Server Side Search, Event Context and CAS-based client login.
 - Add documetation to the class, types and functions.
 - Make better README.
 

+ 1 - 1
src/beartek/matrix_im/client/Conection.hx

@@ -34,7 +34,7 @@ class Conection {
 
     this.account = new Account(this.on_responses, this.send_request, server_url);
     this.account.on_login_data = function(l: Login_data) {
-      this.session.fallback_handler(l)
+      this.session.fallback_handler(l);
     }
 
     this.filters = new Filters(this.on_responses, this.send_request, server_url);

+ 52 - 0
src/beartek/matrix_im/client/handlers/Account.hx

@@ -9,6 +9,8 @@ import beartek.matrix_im.client.types.replys.Login_data;
 import beartek.matrix_im.client.types.replys.UIA;
 import beartek.matrix_im.client.types.replys.Threepid;
 import beartek.matrix_im.client.types.User;
+import beartek.matrix_im.client.types.Room;
+import beartek.matrix_im.client.types.Device;
 import beartek.matrix_im.client.auths.Auth;
 
 class Account extends Handler {
@@ -102,6 +104,44 @@ class Account extends Handler {
   }
 
 
+  public function get_devices( on_response : Array<Device> -> Void ) : Void {
+    this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/devices', null), function( status : Int, data : {devices: Array<Device>} ) : Void {
+      on_response(data.devices);
+    });
+  }
+
+  public function get_device(id: String, on_response : Device -> Void) : Void {
+    this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/devices/' + id, null), function( status : Int, data : Device ) : Void {
+      on_response(data);
+    });
+  }
+
+  public function set_device_name(id: String, name: String, on_response : Void -> Void) : Void {
+    this.send_request(Conection.make_request('PUT', server + '/_matrix/client/r0/devices/' + id, {display_name: name}), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
+  public function delete_device( id: String, on_response : Null<Dynamic> -> Void, on_stage : Auths -> Auth -> Void, ?stage_selector : Array<Array<Auths>> -> Int ) : Void {
+    this.send_request(Conection.make_request('DELETE', server + '/_matrix/client/r0/devices/' + id, null), function( status : Int, response : Dynamic ) : Void {
+      if( Check_reply.is_UIA(response) ) {
+        var data : UIA = new UIA(response);
+        var request = Conection.make_request('DELETE', server + '/_matrix/client/r0/devices/' + id, {});
+
+        if( stage_selector != null ) {
+          data.select_flow(stage_selector(data.get_flows()));
+        } else {
+          data.select_flow(UIA.fast_flow(data.get()));
+        }
+
+        data.start(on_stage, on_response, request, this.send_request);
+      } else {
+        throw 'Error on trying UIA';
+      }
+    }, true);
+  }
+
+
   public function get_3pid( on_response : Array<Threepid> -> Void ) : Void {
     this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/account/3pid', null), function( status : Int, data : {threepids: Array<Threepid>} ) : Void {
       on_response(data.threepids);
@@ -118,6 +158,18 @@ class Account extends Handler {
     this.email_token(id_server, email, attemp, secret, on_response, '/_matrix/client/r0/account/3pid/email/requestToken');
   }
 
+  public function add_data( user : User, type : String, data: Dynamic, on_response : Void -> Void ) : Void {
+    this.send_request(Conection.make_request('PUT', server + '/_matrix/client/r0/user/' + user + '/account_data/' + type, data), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
+  public function add_room_data( user : User, room: Room, type : String, data: Dynamic, on_response : Void -> Void ) : Void {
+    this.send_request(Conection.make_request('PUT', server + '/_matrix/client/r0/user/' + user + '/rooms/' + room + '/account_data/' + type, data), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
   public function whoami( on_response : User -> Void ) : Void {
     trace( 'Use Conection.session.user instead of Conection.account.whoami' );
     this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/account/whoami', null), function( status : Int, data : {user_id: String} ) : Void {

+ 5 - 4
src/beartek/matrix_im/client/handlers/Content.hx

@@ -18,16 +18,16 @@ class Content extends Handler {
       url: server + '/_matrix/media/r0/upload?filename=' + filename,
       method: HttpMethod.POST,
       contentType: mimetype,
-      content: content.getString(0, content.length);
+      content: content.getString(0, content.length)
     });
     this.send_request(request, function ( status : Int, data: {content_uri: String} ) : Void {
-      on_response(new Content_uri(content_uri));
-    }
+      on_response(new Content_uri(data.content_uri));
+    });
   }
 
   public function download(content_uri: Content_uri, ?on_response: String -> String -> haxe.io.Bytes -> Void) : Void {
     var request = new HttpRequest({
-      url: server + '/_matrix/media/r0/download/' + content_uri.get_server() + '/' content_uri.get_media_id(),
+      url: server + '/_matrix/media/r0/download/' + content_uri.get_server() + '/' + content_uri.get_media_id(),
       method: HttpMethod.GET
     });
 
@@ -66,6 +66,7 @@ class Content extends Handler {
   public function preview_url(url: String, time: Int, ?on_response: Map<String, String> -> Void) : Void {
     this.send_request(Conection.make_request(HttpMethod.GET, server + '/_matrix/media/r0/preview_url?url=' + url + '&ts=' + time, null), function ( status : Int, data: Dynamic ) : Void {
       on_response(Conection.to_object_map(data));
+    });
   }
 
 }

+ 5 - 5
src/beartek/matrix_im/client/handlers/Presence.hx

@@ -34,24 +34,24 @@ public function set_presence(user: User, presence: beartek.matrix_im.client.type
     if(status == null) {
         this.send_request(Conection.make_request(HttpMethod.PUT, server + '/_matrix/client/r0/presence/' + user + '/status', {presence: presence}), function ( status : Int, data: Dynamic ) : Void {
             on_response();
-        }
+        });
     } else {
         this.send_request(Conection.make_request(HttpMethod.PUT, server + '/_matrix/client/r0/presence/' + user + '/status', {presence: presence, status_msg: status}), function ( status : Int, data: Dynamic ) : Void {
             on_response();
-        }
+        });
     }
  }
 
 public function get_presence(user: User, ?on_response: User_status -> Void) : Void {
     this.send_request(Conection.make_request(HttpMethod.GET, server + '/_matrix/client/r0/presence/' + user + '/status', null), function ( status : Int, data: User_status ) : Void {
         on_response(data);
-    }
+    });
  }
 
 public function edit_list(user: User, add: Array<User>, remove: Array<User>, ?on_response: Void -> Void) : Void {
     this.send_request(Conection.make_request(HttpMethod.POST, server + '/_matrix/client/r0/presence/list/' + user , {invite: add, drop: remove}), function ( status : Int, data: Dynamic ) : Void {
         on_response();
-    }
+    });
  }
 
 public function update_list(user: User, time: Int, ?on_response: Array<{content: User_status, type: Types}> -> Void) : Void {
@@ -60,7 +60,7 @@ public function update_list(user: User, time: Int, ?on_response: Array<{content:
             this.list[new User(e.content.user_id)] = e.content;
         }
         on_response(data);
-    }
+    });
 
     haxe.Timer.delay(function() {
         this.update_list(user, time, on_response);

+ 1 - 0
src/beartek/matrix_im/client/handlers/Receipt.hx

@@ -17,6 +17,7 @@ class Receipt extends Handler {
   public function send_read(room: Room, event: String, ?on_response: Void -> Void) : Void {
     this.send_request(Conection.make_request(HttpMethod.POST, server + '/_matrix/client/r0/rooms/' + room + '/receipt/m.read/' + event, null), function ( status : Int, data: Dynamic ) : Void {
       on_response();
+    });
   }
 
   public function get_receipt_event(event: Event<Dynamic>): Event<Receipt_event> {

+ 39 - 4
src/beartek/matrix_im/client/handlers/Rooms.hx

@@ -46,16 +46,16 @@ class Rooms extends Handler {
   public function check_typing(time: Int, user: User) {
     for(room in typing_on.keys()) {
       if(typing_on[room] == true) {
-        this.typing(room, user, time + 200);
+        this.typing(room, user, time + 200, function(t:Bool) {});
       } else if(typing_on[room] == false) {
-        this.typing(room, user, time, true);
+        this.typing(room, user, time, true, function(t:Bool) {});
         typing_on[room] == null;
       }
     }
 
-    haxe.Timer.delay(time, function (){
+    haxe.Timer.delay(function (){
       check_typing(time, user);
-    });
+    }, time);
   }
 
   public inline function invite( room : Room, user : User, on_response : Void -> Void ) : Void {
@@ -64,6 +64,12 @@ class Rooms extends Handler {
     });
   }
 
+  public inline function third_invite( room : Room, identity_server : String, address: String, medium: String = 'email', on_response : Void -> Void ) : Void {
+    this.send_request(Conection.make_request('POST', this.server + '/_matrix/client/r0/rooms/' + room + '/invite', {id_server: identity_server, address: address, medium: medium}), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
   public inline function join( room : Room, ?third_party_signed : {sender: String, mxid: String, token: String, signatures: Dynamic}, on_response : Room -> Void ) : Void {
     this.send_request(Conection.make_request('POST', this.server + '/_matrix/client/r0/rooms/' + room + '/join', if(third_party_signed != null) {third_party_signed: third_party_signed} else null), function( status : Int, data : Dynamic ) : Void {
       on_response(new Room(data.room_id));
@@ -150,6 +156,12 @@ class Rooms extends Handler {
     this.get_room_events('/_matrix/client/r0/rooms/' + room + '/state', on_response);
   }
 
+  public inline function get_events( room : Room, ?from_token: String, ?timeout: Int, on_response : String -> String -> Array<Event<Dynamic>> -> Void ) : Void {
+    this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/events?room_id=' + room + (if(timeout != null) '&timeout=' + timeout else '') + (if(from_token != null) '&from=' + from_token else ''), null),
+     function( status : Int, data : {start: String, end: String, chunk: Array<Event<Dynamic>>} ) : Void {
+      on_response(data.start, data.end, data.chunk);
+    });
+  }
   public inline function get_members( room : Room, on_response : Array<Event<m.room.Member>> -> Void ) : Void {
     this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/rooms/' + room + '/members', null), function( status : Int, data : Dynamic ) : Void {
       on_response(data.chunk);
@@ -228,6 +240,29 @@ class Rooms extends Handler {
     });
   }
 
+
+  public inline function get_tags( room : Room, user: User, on_response : Array<m.Tag> -> Void ) : Void {
+    this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/user/' + user + '/rooms/' + room + '/tags', null), function( status : Int, data : {tags: Array<Dynamic>} ) : Void {
+      var result: Array<m.Tag> = [];
+      for(t in data.tags) {
+        result.push({tags: Conection.to_object_map(t)});
+      }
+      on_response(result);
+    });
+  }
+
+  public inline function add_tag( room : Room, user: User, tag: String, order: Int, on_response : Void -> Void ) : Void {
+    this.send_request(Conection.make_request('PUT', server + '/_matrix/client/r0/user/' + user + '/rooms/' + room + '/tags/' + tag, {order: order}), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
+  public inline function remove_tag( room : Room, user: User, tag: String, on_response : Void -> Void ) : Void {
+    this.send_request(Conection.make_request('DELETE', server + '/_matrix/client/r0/user/' + user + '/rooms/' + room + '/tags/' + tag, null), function( status : Int, data : Dynamic ) : Void {
+      on_response();
+    });
+  }
+
   private function get_room_events( url : String, on_response : Array<Event<Dynamic>> -> Void ) : Void {
     this.send_request(Conection.make_request('GET', server + url, null), function( status : Int, data : Dynamic ) : Void {
       on_response(data);

+ 2 - 1
src/beartek/matrix_im/client/handlers/Voip.hx

@@ -14,12 +14,13 @@ class Voip extends Handler {
   public function new( on_responses : Int -> Dynamic -> ?Bool -> Bool, send_request : HttpRequest -> (Int -> Dynamic -> Void) -> ?Bool -> Void, server : String ) {
     super(on_responses, send_request, server);
 
-    this.update_turn()
+    this.update_turn();
   }
 
   public function get_turn_servers(?on_response: Turn_Servers -> Void) : Void {
     this.send_request(Conection.make_request(HttpMethod.GET, server + '/_matrix/client/r0/voip/turnServer', null), function ( status : Int, data: Turn_Servers ) : Void {
       on_response(data);
+    });
   }
 
   public function accept_call(call_id: String, other_call_id: String): Bool {

+ 9 - 0
src/beartek/matrix_im/client/types/Device.hx

@@ -0,0 +1,9 @@
+//Under GNU AGPL v3, see LICENCE
+package beartek.matrix_im.client.types;
+
+typedef Device = {
+  var device_id : String;
+  @:optional var display_name : String;
+  @:optional var last_seen_ip : String;
+  @:optional var last_seen_ts : Int;
+};

+ 0 - 0
src/beartek/matrix_im/client/types/Room.hx


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio