[/trunk] Changeset 137 by mikael
* Implement /add command, partially.
--- a/mcabber/src/TODO.txt Tue Apr 26 10:11:57 2005 +0000
+++ b/mcabber/src/TODO.txt Tue Apr 26 20:05:14 2005 +0000
@@ -5,6 +5,7 @@
* Pending message not displayed if buddy outside Contact window
* We should rebuild the buddy list when receiving a message from an offline
buddy (or invisible/just hidden).
+* When adding a user, we do not sent to him any presence notification...
TODO:
--- a/mcabber/src/commands.c Tue Apr 26 10:11:57 2005 +0000
+++ b/mcabber/src/commands.c Tue Apr 26 20:05:14 2005 +0000
@@ -34,6 +34,7 @@
void do_roster(char *arg);
void do_clear(char *arg);
void do_status(char *arg);
+void do_add(char *arg);
// Global variable for the commands list
static GSList *Commands;
@@ -59,7 +60,7 @@
// ...
void cmd_init(void)
{
- //cmd_add("add");
+ cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
//cmd_add("del");
//cmd_add("group");
@@ -215,8 +216,7 @@
scr_DrawRoster();
} else if (!strcasecmp(arg, "show_offline")) {
buddylist_set_hide_offline_buddies(FALSE);
- if (current_buddy)
- buddylist_build();
+ buddylist_build();
scr_DrawRoster();
} else
scr_LogPrint("Unrecognized parameter!");
@@ -254,3 +254,14 @@
jb_setstatus(st, NULL); // TODO handle message (instead of NULL)
}
+void do_add(char *arg)
+{
+ if (!arg || (*arg == 0)) {
+ scr_LogPrint("Wrong usage");
+ return;
+ }
+
+ // FIXME check arg =~ jabber id
+ // 2nd parameter = optional nickname (XXX NULL for now...)
+ jb_addbuddy(arg, NULL);
+}
--- a/mcabber/src/jabglue.c Tue Apr 26 10:11:57 2005 +0000
+++ b/mcabber/src/jabglue.c Tue Apr 26 20:05:14 2005 +0000
@@ -283,6 +283,40 @@
jb_reset_keepalive();
}
+void jb_addbuddy(const char *jid, const char *group)
+{
+ xmlnode x, y, z;
+
+ // XXX Check jid (but perhaps caller should do it)
+
+ // We don't check if the jabber user already exists in the roster,
+ // because it allows to re-ask for notification.
+
+ //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL);
+ x = jutil_presnew(JPACKET__SUBSCRIBE, jid, "online");
+ jab_send(jc, x);
+ xmlnode_free(x);
+
+ x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
+ y = xmlnode_get_tag(x, "query");
+ z = xmlnode_insert_tag(y, "item");
+ xmlnode_put_attrib(z, "jid", jid);
+
+ if (group) {
+ z = xmlnode_insert_tag(z, "group");
+ xmlnode_insert_cdata(z, group, (unsigned) -1);
+ }
+
+ jab_send(jc, x);
+ xmlnode_free(x);
+
+ roster_add_user(jid, NULL, group, ROSTER_TYPE_USER);
+ buddylist_build();
+
+ // maybe not needed: if user appears his status will change
+ //update_roster = TRUE;
+}
+
void postlogin()
{
//int i;
--- a/mcabber/src/jabglue.h Tue Apr 26 10:11:57 2005 +0000
+++ b/mcabber/src/jabglue.h Tue Apr 26 20:05:14 2005 +0000
@@ -30,6 +30,7 @@
jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass);
void jb_disconnect(void);
void jb_main();
+void jb_addbuddy(const char *jid, const char *group);
inline enum imstatus jb_getstatus();
void jb_setstatus(enum imstatus st, char *msg);
void jb_send_msg(const char *, const char *);