The /status command can specify a status message
We can now use: "/status dnd On the phone..."
Related change: Display the buddy status message when a buddy connects/changes
his/her status.
--- a/mcabber/src/commands.c Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/commands.c Fri Jul 15 18:45:41 2005 +0100
@@ -368,27 +368,40 @@
void do_status(char *arg)
{
enum imstatus st;
+ int len;
+ char *msg;
if (!arg || (*arg == 0)) {
scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]);
return;
}
- if (!strcasecmp(arg, "offline")) st = offline;
- else if (!strcasecmp(arg, "online")) st = available;
- else if (!strcasecmp(arg, "avail")) st = available;
- else if (!strcasecmp(arg, "away")) st = away;
- else if (!strcasecmp(arg, "invisible")) st = invisible;
- else if (!strcasecmp(arg, "dnd")) st = dontdisturb;
- else if (!strcasecmp(arg, "notavail")) st = notavail;
- else if (!strcasecmp(arg, "free")) st = freeforchat;
+ msg = strchr(arg, ' ');
+ if (!msg)
+ len = strlen(arg);
+ else
+ len = msg - arg;
+
+ if (!strncasecmp(arg, "offline", len)) st = offline;
+ else if (!strncasecmp(arg, "online", len)) st = available;
+ else if (!strncasecmp(arg, "avail", len)) st = available;
+ else if (!strncasecmp(arg, "away", len)) st = away;
+ else if (!strncasecmp(arg, "invisible", len)) st = invisible;
+ else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb;
+ else if (!strncasecmp(arg, "notavail", len)) st = notavail;
+ else if (!strncasecmp(arg, "free", len)) st = freeforchat;
else {
scr_LogPrint("Unrecognized parameter!");
return;
}
- // XXX special case if offline??
- jb_setstatus(st, NULL); // TODO handle message (instead of NULL)
+ if (msg && st != offline && st != invisible) {
+ for (msg++ ; *msg && *msg == ' ' ; msg++) ;
+ if (!*msg) msg = NULL;
+ } else
+ msg = NULL;
+
+ jb_setstatus(st, msg);
}
void do_add(char *arg)
--- a/mcabber/src/hooks.c Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/hooks.c Fri Jul 15 18:45:41 2005 +0100
@@ -65,8 +65,9 @@
inline void hk_statuschange(const char *jid, time_t timestamp,
enum imstatus status, const char *status_msg)
{
- scr_LogPrint("Buddy status has changed: [%c>%c] <%s>",
- imstatus2char[roster_getstatus(jid)], imstatus2char[status], jid);
+ scr_LogPrint("Buddy status has changed: [%c>%c] <%s> %s",
+ imstatus2char[roster_getstatus(jid)], imstatus2char[status], jid,
+ ((status_msg) ? status_msg : ""));
roster_setstatus(jid, status, status_msg);
buddylist_build();
scr_DrawRoster();
@@ -74,13 +75,14 @@
}
inline void hk_mystatuschange(time_t timestamp,
- enum imstatus old_status, enum imstatus new_status)
+ enum imstatus old_status, enum imstatus new_status, const char *msg)
{
- if (old_status == new_status)
+ if (!msg && (old_status == new_status))
return;
- scr_LogPrint("Your status has changed: [%c>%c]",
- imstatus2char[old_status], imstatus2char[new_status]);
+ scr_LogPrint("Your status has changed: [%c>%c] %s",
+ imstatus2char[old_status], imstatus2char[new_status],
+ ((msg) ? msg : ""));
//hlog_write_status(NULL, 0, status);
}
--- a/mcabber/src/hooks.h Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/hooks.h Fri Jul 15 18:45:41 2005 +0100
@@ -10,7 +10,7 @@
inline void hk_statuschange(const char *jid, time_t timestamp,
enum imstatus status, char const *status_msg);
inline void hk_mystatuschange(time_t timestamp,
- enum imstatus old_status, enum imstatus new_status);
+ enum imstatus old_status, enum imstatus new_status, const char *msg);
void hk_ext_cmd_init(const char *command);
void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data);
--- a/mcabber/src/jabglue.c Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/jabglue.c Fri Jul 15 18:45:41 2005 +0100
@@ -311,7 +311,7 @@
if (mystatus == offline || st == offline)
update_roster = TRUE;
- hk_mystatuschange(0, mystatus, st);
+ hk_mystatuschange(0, mystatus, st, msg);
mystatus = st;
}
@@ -611,6 +611,7 @@
void packethandler(jconn conn, jpacket packet)
{
char *p, *r;
+ const char *m;
xmlnode x, y;
char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
char *ns=NULL;
@@ -861,7 +862,10 @@
p = NULL;
r = jidtodisp(from);
- if (ust != roster_getstatus(r))
+ m = roster_getstatusmsg(r);
+ // Call hk_statuschange() if status has changed or if the
+ // status message is different
+ if ((ust != roster_getstatus(r)) || (p && (!m || strcmp(p, m))))
hk_statuschange(r, 0, ust, p);
g_free(r);
break;
--- a/mcabber/src/roster.c Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/roster.c Fri Jul 15 18:45:41 2005 +0100
@@ -359,6 +359,19 @@
return roster_usr->status;
}
+const char *roster_getstatusmsg(const char *jid)
+{
+ GSList *sl_user;
+ roster *roster_usr;
+
+ sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
+ if (sl_user == NULL)
+ return offline; // Not in the roster, anyway...
+
+ roster_usr = (roster*)sl_user->data;
+ return roster_usr->status_msg;
+}
+
guint roster_gettype(const char *jid)
{
GSList *sl_user;
--- a/mcabber/src/roster.h Fri Jul 15 13:55:47 2005 +0100
+++ b/mcabber/src/roster.h Fri Jul 15 18:45:41 2005 +0100
@@ -41,6 +41,7 @@
void roster_msg_setflag(const char *jid, guint value);
void roster_settype(const char *jid, guint type);
enum imstatus roster_getstatus(const char *jid);
+const char *roster_getstatusmsg(const char *jid);
guint roster_gettype(const char *jid);
inline guint roster_exists(const char *jidname, enum findwhat type,
guint roster_type);