revamp handling of channels
This commit is contained in:
@@ -10,7 +10,7 @@ ncdc_cmd_friends_list(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
|
||||
LOG(n, L"/FRIENDS list");
|
||||
for (i = 0; i < dc_account_friends_size(current_account); i++) {
|
||||
dc_account_t acc = dc_account_nthfriend(current_account, i);
|
||||
dc_account_t acc = dc_account_nth_friend(current_account, i);
|
||||
switch (dc_account_friend_state(acc)) {
|
||||
case FRIEND_STATE_PENDING: c = 'P'; break;
|
||||
default: c = ' '; break;
|
||||
@@ -76,7 +76,7 @@ ncdc_cmd_friends_remove(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
return_if_true(name == NULL, false);
|
||||
|
||||
for (i = 0; i < dc_account_friends_size(current_account); i++) {
|
||||
dc_account_t cur = dc_account_nthfriend(current_account, i);
|
||||
dc_account_t cur = dc_account_nth_friend(current_account, i);
|
||||
if (strcmp(dc_account_fullname(cur), name) == 0) {
|
||||
friend = cur;
|
||||
break;
|
||||
@@ -120,7 +120,7 @@ ncdc_cmd_friends_accept(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
return_if_true(name == NULL, false);
|
||||
|
||||
for (i = 0; i < dc_account_friends_size(current_account); i++) {
|
||||
dc_account_t cur = dc_account_nthfriend(current_account, i);
|
||||
dc_account_t cur = dc_account_nth_friend(current_account, i);
|
||||
if (strcmp(dc_account_fullname(cur), name) == 0 &&
|
||||
dc_account_friend_state(cur) == FRIEND_STATE_PENDING) {
|
||||
friend = cur;
|
||||
|
||||
@@ -49,7 +49,7 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
dc_unref(current_session);
|
||||
current_session = dc_ref(s);
|
||||
|
||||
LOG(n, L"login: %ls: authentication successful", av[1]);
|
||||
LOG(n, L"login: %ls: authentication successful, waiting for data...", av[1]);
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
|
||||
@@ -15,7 +15,7 @@ bool ncdc_cmd_msg(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
dc_account_t current_account = NULL;
|
||||
size_t i = 0;
|
||||
|
||||
if (is_logged_in()) {
|
||||
if (!is_logged_in()) {
|
||||
LOG(n, L"msg: not logged in");
|
||||
return false;
|
||||
}
|
||||
@@ -27,40 +27,33 @@ bool ncdc_cmd_msg(ncdc_mainwindow_t n, size_t ac, wchar_t **av)
|
||||
|
||||
/* find out if the target is a friend we can contact
|
||||
*/
|
||||
dc_account_t f = dc_account_findfriend(current_account, target);
|
||||
dc_account_t f = dc_session_account_fullname(current_session, target);
|
||||
if (f == NULL) {
|
||||
LOG(n, L"msg: no such friend found: \"%s\"", target);
|
||||
LOG(n, L"msg: no such account found: \"%s\"", target);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
c = dc_session_make_channel(current_session, &f, 1);
|
||||
if (c == NULL) {
|
||||
LOG(n, L"msg: failed to create channel for these recipients");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* see if we have a channel already, that services that user
|
||||
* if so we set v to something non-NIL and it should be good
|
||||
*/
|
||||
for (i = 0; i < ncdc_mainwindow_views(n)->len; i++) {
|
||||
v = g_ptr_array_index(ncdc_mainwindow_views(n), i);
|
||||
dc_channel_t chan = ncdc_textview_channel(v);
|
||||
ncdc_textview_t view = g_ptr_array_index(ncdc_mainwindow_views(n), i);
|
||||
dc_channel_t chan = ncdc_textview_channel(view);
|
||||
|
||||
if (chan != NULL &&
|
||||
dc_channel_type(chan) == CHANNEL_TYPE_DM_TEXT &&
|
||||
dc_account_equal(dc_channel_nthrecipient(chan, 1), f)) {
|
||||
c = dc_ref(chan);
|
||||
if (dc_channel_compare(chan, c)) {
|
||||
ncdc_mainwindow_switchview(n, i);
|
||||
v = view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (c == NULL) {
|
||||
/* no? create a new window and switch to it
|
||||
*/
|
||||
if (!dc_api_create_channel(api, current_account, &f, 1, &c)) {
|
||||
LOG(n, L"msg: failed to create channel");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!dc_api_get_messages(api, current_account, c)) {
|
||||
LOG(n, L"msg: failed to fetch messages in channel");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (v == NULL) {
|
||||
v = ncdc_textview_new();
|
||||
goto_if_true(v == NULL, cleanup);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ static void ncdc_textview_maketitle(ncdc_textview_t v)
|
||||
size_t rlen = dc_channel_recipients(v->channel);
|
||||
|
||||
for (i = 0; i < rlen; i++) {
|
||||
dc_account_t r = dc_channel_nthrecipient(v->channel, i);
|
||||
dc_account_t r = dc_channel_nth_recipient(v->channel, i);
|
||||
fwprintf(f, L"%s", dc_account_fullname(r));
|
||||
if (i < (rlen-1)) {
|
||||
fwprintf(f, L",");
|
||||
@@ -201,7 +201,7 @@ ncdc_textview_render_msgs(ncdc_textview_t v, WINDOW *win, int lines, int cols)
|
||||
atline = lines;
|
||||
|
||||
for (i = msgs-1; i >= 0; i--) {
|
||||
dc_message_t m = dc_channel_nthmessage(v->channel, i);
|
||||
dc_message_t m = dc_channel_nth_message(v->channel, i);
|
||||
wchar_t *s = ncdc_textview_format(m);
|
||||
wchar_t const *end = s, *last = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
Reference in New Issue
Block a user