diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-20 23:37:34 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-20 23:37:34 +0200 |
commit | 3cfe01e3a7570d806a5a0f12808234fcfcd6c0a9 (patch) | |
tree | 2c1ec6f696b873f05d2641b8c8c22f708259a21a | |
parent | c5695a5f6d613bf54ced44a848622825bff17b46 (diff) | |
download | xK-3cfe01e3a7570d806a5a0f12808234fcfcd6c0a9.tar.gz xK-3cfe01e3a7570d806a5a0f12808234fcfcd6c0a9.tar.xz xK-3cfe01e3a7570d806a5a0f12808234fcfcd6c0a9.zip |
degesch: fix some object management
-rw-r--r-- | degesch.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -409,6 +409,8 @@ struct app_context // maybe also broadcast all buffers about the disconnection event // TODO: when getting connected again, rejoin all current channels + // FIXME: these should only have weak references, so that we don't have + // to watch all places where they might get unref-ed struct str_map irc_users; ///< IRC user data struct str_map irc_channels; ///< IRC channel data struct str_map irc_buffer_map; ///< Maps IRC identifiers to buffers @@ -1055,6 +1057,19 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer) } #endif // RL_READLINE_VERSION + // Get rid of the channel, as well as the users, + // if the buffer was the last thing keeping them alive + if (buffer->channel && buffer->channel->ref_count == 2) + str_map_set (&ctx->irc_channels, buffer->channel->name, NULL); + if (buffer->user && buffer->user->ref_count == 2) + str_map_set (&ctx->irc_users, buffer->user->nickname, NULL); + + // And make sure to unlink the buffer from "irc_buffer_map" + if (buffer->channel) + str_map_set (&ctx->irc_buffer_map, buffer->channel->name, NULL); + if (buffer->user) + str_map_set (&ctx->irc_buffer_map, buffer->user->nickname, NULL); + str_map_set (&ctx->buffers_by_name, buffer->name, NULL); LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer); buffer_destroy (buffer); @@ -1907,6 +1922,9 @@ irc_handle_nick (struct app_context *ctx, const struct irc_message *msg) str_map_find (&ctx->irc_buffer_map, user->nickname); if (pm_buffer) { + str_map_set (&ctx->irc_buffer_map, new_nickname, user_ref (user)); + str_map_set (&ctx->irc_buffer_map, user->nickname, NULL); + buffer_send (ctx, pm_buffer, BUFFER_LINE_NICK, 0, msg->prefix, NULL, "%s", new_nickname); // TODO: use a full weechat-style buffer name here |