Fix message types to always have a body
This commit is contained in:
parent
5254776d4f
commit
3bc8735eb5
@ -81,6 +81,9 @@ public abstract class Matrix.Message.Base : Object, Initable {
|
|||||||
initialize_from_json(Json.Node json_data)
|
initialize_from_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
throws Matrix.Error
|
||||||
{
|
{
|
||||||
|
var gen = new Json.Generator();
|
||||||
|
gen.set_root(json_data);
|
||||||
|
|
||||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||||
throw new Matrix.Error.INVALID_FORMAT(
|
throw new Matrix.Error.INVALID_FORMAT(
|
||||||
"The message is not valid");
|
"The message is not valid");
|
||||||
@ -132,6 +135,12 @@ public abstract class Matrix.Message.Base : Object, Initable {
|
|||||||
} else if (Config.DEBUG) {
|
} else if (Config.DEBUG) {
|
||||||
warning("msgtype is not present in a message");
|
warning("msgtype is not present in a message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((node = root.get_member("body")) != null) {
|
||||||
|
_body = node.get_string();
|
||||||
|
} else if (Config.DEBUG) {
|
||||||
|
warning("body is not presente in a message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,6 +158,11 @@ public abstract class Matrix.Message.Base : Object, Initable {
|
|||||||
"Won't generate a message with an empty msgtype");
|
"Won't generate a message with an empty msgtype");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_body == null) {
|
||||||
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
|
"Won't generate a message without body");
|
||||||
|
}
|
||||||
|
|
||||||
root.set_string_member("msgtype", _message_type);
|
root.set_string_member("msgtype", _message_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,18 @@
|
|||||||
* sender. This message could also be represented in a different
|
* sender. This message could also be represented in a different
|
||||||
* colour to distinguish it from regular `m.text` messages.
|
* colour to distinguish it from regular `m.text` messages.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Message.Emote : Matrix.Message.Base {}
|
public class Matrix.Message.Emote : Matrix.Message.Base {
|
||||||
|
public override void
|
||||||
|
from_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.from_json(json_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void
|
||||||
|
to_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -28,4 +28,18 @@
|
|||||||
* infinite-loop situations where two automated clients continuously
|
* infinite-loop situations where two automated clients continuously
|
||||||
* exchange messages, as each responds to the other.
|
* exchange messages, as each responds to the other.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Message.Notice : Matrix.Message.Base {}
|
public class Matrix.Message.Notice : Matrix.Message.Base {
|
||||||
|
public override void
|
||||||
|
from_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.from_json(json_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void
|
||||||
|
to_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,4 +21,18 @@
|
|||||||
*
|
*
|
||||||
* Handle plain text messages.
|
* Handle plain text messages.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Message.Text : Matrix.Message.Base {}
|
public class Matrix.Message.Text : Matrix.Message.Base {
|
||||||
|
public override void
|
||||||
|
from_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.from_json(json_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void
|
||||||
|
to_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user