[mw-devel] [Git][arthur/mw][master] 2 commits: Factor out requests to refresh the wholist
Justin Mitchell
arthur at sucs.org
Tue Jan 12 11:52:20 GMT 2016
Justin Mitchell pushed to branch master at Justin Mitchell / mw
Commits:
ec3091a2 by Justin Mitchell at 2016-01-12T11:27:46Z
Factor out requests to refresh the wholist
- - - - -
97586a6f by Justin Mitchell at 2016-01-12T11:50:14Z
found what broke autocomplete, fixes #6
- - - - -
1 changed file:
- src/client/who.c
Changes:
=====================================
src/client/who.c
=====================================
--- a/src/client/who.c
+++ b/src/client/who.c
@@ -46,6 +46,23 @@ static json_t * whoinfo = NULL;
static time_t whowhen = 0;
static int whotype = -1;
#define WHOCACHE 120 /* cache who data for this many seconds */
+#define NO_CALLBACK -1
+
+/* check if we need to refresh the wholist
+ * and request it if we do
+ * report if we did
+ */
+static int refresh_wholist(int type)
+{
+ time_t now = time(0);
+ if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
+ whotype = type;
+ ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, user->posn);
+ ipcmsg_transmit(msg);
+ return 1;
+ }
+ return 0;
+}
void display_wholist(int mode)
{
@@ -53,10 +70,7 @@ void display_wholist(int mode)
/* we dont have a recent cache of who list,
* request one, and get called back when it arrives */
- if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
- whotype = mode;
- ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, user->posn);
- ipcmsg_transmit(msg);
+ if (refresh_wholist(mode)) {
return;
}
@@ -104,8 +118,9 @@ void display_wholist(int mode)
void update_wholist(ipc_message_t *msg)
{
/* there is an old one, clear it */
- if (whoinfo != NULL)
+ if (whoinfo != NULL) {
json_decref(whoinfo);
+ }
/* store the new one */
whoinfo = json_init(msg);
@@ -122,14 +137,10 @@ char *part_who(const char *text, int status)
{
static int len = 0;
static int index = 0; /* looking for the Nth answer */
- time_t now = time(NULL);
/* we dont have a recent cache of who list,
* ask for an update, then do the best you can */
- if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
- ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, user->posn);
- ipcmsg_transmit(msg);
- }
+ refresh_wholist(NO_CALLBACK);
/* we dont even have stale info */
if (whoinfo == NULL) return(NULL);
@@ -164,14 +175,10 @@ char *part_who_talk(const char *text, int status)
{
static int len = 0;
static int index = 0; /* looking for the Nth answer */
- time_t now = time(NULL);
/* we dont have a recent cache of who list,
* ask for an update, then do the best you can */
- if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
- ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, user->posn);
- ipcmsg_transmit(msg);
- }
+ refresh_wholist(NO_CALLBACK);
/* we dont even have stale info */
if (whoinfo == NULL) return(NULL);
@@ -189,7 +196,7 @@ char *part_who_talk(const char *text, int status)
const char *name = json_getstring(entry, "name");
json_t * perms = json_object_get(entry, "perms");
const char *chatmode = NULL;
- if (perms != NULL) chatmode=json_getstring(entry, "chatmode");
+ if (perms != NULL) chatmode=json_getstring(perms, "chatmode");
if (name == NULL) continue;
if (chatmode == NULL) continue;
@@ -216,13 +223,9 @@ char *part_who_talk(const char *text, int status)
*/
json_t * grab_wholist(void)
{
- time_t now = time(NULL);
/* we dont have a recent cache of who list,
* ask for an update, then do the best you can */
- if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
- ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, user->posn);
- ipcmsg_transmit(msg);
- }
+ refresh_wholist(NO_CALLBACK);
if (whoinfo != NULL) json_incref(whoinfo);
return whoinfo;
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/c59917a3885d883cba0d279776fb40209956f181...97586a6ffcb0f2650402bd5f6eb727260455cdf7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20160112/a6f59294/attachment.html>
More information about the mw-devel
mailing list