Skip to content

Commit

Permalink
Core(improve): activate buffer if chat already exists (#384)
Browse files Browse the repository at this point in the history
Close #381.
  • Loading branch information
SilverRainZ authored Sep 6, 2022
1 parent 425f09d commit ca72ed7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/app_ui_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,20 @@ static SrnRet ui_event_part(SuiBuffer *sui, SuiEvent event, GVariantDict *params
static SrnRet ui_event_query(SuiBuffer *sui, SuiEvent event, GVariantDict *params){
const char *nick = NULL;
SrnServer *srv;
SrnChat *chat;

srv = ctx_get_server(sui);
g_return_val_if_fail(srn_server_is_valid(srv), SRN_ERR);

g_variant_dict_lookup(params, "nick", SUI_EVENT_PARAM_STRING, &nick);

// If chat already exists, activate its buffer.
chat = srn_server_add_and_get_chat(srv, nick);
if (chat) {
sui_activate_buffer(chat->ui);
return SRN_OK;
}

return srn_server_add_chat(srv, nick);
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/chat_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,21 @@ SrnRet on_command_unfilter(SrnCommand *cmd, void *user_data){
SrnRet on_command_query(SrnCommand *cmd, void *user_data){
const char *nick;
SrnServer *srv;
SrnChat *chat;

srv = ctx_get_server(user_data);
g_return_val_if_fail(srv, SRN_ERR);

nick = srn_command_get_arg(cmd, 0);
g_return_val_if_fail(nick, SRN_ERR);

// If chat already exists, activate its buffer.
chat = srn_server_add_and_get_chat(srv, nick);
if (chat) {
sui_activate_buffer(chat->ui);
return SRN_OK;
}

return srn_server_add_chat(srv, nick);
}

Expand Down

0 comments on commit ca72ed7

Please sign in to comment.