/[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.42 by sysadm, Tue Sep 30 14:56:51 2025 UTC Revision 1.46 by sysadm, Mon Oct 13 02:23:27 2025 UTC
# Line 33  Line 33 
33  #include <time.h>  #include <time.h>
34  #include <sys/param.h>  #include <sys/param.h>
35    
36    static int section_aid_locations[BBS_max_section] = {0};
37  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
38  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
39    
# Line 49  enum select_cmd_t Line 50  enum select_cmd_t
50          QUERY_ARTICLE,          QUERY_ARTICLE,
51          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
52          LAST_TOPIC_ARTICLE,          LAST_TOPIC_ARTICLE,
53            SCAN_NEW_ARTICLE,
54          VIEW_EX_DIR,          VIEW_EX_DIR,
55  };  };
56    
# Line 144  static int section_list_draw_items(int p Line 146  static int section_list_draw_items(int p
146                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m %c %s%*s %s %s%s\033[m",
147                                     article_flag,                                     article_flag,
148                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
149                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
150                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
151                                     "",                                     "",
152                                     str_time,                                     str_time,
153                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 166  static int section_list_draw_items(int p Line 168  static int section_list_draw_items(int p
168                                     p_articles[i]->aid,                                     p_articles[i]->aid,
169                                     article_flag,                                     article_flag,
170                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
171                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
172                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
173                                     "",                                     "",
174                                     str_time,                                     str_time,
175                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 291  static enum select_cmd_t section_list_se Line 293  static enum select_cmd_t section_list_se
293                                          (*p_page_id)--;                                          (*p_page_id)--;
294                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
295                                  }                                  }
296                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
297                                    {
298                                            if (total_page > 0)
299                                            {
300                                                    *p_page_id = total_page - 1;
301                                            }
302                                            if (item_count > 0)
303                                            {
304                                                    *p_selected_index = item_count - 1;
305                                            }
306                                    }
307                          }                          }
308                          else                          else
309                          {                          {
# Line 318  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 = 0;                                          *p_selected_index = 0;
333                                  }                                  }
334                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
335                                  {                                  {
336                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
337                                            *p_selected_index = 0;
338                                  }                                  }
339                          }                          }
340                          else                          else
# Line 340  static enum select_cmd_t section_list_se Line 354  static enum select_cmd_t section_list_se
354                                  return LAST_TOPIC_ARTICLE;                                  return LAST_TOPIC_ARTICLE;
355                          }                          }
356                          break;                          break;
357                    case 'S':
358                            if (item_count > 0)
359                            {
360                                    return SCAN_NEW_ARTICLE;
361                            }
362                            break;
363                  case 'h':                  case 'h':
364                          return SHOW_HELP;                          return SHOW_HELP;
365                  case 'x':                  case 'x':
# Line 466  static int display_article_key_handler(i Line 486  static int display_article_key_handler(i
486          return 0;          return 0;
487  }  }
488    
489  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
490  {  {
491          static int display_nickname = 0;          static int display_nickname = 0;
492    
493          SECTION_LIST *p_section;          SECTION_LIST *p_section;
494            int64_t section_index;
495            int32_t aid_location;
496          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
497          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
498          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 486  int section_list_display(const char *sna Line 508  int section_list_display(const char *sna
508          int direction;          int direction;
509          ARTICLE article_new;          ARTICLE article_new;
510          int page_id_cur;          int page_id_cur;
511            const ARTICLE *p_article_locate;
512    
513          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname, &section_index);
514          if (p_section == NULL)          if (p_section == NULL)
515          {          {
516                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
# Line 511  int section_list_display(const char *sna Line 534  int section_list_display(const char *sna
534                  return -2;                  return -2;
535          }          }
536    
537            if (aid == 0)
538            {
539                    aid_location = section_aid_locations[section_index];
540            }
541            else
542            {
543                    aid_location = aid;
544            }      
545    
546            // Locate at article with aid_locate
547            if (aid_location > 0)
548            {
549                    p_article_locate = article_block_find_by_aid(aid_location);
550                    if (p_article_locate == NULL)
551                    {
552                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
553                            return -3;
554                    }
555    
556                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
557                                                                                    &page_id, &selected_index, &article_count);
558                    if (ret < 0)
559                    {
560                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
561                                              p_section->sid, p_article_locate->aid);
562                            return -3;
563                    }
564            }
565    
566          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
567          {          {
568                  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 576  int section_list_display(const char *sna
576                  return -3;                  return -3;
577          }          }
578    
579            section_topic_view_tid = -1;
580    
581          if (article_count == 0) // empty section          if (article_count == 0) // empty section
582          {          {
583                  selected_index = 0;                  selected_index = 0;
584          }          }
585            else if (aid > 0)
586            {
587                    // Update current topic
588                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
589    
590                    // Update current aid location
591                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
592            }
593    
594          while (!SYS_server_exit)          while (!SYS_server_exit)
595          {          {
# Line 731  int section_list_display(const char *sna Line 793  int section_list_display(const char *sna
793    
794                          // Update current topic                          // Update current topic
795                          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);
796                            log_error("topic_view_tid=%d\n", section_topic_view_tid);
797    
798                            // Update current aid location
799                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
800    
801                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
802                          {                          {
# Line 842  int section_list_display(const char *sna Line 908  int section_list_display(const char *sna
908                                  return -3;                                  return -3;
909                          }                          }
910                          else if (ret > 0 && page_id != page_id_cur) // found and page changed                          else if (ret > 0 && page_id != page_id_cur) // found and page changed
911                            {
912                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
913                                    if (ret < 0)
914                                    {
915                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
916                                            return -3;
917                                    }
918                            }
919                            break;
920                    case SCAN_NEW_ARTICLE:
921                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
922                            if (ret < 0)
923                            {
924                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
925                                                      p_section->sid, p_articles[selected_index]->aid);
926                                    return -3;
927                            }
928                            else if (ret == 0) // not found
929                            {
930                                    break;
931                            }
932                            page_id_cur = page_id;
933                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
934                                                                                            &page_id, &selected_index, &article_count);
935                            if (ret < 0)
936                            {
937                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
938                                                      p_section->sid, p_article_locate->aid);
939                                    return -3;
940                            }
941                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
942                          {                          {
943                                  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);
944                                  if (ret < 0)                                  if (ret < 0)


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

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