summaryrefslogtreecommitdiffstats
path: root/src/gui/CoreConnector.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/CoreConnector.vala')
-rw-r--r--src/gui/CoreConnector.vala90
1 files changed, 51 insertions, 39 deletions
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 4c853ff..46c94f2 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -1,25 +1,27 @@
public class CoreConnector {
- static Eva.Term match_gui_init;
+ static Eva.Term match_init_view;
static Eva.Term match_roster_update;
static Eva.Term match_resource_entry;
static Eva.Term match_avatar;
- static Eva.Term match_new_conversation;
- static Eva.Term match_chat_message;
+ static Eva.Term match_conversation;
+ static Eva.Term match_conversation_new;
+ static Eva.Term match_conversation_message;
static construct {
- match_gui_init = Eva.parse("{global,{gui_init,Terms}}");
+ match_init_view = Eva.parse("{global,{init_view,Terms}}");
match_roster_update = Eva.parse("{account,Account,{roster_update,JID,Name,Subscription,Groups,Resources,Avatar}}");
match_resource_entry = Eva.parse("{Name,{resource_entry,Priority,Show,Status}}");
match_avatar = Eva.parse("{avatar,Data}");
- match_new_conversation = Eva.parse("{new_conversation,JID}");
- match_chat_message = Eva.parse("{chat_message,JID,Type,From,Body}");
+ match_conversation = Eva.parse("{account,Account,{conversation,Ref,Message}}");
+ match_conversation_new = Eva.parse("{new,JID}");
+ match_conversation_message = Eva.parse("{message,From,Type,Body}");
}
Eva.PacketHandler con;
public signal void update_contact(Contact contact);
- public signal void new_conversation(string jid);
- public signal void chat_message(string jid, string from, string type, string message);
+ public signal void new_conversation(Eva.Ref conv_ref, string jid);
+ public signal void chat_message(Eva.Ref conv_ref, string from, string type, string message);
public void start() {
con = new Eva.PacketHandler(new UnixInputStream(3, true), new UnixOutputStream(4, true), 4);
@@ -43,7 +45,7 @@ public class CoreConnector {
private void handle_term(Eva.Term term) {
Gee.Map<string, Eva.Term> match;
- if((match = term.match(match_gui_init)) != null) {
+ if((match = term.match(match_init_view)) != null) {
Eva.Cons terms = match["Terms"] as Eva.Cons;
while(terms != null) {
@@ -175,46 +177,56 @@ public class CoreConnector {
}
update_contact(contact);
}
- else if((match = term.match(match_new_conversation)) != null) {
- Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null) {
+ else if((match = term.match(match_conversation)) != null) {
+ Eva.Ref conv_ref = match["Ref"] as Eva.Ref;
+ if(conv_ref == null) {
warn_if_reached();
return;
}
- string jid = from_utf8(jid_term);
-
- new_conversation(jid);
- }
- else if((match = term.match(match_chat_message)) != null) {
- Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null) {
+ Eva.Term message_term = match["Message"];
+ if(message_term == null) {
warn_if_reached();
return;
}
- string jid = from_utf8(jid_term);
-
- Eva.Atom type_term = match["Type"] as Eva.Atom;
- if(type_term == null) {
- warn_if_reached();
- return;
+
+ Gee.Map<string, Eva.Term> cmatch;
+ if((cmatch = message_term.match(match_conversation_new)) != null) {
+ Eva.Binary jid_term = cmatch["JID"] as Eva.Binary;
+ if(jid_term == null) {
+ warn_if_reached();
+ return;
+ }
+
+ string jid = from_utf8(jid_term);
+ new_conversation(conv_ref, jid);
}
- string type = type_term.value;
+ else if((cmatch = message_term.match(match_conversation_message)) != null) {
+ Eva.Binary from_term = cmatch["From"] as Eva.Binary;
+ if(from_term == null) {
+ warn_if_reached();
+ return;
+ }
+ string from = from_utf8(from_term);
- Eva.Binary from_term = match["From"] as Eva.Binary;
- if(from_term == null) {
- warn_if_reached();
- return;
- }
- string from = from_utf8(from_term);
+ Eva.Atom type_term = cmatch["Type"] as Eva.Atom;
+ if(type_term == null) {
+ warn_if_reached();
+ return;
+ }
+ string type = type_term.value;
- Eva.Binary body_term = match["Body"] as Eva.Binary;
- if(body_term == null) {
- warn_if_reached();
- return;
- }
- string body = from_utf8(body_term);
+ Eva.Binary body_term = cmatch["Body"] as Eva.Binary;
+ if(body_term == null) {
+ warn_if_reached();
+ return;
+ }
+ string body = from_utf8(body_term);
- chat_message(jid, type, from, body);
+ chat_message(conv_ref, from, type, body);
+ }
+ else {
+ stdout.printf("Received unhandled term: %s\n", term.to_string());
+ }
}
else {
stdout.printf("Received unhandled term: %s\n", term.to_string());