Fix message types to always have a body

This commit is contained in:
Gergely Polonkai 2016-03-17 17:02:44 +01:00 committed by Gergely Polonkai
parent 5254776d4f
commit 3bc8735eb5
4 changed files with 59 additions and 3 deletions

View File

@ -81,6 +81,9 @@ public abstract class Matrix.Message.Base : Object, Initable {
initialize_from_json(Json.Node json_data)
throws Matrix.Error
{
var gen = new Json.Generator();
gen.set_root(json_data);
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
throw new Matrix.Error.INVALID_FORMAT(
"The message is not valid");
@ -132,6 +135,12 @@ public abstract class Matrix.Message.Base : Object, Initable {
} else if (Config.DEBUG) {
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");
}
if (_body == null) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a message without body");
}
root.set_string_member("msgtype", _message_type);
}
}

View File

@ -25,4 +25,18 @@
* sender. This message could also be represented in a different
* 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);
}
}

View File

@ -28,4 +28,18 @@
* infinite-loop situations where two automated clients continuously
* 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);
}
}

View File

@ -21,4 +21,18 @@
*
* 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);
}
}