From 0700d2580a870f92008686de2cdf42b4759033ab Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 6 Jul 2011 12:59:10 -0400 Subject: [PATCH] Condense the default wholist when there are multiple sessions from the same user --- citadel/citserver.c | 2 +- citadel/textclient/citadel.c | 52 ++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index 586732593..59e3514b4 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -626,7 +626,7 @@ void GenerateRoomDisplay(char *real_room, if (viewed->room.QRflags & QR_PRIVATE) { CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL); if ( (ra & UA_KNOWN) == 0) { - strcpy(real_room, ""); + strcpy(real_room, " "); } } diff --git a/citadel/textclient/citadel.c b/citadel/textclient/citadel.c index 3b3fba25d..19f46ca57 100644 --- a/citadel/textclient/citadel.c +++ b/citadel/textclient/citadel.c @@ -1175,7 +1175,20 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname) /* - * Record compare function for SortOnlineUsers() + * Session username compare function for SortOnlineUsers() + */ +int rwho_username_cmp(const void *rec1, const void *rec2) { + char *u1, *u2; + + u1 = strchr(rec1, '|'); + u2 = strchr(rec2, '|'); + + return strcasecmp( (u1?++u1:"") , (u2?++u2:"") ); +} + + +/* + * Idle time compare function for SortOnlineUsers() */ int idlecmp(const void *rec1, const void *rec2) { time_t i1, i2; @@ -1193,8 +1206,11 @@ int idlecmp(const void *rec1, const void *rec2) { * Sort the list of online users by idle time. * This function frees the supplied buffer, and returns a new one * to the caller. The caller is responsible for freeing the returned buffer. + * + * If 'condense' is nonzero, multiple sessions for the same user will be + * combined into one for brevity. */ -char *SortOnlineUsers(char *listing) { +char *SortOnlineUsers(char *listing, int condense) { int rows; char *sortbuf; char *retbuf; @@ -1217,17 +1233,37 @@ char *SortOnlineUsers(char *listing) { memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ); } - /* Do the sort */ + /* Sort by idle time */ qsort(sortbuf, rows, SIZ, idlecmp); + /* Combine multiple sessions for the same user */ + if (condense) { + qsort(sortbuf, rows, SIZ, rwho_username_cmp); + if (rows > 1) for (i=1; i0) { + char u1[USERNAME_SIZE]; + char u2[USERNAME_SIZE]; + extract_token(u1, &sortbuf[(i-1)*SIZ], 1, '|', sizeof u1); + extract_token(u2, &sortbuf[i*SIZ], 1, '|', sizeof u2); + if (!strcasecmp(u1, u2)) { + memcpy(&sortbuf[i*SIZ], &sortbuf[(i+1)*SIZ], (rows-i-1)*SIZ); + --rows; + --i; + } + } + + qsort(sortbuf, rows, SIZ, idlecmp); /* idle sort again */ + } + /* Copy back to a \n delimited list */ strcpy(retbuf, ""); for (i=0; i