Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tong committed Apr 11, 2024
1 parent 8cc8d2b commit bd21c49
Show file tree
Hide file tree
Showing 28 changed files with 1,788 additions and 1,642 deletions.
25 changes: 12 additions & 13 deletions src/xmpp/Attention.hx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package xmpp;

/**
Extension for getting the attention of another user.
Extension for getting the attention of another user.
[XEP-0224: Attention](https://xmpp.org/extensions/xep-0224.html)
[XEP-0224: Attention](https://xmpp.org/extensions/xep-0224.html)
**/
@xep(224)
class Attention {

public static inline var XMLNS = "urn:xmpp:attention:0";

/**
Sends a message packet to the given entity inluding a property to get attention.
Sends a message packet to the given entity inluding a property to get attention.
**/
public static inline function captureAttention(message : xmpp.Message) : xmpp.Message {
message.properties.push(XML.create("attention").set('xmlns', XMLNS));
return message;
public static inline function captureAttention(message:xmpp.Message):xmpp.Message {
message.properties.push(XML.create("attention").set('xmlns', XMLNS));
return message;
}

/**
Return `true` if the message stanza includes an `<attention/>` element.
**/
public static inline function wantsAttention(message : xmpp.Message) : Bool {
return message.properties.filter(e -> return e.is(XMLNS)).length > 0;
}
/**
Return `true` if the message stanza includes an `<attention/>` element.
**/
public static inline function wantsAttention(message:xmpp.Message):Bool {
return message.properties.filter(e -> return e.is(XMLNS)).length > 0;
}
}
46 changes: 23 additions & 23 deletions src/xmpp/Block.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ package xmpp;
import xmpp.IQ;

/**
Extension for communicatin blocking.
Extension for communicatin blocking.
[XEP-0191: Blocking Command](https://xmpp.org/extensions/xep-0191.html)
[XEP-0191: Blocking Command](https://xmpp.org/extensions/xep-0191.html)
**/
@xep(191)
class Block {

public static inline var XMLNS = 'urn:xmpp:blocking';

/**
Load list of blocked entities.
**/
public static inline function getBlocklist(stream: xmpp.Stream, handler: xmpp.Response<XML>->Void) : IQ {
return stream.get(Payload.create(XMLNS, "blocklist"), handler);
}
/**
Load list of blocked entities.
**/
public static inline function getBlocklist(stream:xmpp.Stream, handler:xmpp.Response<XML>->Void):IQ {
return stream.get(Payload.create(XMLNS, "blocklist"), handler);
}

/**
Block recieving stanzas from entity.
**/
public static inline function block(stream: xmpp.Stream, jid: Jid, handler: xmpp.Response<XML>->Void) : IQ {
return stream.set(Payload.create(XMLNS, "block").append(XML.create('item').set('jid', jid)), handler);
}
/**
Block recieving stanzas from entity.
**/
public static inline function block(stream:xmpp.Stream, jid:Jid, handler:xmpp.Response<XML>->Void):IQ {
return stream.set(Payload.create(XMLNS, "block").append(XML.create('item').set('jid', jid)), handler);
}

/**
Unblock recieving stanzas from entity.
**/
public static function unblock(stream: Stream, ?jid: Jid, handler: xmpp.Response<XML>->Void) : IQ {
var x = IQ.Payload.create(XMLNS, "unblock");
if(jid != null) x.append(XML.create('item').set('jid', jid));
return stream.set(x, handler);
}
/**
Unblock recieving stanzas from entity.
**/
public static function unblock(stream:Stream, ?jid:Jid, handler:xmpp.Response<XML>->Void):IQ {
var x = IQ.Payload.create(XMLNS, "unblock");
if (jid != null)
x.append(XML.create('item').set('jid', jid));
return stream.set(x, handler);
}
}
227 changes: 121 additions & 106 deletions src/xmpp/DataForm.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xmpp;

enum abstract FormType(String) from String to String {

/**
The form-submitting entity has cancelled submission of data to the form-processing entity.
**/
Expand All @@ -27,12 +26,11 @@ enum abstract FormType(String) from String to String {
}

enum abstract FieldType(String) from String to String {

/**
The field enables an entity to gather or provide an either-or choice between two options.
The default value is `false`.
**/
var boolean; //TODO java throws error
var boolean; // TODO java throws error

/**
The field is intended for data description (e.g., human-readable text such as "section" headers) rather than data gathering or provision.
Expand Down Expand Up @@ -74,7 +72,7 @@ enum abstract FieldType(String) from String to String {
var list_single = "list-single";

/**
The field enables an entity to gather or provide multiple lines of text.
The field enables an entity to gather or provide multiple lines of text.
**/
var text_multi = "text-multi";

Expand All @@ -92,126 +90,143 @@ enum abstract FieldType(String) from String to String {
}

private typedef FieldOption = {
var ?label : String;
var value : String;
var ?label:String;
var value:String;
}

typedef Field = {
/** **/
var ?label:String;

/** **/
var ?label : String;
/** **/
var ?type:FieldType;

/** **/
var ?type : FieldType;
/** **/
@:native('var') var ?variable:String;

/** **/
@:native('var') var ?variable : String;
/** **/
var ?options:Array<FieldOption>;

/** **/
var ?options : Array<FieldOption>;
/** Provides a natural-language description of the field. **/
var ?desc:String;

/** Provides a natural-language description of the field. **/
var ?desc : String;
/** **/
var ?values:Array<String>;

/** **/
var ?values : Array<String>;

/** Flags the field as required in order for the form to be considered valid. **/
var ?required : Bool;
/** Flags the field as required in order for the form to be considered valid. **/
var ?required:Bool;
}

@:structInit private class TDataForm {
public var type : FormType;
public var title : String;
public var instructions : String;
public var fields : Array<Field>;
public var reported : Array<Field>;
public var items : Array<Array<Field>>;
public function new(type:FormType, ?title:String, ?instructions:String, ?fields:Array<Field>, ?reported:Array<Field>, ?items:Array<Array<Field>>) {
this.type = type;
this.title = title;
this.instructions = instructions;
this.fields = fields ?? [];
this.reported = reported ?? [];
this.items = items ?? [];
}
public var type:FormType;
public var title:String;
public var instructions:String;
public var fields:Array<Field>;
public var reported:Array<Field>;
public var items:Array<Array<Field>>;

public function new(type:FormType, ?title:String, ?instructions:String, ?fields:Array<Field>, ?reported:Array<Field>, ?items:Array<Array<Field>>) {
this.type = type;
this.title = title;
this.instructions = instructions;
this.fields = fields ?? [];
this.reported = reported ?? [];
this.items = items ?? [];
}
}

/**
Data forms that can be used in workflows such as service configuration as well as for application-specific data description and reporting.
Data forms that can be used in workflows such as service configuration as well as for application-specific data description and reporting.
[XEP-0004: Data Forms](https://xmpp.org/extensions/xep-0004.html)
[XEP-0004: Data Forms](https://xmpp.org/extensions/xep-0004.html)
**/
@:forward
abstract DataForm(TDataForm) from TDataForm to TDataForm {

public static inline var XMLNS = "jabber:x:data";

public inline function new(type:FormType, ?title:String, ?instructions:String, ?fields:Array<Field>, ?items:Array<Array<Field>>)
this = new TDataForm(type, title, instructions, fields, items);

@:to public function toXML() : XML {
function fieldToXML(f:Field) : XML {
final c = XML.create("field");
if(f.variable != null) c.set("var", f.variable);
if(f.label != null) c.set("label", f.label);
if(f.type != null) c.set("type", f.type);
if(f.options != null) for(o in f.options) {
var e = XML.create("option");
if(o.label != null) e.set("label", o.label);
e.append(XML.create("value", o.value));
c.append(e);
}
if(f.desc != null) c.set("desc", f.desc);
if(f.values != null) for(v in f.values) c.append(XML.create("value",v));
return c;
}
final xml = XML.create("x").set("xmlns", XMLNS).set("type", this.type);
if(this.title != null) xml.append(XML.create("title", this.title));
if(this.instructions != null) xml.append(XML.create("instructions", this.instructions));
for(f in this.fields) xml.append(fieldToXML(f));
if(this.reported.length > 0) {
final e = XML.create("reported");
for(f in this.reported) e.append(fieldToXML(f));
xml.append(e);
}
return xml;
}

@:from public static function fromXML(xml:XML) : DataForm {
function parseField(e:XML) : Field {
final f : Field = {
type: e["type"],
label: e["label"],
variable: e["var"],
options: []
};
for(e in e.elements) {
switch e.name {
case "desc": f.desc = e.text;
case "option": f.options.push({
label: e["label"],
value: e.firstElement.text
});
case "required": f.required = true;
}
}
return f;
}
final form = new DataForm(xml.get("type"));
for(e in xml.elements) {
public static inline var XMLNS = "jabber:x:data";

public inline function new(type:FormType, ?title:String, ?instructions:String, ?fields:Array<Field>, ?items:Array<Array<Field>>)
this = new TDataForm(type, title, instructions, fields, items);

@:to public function toXML():XML {
function fieldToXML(f:Field):XML {
final c = XML.create("field");
if (f.variable != null)
c.set("var", f.variable);
if (f.label != null)
c.set("label", f.label);
if (f.type != null)
c.set("type", f.type);
if (f.options != null)
for (o in f.options) {
var e = XML.create("option");
if (o.label != null)
e.set("label", o.label);
e.append(XML.create("value", o.value));
c.append(e);
}
if (f.desc != null)
c.set("desc", f.desc);
if (f.values != null)
for (v in f.values)
c.append(XML.create("value", v));
return c;
}
final xml = XML.create("x").set("xmlns", XMLNS).set("type", this.type);
if (this.title != null)
xml.append(XML.create("title", this.title));
if (this.instructions != null)
xml.append(XML.create("instructions", this.instructions));
for (f in this.fields)
xml.append(fieldToXML(f));
if (this.reported.length > 0) {
final e = XML.create("reported");
for (f in this.reported)
e.append(fieldToXML(f));
xml.append(e);
}
return xml;
}

@:from public static function fromXML(xml:XML):DataForm {
function parseField(e:XML):Field {
final f:Field = {
type: e["type"],
label: e["label"],
variable: e["var"],
options: []
};
for (e in e.elements) {
switch e.name {
case "desc":
f.desc = e.text;
case "option":
f.options.push({
label: e["label"],
value: e.firstElement.text
});
case "required":
f.required = true;
}
}
return f;
}
final form = new DataForm(xml.get("type"));
for (e in xml.elements) {
switch e.name {
case "title": form.title = e.text;
case "field": form.fields.push(parseField(e));
case "item":
for(e in e.elements)
form.items.push([for(e in e.elements) parseField(e)]);
case "instructions": form.instructions = e.text;
case "reported":
for(e in e.elements)
form.reported.push(parseField(e));
}
}
return form;
}
case "title":
form.title = e.text;
case "field":
form.fields.push(parseField(e));
case "item":
for (e in e.elements)
form.items.push([for (e in e.elements) parseField(e)]);
case "instructions":
form.instructions = e.text;
case "reported":
for (e in e.elements)
form.reported.push(parseField(e));
}
}
return form;
}
}
Loading

0 comments on commit bd21c49

Please sign in to comment.