/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.43 by sysadm, Tue Sep 30 15:06:42 2025 UTC Revision 1.55 by sysadm, Fri Oct 17 01:25:08 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_favor.h"
19  #include "article_op.h"  #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
# Line 24  Line 25 
25  #include "log.h"  #include "log.h"
26  #include "login.h"  #include "login.h"
27  #include "menu.h"  #include "menu.h"
28    #include "menu_proc.h"
29  #include "section_list_display.h"  #include "section_list_display.h"
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
# Line 33  Line 35 
35  #include <time.h>  #include <time.h>
36  #include <sys/param.h>  #include <sys/param.h>
37    
38    static int section_aid_locations[BBS_max_section] = {0};
39  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
40  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
41    
# Line 47  enum select_cmd_t Line 50  enum select_cmd_t
50          EDIT_ARTICLE,          EDIT_ARTICLE,
51          DELETE_ARTICLE,          DELETE_ARTICLE,
52          QUERY_ARTICLE,          QUERY_ARTICLE,
53            SET_FAVOR_ARTICLE,
54            UNSET_FAVOR_ARTICLE,
55          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
56          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
57            SCAN_NEW_ARTICLE,
58          VIEW_EX_DIR,          VIEW_EX_DIR,
59            SHOW_TOP10,
60  };  };
61    
62  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 64  static int section_list_draw_items(int p Line 71  static int section_list_draw_items(int p
71          size_t j;          size_t j;
72          char article_flag;          char article_flag;
73          int is_viewed;          int is_viewed;
74            int is_favor;
75          time_t tm_now;          time_t tm_now;
76    
77          time(&tm_now);          time(&tm_now);
# Line 86  static int section_list_draw_items(int p Line 94  static int section_list_draw_items(int p
94                          }                          }
95                  }                  }
96    
97                    if (p_articles[i]->tid == 0)
98                    {
99                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
100                            if (is_favor < 0)
101                            {
102                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
103                                    is_favor = 0;
104                            }
105                    }
106                    else
107                    {
108                            is_favor = 0;
109                    }
110    
111                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
112                  {                  {
113                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 132  static int section_list_draw_items(int p Line 154  static int section_list_draw_items(int p
154                  }                  }
155                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
156    
157                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
158                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
159                  {                  {
160                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 141  static int section_list_draw_items(int p Line 163  static int section_list_draw_items(int p
163                  moveto(4 + i, 1);                  moveto(4 + i, 1);
164                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
165                  {                  {
166                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m%c%c %s%*s %s %s%s\033[m",
167                                       (is_favor ? '@' : ' '),
168                                     article_flag,                                     article_flag,
169                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
170                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 157  static int section_list_draw_items(int p Line 180  static int section_list_draw_items(int p
180                  }                  }
181                  else                  else
182                  {                  {
183                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                          prints("  %s%7d\033[m%c%c %s%*s %s %s%s\033[m",
184                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
185                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
186                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
187                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
188                                                             : "")),                                                             : "")),
189                                     p_articles[i]->aid,                                     p_articles[i]->aid,
190                                       (is_favor ? '@' : ' '),
191                                     article_flag,                                     article_flag,
192                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
193                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
# Line 231  static enum select_cmd_t section_list_se Line 255  static enum select_cmd_t section_list_se
255          {          {
256                  ch = igetch(100);                  ch = igetch(100);
257    
258                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
259                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
260                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
261                    }
262    
263                    switch (ch)
264                    {
265                  case KEY_NULL:                   // broken pipe                  case KEY_NULL:                   // broken pipe
266                          return EXIT_SECTION; // exit section                          log_error("KEY_NULL\n");
267                            return EXIT_SECTION;
268                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
269                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
270                          {                          {
271                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
272                                    return EXIT_SECTION;
273                          }                          }
274                          continue;                          continue;
275                    case KEY_ESC:
276                    case KEY_LEFT:
277                            return EXIT_SECTION;
278                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
279                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
280                  case CR:                  case CR:
                         igetch_reset();  
281                  case 'r':                  case 'r':
282                  case KEY_RIGHT:                  case KEY_RIGHT:
283                          if (item_count > 0)                          if (item_count > 0)
284                          {                          {
                                 BBS_last_access_tm = time(NULL);  
285                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
286                          }                          }
287                          break;                          break;
# Line 277  static enum select_cmd_t section_list_se Line 305  static enum select_cmd_t section_list_se
305                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
306                          }                          }
307                          break;                          break;
308                    case 'F':
309                            if (item_count > 0)
310                            {
311                                    return SET_FAVOR_ARTICLE;
312                            }
313                            break;
314                    case '-':
315                            if (item_count > 0)
316                            {
317                                    return UNSET_FAVOR_ARTICLE;
318                            }
319                            break;
320                  case KEY_HOME:                  case KEY_HOME:
321                          *p_page_id = 0;                          *p_page_id = 0;
322                  case 'P':                  case 'P':
# Line 291  static enum select_cmd_t section_list_se Line 331  static enum select_cmd_t section_list_se
331                                          (*p_page_id)--;                                          (*p_page_id)--;
332                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
333                                  }                                  }
334                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
335                                    {
336                                            if (total_page > 0)
337                                            {
338                                                    *p_page_id = total_page - 1;
339                                            }
340                                            if (item_count > 0)
341                                            {
342                                                    *p_selected_index = item_count - 1;
343                                            }
344                                    }
345                          }                          }
346                          else                          else
347                          {                          {
# Line 318  static enum select_cmd_t section_list_se Line 369  static enum select_cmd_t section_list_se
369                                          (*p_page_id)++;                                          (*p_page_id)++;
370                                          *p_selected_index = 0;                                          *p_selected_index = 0;
371                                  }                                  }
372                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
373                                  {                                  {
374                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
375                                            *p_selected_index = 0;
376                                  }                                  }
377                          }                          }
378                          else                          else
# Line 340  static enum select_cmd_t section_list_se Line 392  static enum select_cmd_t section_list_se
392                                  return LAST_TOPIC_ARTICLE;                                  return LAST_TOPIC_ARTICLE;
393                          }                          }
394                          break;                          break;
395                    case 'S':
396                            if (item_count > 0)
397                            {
398                                    return SCAN_NEW_ARTICLE;
399                            }
400                            break;
401                  case 'h':                  case 'h':
402                          return SHOW_HELP;                          return SHOW_HELP;
403                  case 'x':                  case 'x':
404                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
405                    case 'H':
406                            return SHOW_TOP10;
407                  default:                  default:
408                  }                  }
409    
# Line 369  static enum select_cmd_t section_list_se Line 429  static enum select_cmd_t section_list_se
429                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
430                  }                  }
431    
                 BBS_last_access_tm = time(NULL);  
