|
@@ -14,13 +14,10 @@ import beartek.matrix_im.client.types.enums.Directions;
|
|
|
|
|
|
class Rooms extends Handler {
|
|
|
public var joined_rooms : Array<Room>;
|
|
|
+ public var typing_on: Map<Room, Bool>;
|
|
|
|
|
|
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.list(function( rooms : Array<Room> ) : Void {
|
|
|
- this.joined_rooms = rooms;
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
public inline function create( ?visibility : Visibilities, ?alias : String, ?name : String, ?topic : String, ?invite : Array<String>, ?invite_3pid : Array<{id_server : String, medium : String, address: String}>, ?creation_content: Dynamic, ?initial_state : Array<{type: String, state_key: String, content: String}>, ?preset : Room_preset, is_direct : Bool = false, on_response : Room -> Void ) : Void {
|
|
@@ -40,6 +37,27 @@ class Rooms extends Handler {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public inline function typing(room : Room, user : User, timeout=3000, stop=false, on_response : Bool -> Void) {
|
|
|
+ this.send_request(Conection.make_request('PUT', this.server + '/_matrix/client/r0/rooms/' + room + '/typing/' + user, {typing: if(stop) false else true, timeout: timeout}), function( status : Int, data : Dynamic ) : Void {
|
|
|
+ on_response(if(stop) false else true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ } else if(typing_on[room] == false) {
|
|
|
+ this.typing(room, user, time, true);
|
|
|
+ typing_on[room] == null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ haxe.Timer.delay(time, function (){
|
|
|
+ check_typing(time, user);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public inline function invite( room : Room, user : User, on_response : Void -> Void ) : Void {
|
|
|
this.send_request(Conection.make_request('POST', this.server + '/_matrix/client/r0/rooms/' + room + '/invite', {user_id: user.toString()}), function( status : Int, data : Dynamic ) : Void {
|
|
|
on_response();
|
|
@@ -82,12 +100,19 @@ class Rooms extends Handler {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public inline function list( on_response : Array<Room> -> Void ) : Void {
|
|
|
this.send_request(Conection.make_request('GET', this.server + '/_matrix/client/r0/joined_rooms', null), function( status : Int, data : {joined_rooms: Array<String>} ) : Void {
|
|
|
on_response(data.joined_rooms.map(Room.new));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public inline function update_joined_room() {
|
|
|
+ this.list(function( rooms : Array<Room> ) : Void {
|
|
|
+ this.joined_rooms = rooms;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public inline function list_public( ?server : String, limit: Int = 100, ?since : String, ?search : String, on_response : Array<{aliases: Array<String>, canonical_alias: String, name: String, num_joined_members: Int, room_id: String, topic: String, world_readable: Bool, guest_can_join: Bool, avatar_url: String}> -> String -> String -> Int -> Void ) : Void {
|
|
|
var req : Dynamic = {limit: limit};
|
|
|
if(server != null) req.server = server;
|
|
@@ -137,6 +162,41 @@ class Rooms extends Handler {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public inline function get_display_names(members: Map<String,{display_name: String, avatar_url: String}>): Map<String,{id: User, avatar_url: String}> {
|
|
|
+ var result: Map<String,{id: User, avatar_url: String}> = new Map();
|
|
|
+
|
|
|
+ for(id in members.keys()) {
|
|
|
+ result = check_name_collision(result, {id: new User(id), display_name: members[id].display_name, avatar_url: members[id].avatar_url});
|
|
|
+ };
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public inline function get_display_names_events(events: Array<Event<m.room.Member>>): Map<String,{id: User, avatar_url: String}> {
|
|
|
+ //TODO: memberships and is_direct
|
|
|
+ var result: Map<String,{id: User, avatar_url: String}> = new Map();
|
|
|
+
|
|
|
+ for(e in events) {
|
|
|
+ result = check_name_collision(result, {id: new User(e.state_key), display_name: e.content.displayname, avatar_url: e.content.avatar_url});
|
|
|
+ };
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function check_name_collision(members: Map<String,{id: User, avatar_url: String}>, new_member: {id: User, display_name: String, avatar_url: String}): Map<String,{id: User, avatar_url: String}> {
|
|
|
+ //TODO: This algo only works on pairs numbers of collisions
|
|
|
+ if(new_member.display_name != null) {
|
|
|
+ if(members[new_member.display_name] != null) {
|
|
|
+ members[new_member.display_name + ' (' + members[new_member.display_name].id + ')'] = members[new_member.display_name];
|
|
|
+ members[new_member.display_name + ' (' + new_member.id + ')'] = {id: new_member.id, avatar_url: new_member.avatar_url};
|
|
|
+ members[new_member.display_name] = null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ members[new_member.id] = {id: new_member.id, avatar_url: new_member.avatar_url};
|
|
|
+ }
|
|
|
+ return members;
|
|
|
+ }
|
|
|
+
|
|
|
public inline function get_messages( room : Room, from : String, ?to : String, dir : Directions, limit : Int = 10, ?filter : Dynamic, on_response : Array<Event<Dynamic>> -> Void ) : Void {
|
|
|
this.send_request(Conection.make_request('GET', server + '/_matrix/client/r0/rooms/' + room + '/messages', {from: from, to: to, dir: dir, limit: limit, filter: filter}), function( status : Int, data : Dynamic ) : Void {
|
|
|
on_response(data.chunk);
|