summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/ephraim_conv.erl16
-rw-r--r--src/core/ephraim_gui.erl1
-rw-r--r--src/gui/Conversation.vala16
-rw-r--r--src/gui/CoreConnector.vala61
-rw-r--r--src/gui/Ephraim.vala10
5 files changed, 47 insertions, 57 deletions
diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl
index dbf84c8..199787a 100644
--- a/src/core/ephraim_conv.erl
+++ b/src/core/ephraim_conv.erl
@@ -2,14 +2,16 @@
-compile([debug_info, export_all]).
-record(conv_state, {
- jid :: binary()
+ my_jid :: binary(),
+ jid :: binary()
}).
-spec init(binary()) -> ok.
init(JID) ->
io:format("Starting a conversation with ~p~n", [JID]),
- loop(#conv_state{jid=JID}),
+ {jid,MyJID} = ephraim_config:get(jid),
+ loop(#conv_state{my_jid=list_to_binary(MyJID),jid=JID}),
io:format("Stopping a conversation with ~p~n", [JID]).
-spec loop(#conv_state{}) -> ok.
@@ -21,8 +23,12 @@ loop(State) ->
{receive_message, Packet} ->
Type = exmpp_message:get_type(Packet),
Body = exmpp_message:get_body(Packet),
- %io:format("Received message from ~p:~n~p~n", [State#conv_state.jid, Packet]),
- ephraim ! {ui_update, {receive_message, State#conv_state.jid, Type, Body}},
+ if
+ Body =/= undefined ->
+ ephraim ! {ui_update, {chat_message, State#conv_state.jid, Type, State#conv_state.jid, Body}};
+ true ->
+ io:format("Received strange message from ~p:~n~p~n", [State#conv_state.jid, Packet])
+ end,
loop(State);
{send_message, Type, Message} ->
@@ -30,7 +36,7 @@ loop(State) ->
Packet2 = exmpp_message:set_type(Packet, Type),
Packet3 = exmpp_xml:set_attribute(Packet2, to, State#conv_state.jid),
ephraim ! {send_packet, Packet3},
- ephraim ! {ui_update, {sent_message, State#conv_state.jid, Type, Message}},
+ ephraim ! {ui_update, {chat_message, State#conv_state.jid, Type, State#conv_state.my_jid, Message}},
loop(State);
Msg ->
diff --git a/src/core/ephraim_gui.erl b/src/core/ephraim_gui.erl
index 79433e0..8ee56b8 100644
--- a/src/core/ephraim_gui.erl
+++ b/src/core/ephraim_gui.erl
@@ -3,6 +3,7 @@
-spec init() -> ok.
init() ->
+ {jid,JID} = ephraim_config:get(jid),
Port = open_port({spawn_executable, "ephraim-gtk"}, [binary, nouse_stdio, {packet, 4}]),
ephraim ! {register_ui, self()},
loop(Port),
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())