| 17 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 18 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 19 |
#include "article_cache.h" |
#include "article_cache.h" |
| 20 |
|
#include "article_post.h" |
| 21 |
#include "common.h" |
#include "common.h" |
| 22 |
#include "io.h" |
#include "io.h" |
| 23 |
#include "screen.h" |
#include "screen.h" |
| 24 |
#include "log.h" |
#include "log.h" |
| 25 |
|
#include "user_priv.h" |
| 26 |
|
#include "article_view_log.h" |
| 27 |
#include "str_process.h" |
#include "str_process.h" |
| 28 |
#include <time.h> |
#include <time.h> |
| 29 |
#include <sys/param.h> |
#include <sys/param.h> |
| 40 |
CHANGE_PAGE = 2, |
CHANGE_PAGE = 2, |
| 41 |
REFRESH_SCREEN = 3, |
REFRESH_SCREEN = 3, |
| 42 |
CHANGE_NAME_DISPLAY = 4, |
CHANGE_NAME_DISPLAY = 4, |
| 43 |
|
POST_ARTICLE = 5, |
| 44 |
|
EDIT_ARTICLE = 6, |
| 45 |
}; |
}; |
| 46 |
|
|
| 47 |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname) |
| 54 |
int len; |
int len; |
| 55 |
int i; |
int i; |
| 56 |
char article_flag; |
char article_flag; |
| 57 |
|
int is_viewed; |
| 58 |
time_t tm_now; |
time_t tm_now; |
| 59 |
|
|
| 60 |
time(&tm_now); |
time(&tm_now); |
| 63 |
|
|
| 64 |
for (i = 0; i < article_count; i++) |
for (i = 0; i < article_count; i++) |
| 65 |
{ |
{ |
| 66 |
article_flag = ' '; |
if (p_articles[i]->uid == BBS_priv.uid) |
| 67 |
|
{ |
| 68 |
|
is_viewed = 1; |
| 69 |
|
} |
| 70 |
|
else |
| 71 |
|
{ |
| 72 |
|
is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); |
| 73 |
|
if (is_viewed < 0) |
| 74 |
|
{ |
| 75 |
|
log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); |
| 76 |
|
is_viewed = 0; |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
article_flag = (is_viewed ? ' ' : 'N'); |
| 81 |
|
|
| 82 |
if (p_articles[i]->excerption) |
if (p_articles[i]->excerption) |
| 83 |
{ |
{ |
| 84 |
article_flag = 'm'; |
article_flag = (is_viewed ? 'm' : 'M'); |
| 85 |
} |
} |
| 86 |
else if (p_articles[i]->lock) |
else if (p_articles[i]->lock && is_viewed) |
| 87 |
{ |
{ |
| 88 |
article_flag = 'x'; |
article_flag = 'x'; |
| 89 |
} |
} |
| 110 |
|
|
| 111 |
moveto(4 + i, 1); |
moveto(4 + i, 1); |
| 112 |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
prints(" %s%7d\033[m %c %s%*s %s %s%s\033[m", |
| 113 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[36m" : "")), |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
| 114 |
p_articles[i]->aid, |
p_articles[i]->aid, |
| 115 |
article_flag, |
article_flag, |
| 116 |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
(display_nickname ? p_articles[i]->nickname : p_articles[i]->username), |
| 118 |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
: BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))), |
| 119 |
"", |
"", |
| 120 |
str_time, |
str_time, |
| 121 |
(p_articles[i]->aid == section_topic_view_tid ? "\033[33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[36m" : "")), |
(p_articles[i]->aid == section_topic_view_tid ? "\033[1;33m" : (p_articles[i]->tid == section_topic_view_tid ? "\033[1;36m" : "")), |
| 122 |
title_f); |
title_f); |
| 123 |
} |
} |
| 124 |
|
|
| 140 |
show_top(str_section_master, stitle, str_section_name); |
show_top(str_section_master, stitle, str_section_name); |
| 141 |
moveto(2, 0); |
moveto(2, 0); |
| 142 |
prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] " |
prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] " |
| 143 |
"阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m %s[\033[1;32mn\033[0;37m]\033[m", |
"阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] " |
| 144 |
|
"修改[\033[1;32mE\033[0;37m] %s[\033[1;32mn\033[0;37m]\033[m", |
| 145 |
(display_nickname ? "显示用户名" : "显示昵称")); |
(display_nickname ? "显示用户名" : "显示昵称")); |
| 146 |
moveto(3, 0); |
moveto(3, 0); |
| 147 |
if (display_nickname) |
if (display_nickname) |
| 197 |
return VIEW_ARTICLE; |
return VIEW_ARTICLE; |
| 198 |
} |
} |
| 199 |
break; |
break; |
| 200 |
|
case Ctrl('P'): |
| 201 |
|
return POST_ARTICLE; |
| 202 |
|
case 'E': |
| 203 |
|
return EDIT_ARTICLE; |
| 204 |
case KEY_HOME: |
case KEY_HOME: |
| 205 |
*p_page_id = 0; |
*p_page_id = 0; |
| 206 |
case KEY_PGUP: |
case KEY_PGUP: |
| 237 |
(*p_page_id)++; |
(*p_page_id)++; |
| 238 |
*p_selected_index = 0; |
*p_selected_index = 0; |
| 239 |
} |
} |
| 240 |
|
else // end of last page |
| 241 |
|
{ |
| 242 |
|
return CHANGE_PAGE; // force refresh pages |
| 243 |
|
} |
| 244 |
} |
} |
| 245 |
else |
else |
| 246 |
{ |
{ |
| 288 |
if (section_topic_view_mode) |
if (section_topic_view_mode) |
| 289 |
{ |
{ |
| 290 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 291 |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 292 |
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ " |
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] " |
| 293 |
"模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |"); |
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 294 |
} |
} |
| 295 |
else |
else |
| 296 |
{ |
{ |
| 297 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 298 |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] " |
| 299 |
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] " |
| 300 |
"模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |"); |
"切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |"); |
| 301 |
} |
} |
| 302 |
*p_key = 0; |
*p_key = 0; |
| 303 |
break; |
break; |
| 304 |
|
case 'r': // Reply article |
| 305 |
|
return 1; |
| 306 |
case KEY_UP: |
case KEY_UP: |
| 307 |
|
case KEY_PGUP: |
| 308 |
|
case KEY_HOME: |
| 309 |
if (p_ctx->reach_begin) |
if (p_ctx->reach_begin) |
| 310 |
{ |
{ |
| 311 |
if (section_topic_view_mode) |
if (section_topic_view_mode) |
| 312 |
{ |
{ |
| 313 |
*p_key = KEY_PGUP; |
*p_key = KEY_PGUP; |
| 314 |
} |
} |
| 315 |
|
else |
| 316 |
|
{ |
| 317 |
|
*p_key = KEY_UP; |
| 318 |
|
} |
| 319 |
return 1; |
return 1; |
| 320 |
} |
} |
| 321 |
break; |
break; |
| 322 |
case KEY_DOWN: |
case KEY_DOWN: |
| 323 |
|
case KEY_PGDN: |
| 324 |
|
case KEY_END: |
| 325 |
if (p_ctx->reach_end) |
if (p_ctx->reach_end) |
| 326 |
{ |
{ |
| 327 |
if (section_topic_view_mode) |
if (section_topic_view_mode) |
| 328 |
{ |
{ |
| 329 |
*p_key = KEY_PGDN; |
*p_key = KEY_PGDN; |
| 330 |
} |
} |
| 331 |
|
else |
| 332 |
|
{ |
| 333 |
|
*p_key = KEY_DOWN; |
| 334 |
|
} |
| 335 |
return 1; |
return 1; |
| 336 |
} |
} |
| 337 |
break; |
break; |
| 357 |
int ret; |
int ret; |
| 358 |
int loop; |
int loop; |
| 359 |
int direction; |
int direction; |
| 360 |
|
ARTICLE article_new; |
| 361 |
|
|
| 362 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 363 |
if (p_section == NULL) |
if (p_section == NULL) |
| 449 |
break; |
break; |
| 450 |
} |
} |
| 451 |
|
|
| 452 |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 1, 0, |
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, |
| 453 |
display_article_key_handler, DATA_READ_HELP); |
display_article_key_handler, DATA_READ_HELP); |
| 454 |
|
|
| 455 |
if (article_cache_unload(&cache) < 0) |
if (article_cache_unload(&cache) < 0) |
| 458 |
break; |
break; |
| 459 |
} |
} |
| 460 |
|
|
| 461 |
|
// Update article_view_log |
| 462 |
|
if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0) |
| 463 |
|
{ |
| 464 |
|
log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid); |
| 465 |
|
} |
| 466 |
|
|
| 467 |
switch (ret) |
switch (ret) |
| 468 |
{ |
{ |
| 469 |
case KEY_UP: |
case KEY_UP: |
| 549 |
loop = 1; |
loop = 1; |
| 550 |
} |
} |
| 551 |
break; |
break; |
| 552 |
|
case 'r': // Reply article |
| 553 |
|
if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) |
| 554 |
|
{ |
| 555 |
|
log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid); |
| 556 |
|
} |
| 557 |
|
loop = 1; |
| 558 |
|
break; |
| 559 |
} |
} |
| 560 |
} while (loop); |
} while (loop); |
| 561 |
|
|
| 573 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 574 |
{ |
{ |
| 575 |
log_error("section_list_draw_screen() error\n"); |
log_error("section_list_draw_screen() error\n"); |
| 576 |
|
return -2; |
| 577 |
|
} |
| 578 |
|
break; |
| 579 |
|
case POST_ARTICLE: |
| 580 |
|
ret = article_post(p_section, &article_new); |
| 581 |
|
if (ret < 0) |
| 582 |
|
{ |
| 583 |
|
log_error("article_post(sid=%d, NEW) error\n", p_section->sid); |
| 584 |
|
} |
| 585 |
|
else if (ret > 0) // New article posted |
| 586 |
|
{ |
| 587 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 588 |
|
if (ret < 0) |
| 589 |
|
{ |
| 590 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 591 |
|
return -3; |
| 592 |
|
} |
| 593 |
|
} |
| 594 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 595 |
|
{ |
| 596 |
|
log_error("section_list_draw_screen() error\n"); |
| 597 |
|
return -2; |
| 598 |
|
} |
| 599 |
|
break; |
| 600 |
|
case EDIT_ARTICLE: |
| 601 |
|
if (p_articles[selected_index]->uid != BBS_priv.uid) |
| 602 |
|
{ |
| 603 |
|
break; |
| 604 |
|
} |
| 605 |
|
if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) |
| 606 |
|
{ |
| 607 |
|
log_error("article_post(aid=%d, EDIT) error\n", p_articles[selected_index]->aid); |
| 608 |
|
} |
| 609 |
|
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 610 |
|
{ |
| 611 |
|
log_error("section_list_draw_screen() error\n"); |
| 612 |
return -2; |
return -2; |
| 613 |
} |
} |
| 614 |
break; |
break; |