432                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
433                  {                  {
434                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 466  static int display_article_key_handler(i Line 525  static int display_article_key_handler(i
525          return 0;          return 0;
526  }  }
527    
528  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
529  {  {
530          static int display_nickname = 0;          static int display_nickname = 0;
531    
532          SECTION_LIST *p_section;          SECTION_LIST *p_section;
533            int64_t section_index;
534            int32_t aid_location;
535          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
536          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
537          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 486  int section_list_display(const char *sna Line 547  int section_list_display(const char *sna
547          int direction;          int direction;
548          ARTICLE article_new;          ARTICLE article_new;
549          int page_id_cur;          int page_id_cur;
550            const ARTICLE *p_article_locate;
551    
552          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
553          if (p_section == NULL)          if (p_section == NULL)
# Line 494  int section_list_display(const char *sna Line 556  int section_list_display(const char *sna
556                  return -1;                  return -1;
557          }          }
558    
559            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
560            {
561                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
562                                      p_section->sid, BBS_priv.uid);
563                    return -1;
564            }
565    
566            section_index = get_section_index(p_section);
567    
568          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
569          {          {
570                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 511  int section_list_display(const char *sna Line 582  int section_list_display(const char *sna
582                  return -2;                  return -2;
583          }          }
584    
585            if (aid == 0)
586            {
587                    aid_location = section_aid_locations[section_index];
588            }
589            else
590            {
591                    aid_location = aid;
592            }
593    
594            // Locate at article with aid_locate
595            if (aid_location > 0)
596            {
597                    p_article_locate = article_block_find_by_aid(aid_location);
598                    if (p_article_locate == NULL)
599                    {
600                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
601                            return -3;
602                    }
603    
604                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
605                                                                                    &page_id, &selected_index, &article_count);
606                    if (ret < 0)
607                    {
608                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
609                                              p_section->sid, p_article_locate->aid);
610                            return -3;
611                    }
612            }
613    
614          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
615          {          {
616                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 524  int section_list_display(const char *sna Line 624  int section_list_display(const char *sna
624                  return -3;                  return -3;
625          }          }
626    
627            section_topic_view_tid = -1;
628    
629          if (article_count == 0) // empty section          if (article_count == 0) // empty section
630          {          {
631                  selected_index = 0;                  selected_index = 0;
632          }          }
633            else if (aid > 0)
634            {
635                    // Update current topic
636                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
637    
638                    // Update current aid location
639                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
640            }
641    
642          while (!SYS_server_exit)          while (!SYS_server_exit)
643          {          {
# Line 732  int section_list_display(const char *sna Line 842  int section_list_display(const char *sna
842                          // Update current topic                          // Update current topic
843                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
844    
845                            // Update current aid location
846                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
847    
848                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
849                          {                          {
850                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 829  int section_list_display(const char *sna Line 942  int section_list_display(const char *sna
942                                  return -2;                                  return -2;
943                          }                          }
944                          break;                          break;
945                    case SET_FAVOR_ARTICLE:
946                            ret = article_favor_set(p_articles[selected_index]->tid == 0
947                                                                                    ? p_articles[selected_index]->aid
948                                                                                    : p_articles[selected_index]->tid,
949                                                                            &BBS_article_favor, 1);
950                            if (ret < 0)
951                            {
952                                    log_error("article_favor_set(aid=%d, 1) error\n",
953                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
954                            }
955                            break;
956                    case UNSET_FAVOR_ARTICLE:
957                            ret = article_favor_set(p_articles[selected_index]->tid == 0
958                                                                                    ? p_articles[selected_index]->aid
959                                                                                    : p_articles[selected_index]->tid,
960                                                                            &BBS_article_favor, 0);
961                            if (ret < 0)
962                            {
963                                    log_error("article_favor_set(aid=%d, 0) error\n",
964                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
965                            }
966                            break;
967                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
968                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
969                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 851  int section_list_display(const char *sna Line 986  int section_list_display(const char *sna
986                                  }                                  }
987                          }                          }
988                          break;                          break;
989                    case SCAN_NEW_ARTICLE:
990                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
991                            if (ret < 0)
992                            {
993                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
994                                                      p_section->sid, p_articles[selected_index]->aid);
995                                    return -3;
996                            }
997                            else if (ret == 0) // not found
998                            {
999                                    break;
1000                            }
1001                            page_id_cur = page_id;
1002                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1003                                                                                            &page_id, &selected_index, &article_count);
1004                            if (ret < 0)
1005                            {
1006                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1007                                                      p_section->sid, p_article_locate->aid);
1008                                    return -3;
1009                            }
1010                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1011                            {
1012                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1013                                    if (ret < 0)
1014                                    {
1015                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1016                                            return -3;
1017                                    }
1018                            }
1019                            break;
1020                  case SHOW_HELP:                  case SHOW_HELP:
1021                          // Display help information                          // Display help information
1022                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 871  int section_list_display(const char *sna Line 1037  int section_list_display(const char *sna
1037                                  return -2;                                  return -2;
1038                          }                          }
1039                          break;                          break;
1040                    case SHOW_TOP10:
1041                            show_top10_menu(NULL);
1042                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1043                            {
1044                                    log_error("section_list_draw_screen() error\n");
1045                                    return -2;
1046                            }
1047                            break;
1048                  default:                  default:
1049                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
1050                  }                  }
# Line 919  int section_list_ex_dir_display(SECTION_ Line 1093  int section_list_ex_dir_display(SECTION_
1093                  {                  {
1094                          iflush();                          iflush();
1095                          ch = igetch(100);                          ch = igetch(100);
1096    
1097                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1098                            {
1099                                    BBS_last_access_tm = time(NULL);
1100                            }
1101    
1102                          switch (ch)                          switch (ch)
1103                          {                          {
1104                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1105                                    log_error("KEY_NULL\n");
1106                                  return 0;                                  return 0;
1107                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1108                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1109                                  {                                  {
1110                                            log_error("User input timeout\n");
1111                                          return 0;                                          return 0;
1112                                  }                                  }
1113                                  continue;                                  continue;
1114                          case CR:                          case CR:
                                 igetch_reset();  
1115                          default:                          default:
1116                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1117                                  {                                  {
# Line 949  int section_list_ex_dir_display(SECTION_ Line 1130  int section_list_ex_dir_display(SECTION_
1130                                  }                                  }
1131                          }                          }
1132    
                         BBS_last_access_tm = time(NULL);  
   
1133                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1134                          {                          {
1135                                  break;                                  break;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1