From f9db598e1691bd8e3f9a1374e176810e158dafb3 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 29 Jul 2019 19:22:33 +0200 Subject: [PATCH] automatically open the chat for direct message channels --- README.md | 1 - ncdc/src/mainwindow.c | 22 ++++++++++++++++++++++ todo.org | 10 +++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c13e502..12840cc 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,6 @@ are a few that would be nice to have: * auto completion * man pages * notification handling if guilds are edited -* notification handling if friends send you a message * /markread support * handling for markdown, i.e. bold, italics, colours etc. * voice chat support diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index 0393b8e..6cf6a32 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -483,7 +483,10 @@ static void ncdc_mainwindow_handle_events(ncdc_mainwindow_t n) return; } + dc_channel_t c = NULL; dc_event_t e = NULL; + dc_message_t m = NULL; + char const *id = NULL; e = dc_session_pop_event(current_session); if (e == NULL) { @@ -497,9 +500,28 @@ static void ncdc_mainwindow_handle_events(ncdc_mainwindow_t n) ncdc_mainwindow_update_guilds(n); } break; + case DC_EVENT_TYPE_MESSAGE_CREATE: + { + m = dc_message_from_json(dc_event_payload(e)); + id = dc_message_channel_id(m); + goto_if_true(m == NULL || id == NULL, cleanup); + + c = dc_session_channel_by_id(current_session, id); + goto_if_true(c == NULL, cleanup); + + /* TODO: handle unmuted channels here + */ + if (dc_channel_is_dm(c)) { + ncdc_mainwindow_switch_or_add(n, c); + } + } break; + default: break; } +cleanup: + + dc_unref(m); dc_unref(e); } diff --git a/todo.org b/todo.org index 35416ba..725a5bd 100644 --- a/todo.org +++ b/todo.org @@ -1,11 +1,11 @@ * General ** TODO move key handling away from the thread the event_loop thread -* Channels [2/4] -** TODO Automatically open window for 1:1 and 1:N +* Channels [3/4] +** DONE Automatically open window for 1:1 and 1:N ** DONE send v6/api/channels/$ID/ack for "I read that shit" ** TODO add timestamps from messages ** DONE add message sending -* Guilds [0/3] -** TODO Guild support code -** TODO Guild view on the left pane +* Guilds [2/3] +** DONE Guild support code +** DONE Guild view on the left pane ** TODO silence guild channels