| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
section_list_display.c - description |
/* |
| 3 |
------------------- |
* section_list_display |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - user interactive feature of section articles list |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "article_cache.h" |
#include "article_cache.h" |
| 14 |
#include "article_favor.h" |
#include "article_favor.h" |
| 35 |
#include <time.h> |
#include <time.h> |
| 36 |
#include <sys/param.h> |
#include <sys/param.h> |
| 37 |
|
|
| 38 |
#define TITLE_SEARCH_MAX_LEN 60 |
enum _section_list_display_constant_t |
| 39 |
|
{ |
| 40 |
|
TITLE_SEARCH_MAX_LEN = 60, |
| 41 |
|
}; |
| 42 |
|
|
| 43 |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
static int32_t section_aid_locations[BBS_max_section] = {0}; |
| 44 |
static int section_topic_view_mode = 0; |
static int section_topic_view_mode = 0; |
| 60 |
UNSET_FAVOR_ARTICLE, |
UNSET_FAVOR_ARTICLE, |
| 61 |
FIRST_TOPIC_ARTICLE, |
FIRST_TOPIC_ARTICLE, |
| 62 |
LAST_TOPIC_ARTICLE, |
LAST_TOPIC_ARTICLE, |
| 63 |
|
LAST_SECTION_ARTICLE, |
| 64 |
SCAN_NEW_ARTICLE, |
SCAN_NEW_ARTICLE, |
| 65 |
SCAN_ARTICLE_BACKWARD_BY_USER, |
SCAN_ARTICLE_BACKWARD_BY_USER, |
| 66 |
SCAN_ARTICLE_FORWARD_BY_USER, |
SCAN_ARTICLE_FORWARD_BY_USER, |
| 225 |
|
|
| 226 |
if (master_list[0] != '\0') |
if (master_list[0] != '\0') |
| 227 |
{ |
{ |
| 228 |
snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list); |
snprintf(str_section_master, sizeof(str_section_master), "版主: %s", master_list); |
| 229 |
} |
} |
| 230 |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname); |
snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname); |
| 231 |
|
|
| 278 |
log_error("KEY_NULL\n"); |
log_error("KEY_NULL\n"); |
| 279 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 280 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 281 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
| 282 |
{ |
{ |
| 283 |
log_error("User input timeout\n"); |
log_error("User input timeout\n"); |
| 284 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 368 |
break; |
break; |
| 369 |
case '$': |
case '$': |
| 370 |
case KEY_END: |
case KEY_END: |
| 371 |
|
if (*p_page_id + 1 == total_page && *p_selected_index + 1 == item_count) // Press END at end of list |
| 372 |
|
{ |
| 373 |
|
return LAST_SECTION_ARTICLE; |
| 374 |
|
} |
| 375 |
if (total_page > 0) |
if (total_page > 0) |
| 376 |
{ |
{ |
| 377 |
*p_page_id = total_page - 1; |
*p_page_id = total_page - 1; |
| 714 |
// Update current aid location |
// Update current aid location |
| 715 |
if (p_articles[selected_index] != NULL) |
if (p_articles[selected_index] != NULL) |
| 716 |
{ |
{ |
| 717 |
section_aid_locations[section_index] = p_articles[selected_index]->aid; |
if (selected_index >= ontop_start_offset) |
| 718 |
} |
{ |
| 719 |
else |
ret = last_article_in_section(p_section, &p_article_locate); |
| 720 |
{ |
if (ret < 0) |
| 721 |
log_error("p_articles[selected_index=%d] is NULL when exit section [%s]\n", selected_index, sname); |
{ |
| 722 |
|
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
| 723 |
|
return -3; |
| 724 |
|
} |
| 725 |
|
else if (ret == 0) |
| 726 |
|
{ |
| 727 |
|
section_aid_locations[section_index] = 0; |
| 728 |
|
} |
| 729 |
|
else // ret > 0 |
| 730 |
|
{ |
| 731 |
|
section_aid_locations[section_index] = p_article_locate->aid; |
| 732 |
|
} |
| 733 |
|
} |
| 734 |
|
else |
| 735 |
|
{ |
| 736 |
|
section_aid_locations[section_index] = (p_articles[selected_index]->visible ? p_articles[selected_index]->aid : 0); |
| 737 |
|
} |
| 738 |
} |
} |
| 739 |
return 0; |
return 0; |
| 740 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 880 |
{ |
{ |
| 881 |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); |
| 882 |
} |
} |
| 883 |
|
else if (ret > 0) // Article replied |
| 884 |
|
{ |
| 885 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 886 |
|
if (ret < 0) |
| 887 |
|
{ |
| 888 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 889 |
|
return -3; |
| 890 |
|
} |
| 891 |
|
} |
| 892 |
loop = 1; |
loop = 1; |
| 893 |
break; |
break; |
| 894 |
case '=': // First topic article |
case '=': // First topic article |
| 952 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 953 |
if (ret < 0) |
if (ret < 0) |
| 954 |
{ |
{ |
| 955 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error: %d\n", p_section->sid, page_id, ret); |
| 956 |
return -3; |
return -3; |
| 957 |
} |
} |
| 958 |
} |
} |
| 978 |
{ |
{ |
| 979 |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); |
| 980 |
} |
} |
| 981 |
|
else if (ret > 0) // Article modified |
| 982 |
|
{ |
| 983 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 984 |
|
if (ret < 0) |
| 985 |
|
{ |
| 986 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 987 |
|
return -3; |
| 988 |
|
} |
| 989 |
|
} |
| 990 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 991 |
{ |
{ |
| 992 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 1005 |
} |
} |
| 1006 |
else if (ret > 0) // Article deleted |
else if (ret > 0) // Article deleted |
| 1007 |
{ |
{ |
| 1008 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
do |
|
if (ret < 0) |
|
| 1009 |
{ |
{ |
| 1010 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1011 |
return -3; |
if (ret >= 0 && selected_index > article_count - 1) |
| 1012 |
} |
{ |
| 1013 |
|
selected_index = article_count - 1; |
| 1014 |
|
break; |
| 1015 |
|
} |
| 1016 |
|
else if (ret < 0 && page_id > 0) |
| 1017 |
|
{ |
| 1018 |
|
page_id--; |
| 1019 |
|
selected_index = BBS_article_limit_per_page - 1; |
| 1020 |
|
} |
| 1021 |
|
else if (ret < 0 && page_id <= 0) |
| 1022 |
|
{ |
| 1023 |
|
selected_index = 0; |
| 1024 |
|
break; |
| 1025 |
|
} |
| 1026 |
|
} while (ret < 0); |
| 1027 |
} |
} |
| 1028 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 1029 |
{ |
{ |
| 1109 |
} |
} |
| 1110 |
} |
} |
| 1111 |
break; |
break; |
| 1112 |
|
case LAST_SECTION_ARTICLE: |
| 1113 |
|
page_id_cur = page_id; |
| 1114 |
|
ret = last_article_in_section(p_section, &p_article_locate); |
| 1115 |
|
if (ret < 0) |
| 1116 |
|
{ |
| 1117 |
|
log_error("last_article_in_section(sid=%d) error\n", p_section->sid); |
| 1118 |
|
return -3; |
| 1119 |
|
} |
| 1120 |
|
else if (ret == 0) |
| 1121 |
|
{ |
| 1122 |
|
break; |
| 1123 |
|
} |
| 1124 |
|
ret = locate_article_in_section(p_section, p_article_locate, 0, 0, |
| 1125 |
|
&page_id, &selected_index, &article_count); |
| 1126 |
|
if (ret < 0) |
| 1127 |
|
{ |
| 1128 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", |
| 1129 |
|
p_section->sid, p_article_locate->aid); |
| 1130 |
|
return -3; |
| 1131 |
|
} |
| 1132 |
|
else if (ret > 0 && page_id != page_id_cur) // found and page changed |
| 1133 |
|
{ |
| 1134 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); |
| 1135 |
|
if (ret < 0) |
| 1136 |
|
{ |
| 1137 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 1138 |
|
return -3; |
| 1139 |
|
} |
| 1140 |
|
} |
| 1141 |
|
break; |
| 1142 |
case SCAN_NEW_ARTICLE: |
case SCAN_NEW_ARTICLE: |
| 1143 |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); |
| 1144 |
if (ret < 0) |
if (ret < 0) |
| 1180 |
moveto(SCREEN_ROWS, 1); |
moveto(SCREEN_ROWS, 1); |
| 1181 |
clrtoeol(); |
clrtoeol(); |
| 1182 |
get_data(SCREEN_ROWS, 1, |
get_data(SCREEN_ROWS, 1, |
| 1183 |
(direction == 1 ? "向下搜寻作者: " : "向上搜寻作者: "), |
(direction == 1 ? "↓搜寻作者: " : "↑搜寻作者: "), |
| 1184 |
username, sizeof(username), BBS_username_max_len); |
username, sizeof(username), BBS_username_max_len); |
| 1185 |
|
|
| 1186 |
if (username[0] == '\0') |
if (username[0] == '\0') |
| 1269 |
moveto(SCREEN_ROWS, 1); |
moveto(SCREEN_ROWS, 1); |
| 1270 |
clrtoeol(); |
clrtoeol(); |
| 1271 |
get_data(SCREEN_ROWS, 1, |
get_data(SCREEN_ROWS, 1, |
| 1272 |
(direction == 1 ? "向下搜寻标题: " : "向上搜寻标题: "), |
(direction == 1 ? "↓搜寻标题: " : "↑搜寻标题: "), |
| 1273 |
title, sizeof(title), TITLE_SEARCH_MAX_LEN); |
title, sizeof(title), TITLE_SEARCH_MAX_LEN); |
| 1274 |
|
|
| 1275 |
if (title[0] == '\0') |
if (title[0] == '\0') |
| 1405 |
log_error("KEY_NULL\n"); |
log_error("KEY_NULL\n"); |
| 1406 |
return 0; |
return 0; |
| 1407 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 1408 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
| 1409 |
{ |
{ |
| 1410 |
log_error("User input timeout\n"); |
log_error("User input timeout\n"); |
| 1411 |
return 0; |
return 0; |