From: Art Cancro Date: Wed, 6 Jul 2011 16:59:10 +0000 (-0400) Subject: Condense the default wholist when there are multiple sessions from the same user X-Git-Tag: v8.11~603 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=1428e60c50b70d910e8c6d1180208fad2dde48f7 Condense the default wholist when there are multiple sessions from the same user --- diff --git a/citadel/citserver.c b/citadel/citserver.c index 3890ae6f1..f0a2d3435 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -652,7 +652,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