Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Factor out requests to refresh the wholist
· ec3091a2
Justin Mitchell
authored
Jan 12, 2016
ec3091a2
found what broke autocomplete, fixes
#6
· 97586a6f
Justin Mitchell
authored
Jan 12, 2016
97586a6f
Hide whitespace changes
Inline
Side-by-side
src/client/who.c
View file @
97586a6f
...
...
@@ -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
;
...
...