degesch: factor out irc_get_or_make_user()

This commit is contained in:
Přemysl Eric Janouch 2015-05-15 05:43:59 +02:00
parent d41e3499c9
commit 489a5fa552

View File

@ -2670,6 +2670,15 @@ irc_make_user (struct server *s, char *nickname)
return user; return user;
} }
struct user *
irc_get_or_make_user (struct server *s, const char *nickname)
{
struct user *user = str_map_find (&s->irc_users, nickname);
if (user)
return user_ref (user);
return irc_make_user (s, xstrdup (nickname));
}
static struct buffer * static struct buffer *
irc_get_or_make_user_buffer (struct server *s, const char *nickname) irc_get_or_make_user_buffer (struct server *s, const char *nickname)
{ {
@ -2677,11 +2686,7 @@ irc_get_or_make_user_buffer (struct server *s, const char *nickname)
if (buffer) if (buffer)
return buffer; return buffer;
struct user *user = str_map_find (&s->irc_users, nickname); struct user *user = irc_get_or_make_user (s, nickname);
if (!user)
user = irc_make_user (s, xstrdup (nickname));
else
user = user_ref (user);
// Open a new buffer for the user // Open a new buffer for the user
buffer = buffer_new (); buffer = buffer_new ();