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.vala56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 7486aec..1030428 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -69,7 +69,7 @@ public class CoreConnector {
// Do nothing
break;
case Erl.ReceiveType.MSG:
- Idle.add(() => {handleTerm(response); return false;});
+ Idle.add(() => {handle_term(response); return false;});
break;
}
}
@@ -86,12 +86,15 @@ public class CoreConnector {
return null;
}
- private void handleTerm(TermStore store) {
+ private void handle_term(TermStore store) {
unowned Erl.Term term = store.term;
Erl.Term match_term;
if((match_term = match("{roster_update,JID,Name,Subscription,Groups,Resources}", term)) != null) {
Erl.Term jid_term = match_term.var_content("JID");
+ if(!jid_term.is_binary())
+ // TODO Debug output
+ return;
string jid = ((string)jid_term.bin_ptr()).ndup(jid_term.bin_size());
Erl.Term name_term = match_term.var_content("Name");
@@ -101,7 +104,54 @@ public class CoreConnector {
else
name = null;
- roster.update_contact(new Contact(jid, name));
+ Contact contact = new Contact(jid, name);
+
+ Erl.Term resources = match_term.var_content("Resources");
+
+ while(resources.is_cons()) {
+ Erl.Term r;
+
+ if((r = match("{Name,{resource_entry,Priority,Show,Status}}", resources.hd())) != null) {
+ Erl.Term rname_term = r.var_content("Name");
+ Erl.Term prio_term = r.var_content("Priority");
+ Erl.Term show_term = r.var_content("Show");
+ Erl.Term status_term = r.var_content("Status");
+
+ if(rname_term.is_binary() && prio_term.is_integer() && show_term.is_atom()) {
+ string rname = ((string)rname_term.bin_ptr()).ndup(rname_term.bin_size());
+ int prio = prio_term.int_value();
+
+ Contact.Show show = Contact.Show.UNDEFINED;
+ switch((string)show_term.atom_ptr()) {
+ case "online":
+ show = Contact.Show.ONLINE;
+ break;
+ case "away":
+ show = Contact.Show.AWAY;
+ break;
+ case "chat":
+ show = Contact.Show.CHAT;
+ break;
+ case "dnd":
+ show = Contact.Show.DND;
+ break;
+ case "xa":
+ show = Contact.Show.XA;
+ break;
+ }
+
+ string? status = null;
+ if(status_term.is_binary())
+ status = ((string)status_term.bin_ptr()).ndup(status_term.bin_size());
+
+ contact.update_resource(rname, new Contact.Resource(prio, show, status));
+ }
+ }
+
+ resources = resources.tl();
+ }
+
+ roster.update_contact(contact);
}
else {
Erl.print_term(stdout, term);