diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-10-05 01:44:25 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-10-05 01:44:25 +0200 |
commit | 2444ac841fad00133f231e9667ab427c4ce4d39e (patch) | |
tree | f85d6a82d7aed6aa4d758fc3045858ec8f4452bc /src/gui | |
parent | cabc0995c0e0964ecbef18470c6a483022879071 (diff) | |
download | ephraim-2444ac841fad00133f231e9667ab427c4ce4d39e.tar ephraim-2444ac841fad00133f231e9667ab427c4ce4d39e.zip |
Receiving messages works again (kinda)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/Conversation.vala | 2 | ||||
-rw-r--r-- | src/gui/CoreConnector.vala | 90 | ||||
-rw-r--r-- | src/gui/Ephraim.vala | 22 |
3 files changed, 62 insertions, 52 deletions
diff --git a/src/gui/Conversation.vala b/src/gui/Conversation.vala index 7c8dc03..926ed3d 100644 --- a/src/gui/Conversation.vala +++ b/src/gui/Conversation.vala @@ -62,7 +62,7 @@ public class Conversation { conversations.remove(widget); } - public void chat_message(string type, string from, string message) { + public void chat_message(string from, string type, string message) { if(type != "chat") return; 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()); diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala index 5801966..fb5e77f 100644 --- a/src/gui/Ephraim.vala +++ b/src/gui/Ephraim.vala @@ -17,7 +17,7 @@ public class Ephraim { unowned Gtk.TreeView rosterView = builder.get_object("Roster") as Gtk.TreeView; - Gee.TreeMap<string, Conversation> conversations = new Gee.TreeMap<string, Conversation>(); + Gee.TreeMap<Eva.Ref, Conversation> conversations = new Gee.TreeMap<Eva.Ref, Conversation>(); unowned Gtk.Notebook conversationNotebook = builder.get_object("Conversations") as Gtk.Notebook; ContactList roster = new ContactList(rosterView); @@ -28,24 +28,22 @@ public class Ephraim { coreconn.update_contact.connect(roster.update_contact); - coreconn.new_conversation.connect((jid) => { + coreconn.new_conversation.connect((conv_ref, jid) => { Contact contact = roster.get_contact(jid); - if(contact != null) { - conversations[jid] = new Conversation(conversationNotebook, jid, contact.display_string); - } - else { - conversations[jid] = new Conversation(conversationNotebook, jid, null); - } + Conversation conv = new Conversation(conversationNotebook, jid, contact != null ? contact.display_string : null); - conversations[jid].send_message.connect((type, message) => coreconn.send_message(jid, type, message)); + conversations[conv_ref] = conv; + conv.send_message.connect((type, message) => coreconn.send_message(jid, type, message)); }); - coreconn.chat_message.connect((jid, type, from, message) => { - if(!(jid in conversations.keys)) + coreconn.chat_message.connect((conv_ref, from, type, message) => { + if(!(conv_ref in conversations.keys)) { + warn_if_reached(); return; + } - conversations[jid].chat_message(type, from, message); + conversations[conv_ref].chat_message(from, type, message); }); //if(!coreconn.start()) |