summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-07-17 20:20:02 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-07-17 20:20:02 +0200
commit0aac619ba4dccd81018bddaa4690213b14cfe2b6 (patch)
treecd21aa85f777f45f8b6ab9f01dbd73cfc5f1d2b5 /src/gui
parentdfc0469a184ae978f40cac9df20d399fdeca99a3 (diff)
downloadephraim-0aac619ba4dccd81018bddaa4690213b14cfe2b6.tar
ephraim-0aac619ba4dccd81018bddaa4690213b14cfe2b6.zip
Moved some message handling from GUI to core
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/Conversation.vala16
-rw-r--r--src/gui/CoreConnector.vala61
-rw-r--r--src/gui/Ephraim.vala10
3 files changed, 35 insertions, 52 deletions
diff --git a/src/gui/Conversation.vala b/src/gui/Conversation.vala
index 811fa5c..246aba0 100644
--- a/src/gui/Conversation.vala
+++ b/src/gui/Conversation.vala
@@ -64,23 +64,11 @@ public class Conversation {
conversations.remove(widget);
}
- public void sent_message(string type, string message) {
+ public void chat_message(string type, string from, string message) {
if(type != "chat")
return;
- string str = me + ": " + message;
-
- if(content.buffer.text.length != 0)
- str = "\n" + str;
-
- content.buffer.text += str;
- }
-
- public void receive_message(string type, string message) {
- if(type != "chat")
- return;
-
- string str = display_name + ": " + message;
+ string str = from + ": " + message;
if(content.buffer.text.length != 0)
str = "\n" + str;
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 445f097..5566686 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -1,26 +1,25 @@
public class CoreConnector {
+ static Eva.Term match_gui_init;
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_receive_message;
- static Eva.Term match_sent_message;
+ static Eva.Term match_chat_message;
static construct {
+ match_gui_init = Eva.parse("{gui_init,Terms}");
match_roster_update = Eva.parse("{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_receive_message = Eva.parse("{receive_message,JID,Type,Body}");
- match_sent_message = Eva.parse("{sent_message,JID,Type,Body}");
+ match_chat_message = Eva.parse("{chat_message,JID,Type,From,Body}");
}
Eva.PacketHandler con;
public signal void update_contact(Contact contact);
public signal void new_conversation(string jid);
- public signal void receive_message(string jid, string type, string message);
- public signal void sent_message(string jid, string type, string message);
+ public signal void chat_message(string jid, string from, string type, string message);
public void start() {
con = new Eva.PacketHandler(new UnixInputStream(3, true), new UnixOutputStream(4, true), 4);
@@ -41,7 +40,26 @@ public class CoreConnector {
private void handle_term(Eva.Term term) {
Gee.Map<string, Eva.Term> match;
- if((match = term.match(match_roster_update)) != null) {
+ if((match = term.match(match_gui_init)) != null) {
+ Eva.Cons terms = match["Terms"] as Eva.Cons;
+
+ while(terms != null) {
+ Eva.Tuple tuple = terms.head as Eva.Tuple;
+
+ if(tuple != null && tuple.size > 0) {
+ Eva.Atom key = tuple[0] as Eva.Atom;
+
+ /*if(key != null) {
+ switch(key.value) {
+ // None yet
+ }
+ }*/
+ }
+
+ terms = terms.tail as Eva.Cons;
+ }
+ }
+ else if((match = term.match(match_roster_update)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
if(jid_term == null) {
warn_if_reached();
@@ -140,7 +158,7 @@ public class CoreConnector {
new_conversation(jid);
}
- else if((match = term.match(match_receive_message)) != null) {
+ else if((match = term.match(match_chat_message)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
if(jid_term == null) {
warn_if_reached();
@@ -155,29 +173,12 @@ public class CoreConnector {
}
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);
-
- receive_message(jid, type, body);
- }
- else if((match = term.match(match_sent_message)) != null) {
- Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null) {
+ Eva.Binary from_term = match["From"] as Eva.Binary;
+ if(from_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;
- }
- string type = type_term.value;
+ string from = from_utf8(from_term);
Eva.Binary body_term = match["Body"] as Eva.Binary;
if(body_term == null) {
@@ -186,10 +187,10 @@ public class CoreConnector {
}
string body = from_utf8(body_term);
- sent_message(jid, type, body);
+ chat_message(jid, type, from, body);
}
else {
- stdout.printf("%s\n", term.to_string());
+ stdout.printf("Received unhandled term: %s\n", term.to_string());
}
}
diff --git a/src/gui/Ephraim.vala b/src/gui/Ephraim.vala
index 50f83e1..c75d926 100644
--- a/src/gui/Ephraim.vala
+++ b/src/gui/Ephraim.vala
@@ -44,17 +44,11 @@ public class Ephraim {
conversations[jid].send_message.connect((type, message) => coreconn.send_message(jid, type, message));
});
- coreconn.receive_message.connect((jid, type, message) => {
+ coreconn.chat_message.connect((jid, type, from, message) => {
if(!(jid in conversations))
return;
- conversations[jid].receive_message(type, message);
- });
- coreconn.sent_message.connect((jid, type, message) => {
- if(!(jid in conversations))
- return;
-
- conversations[jid].sent_message(type, message);
+ conversations[jid].chat_message(type, from, message);
});
//if(!coreconn.start())