/[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.49 by sysadm, Mon Oct 13 07:40:35 2025 UTC Revision 1.54 by sysadm, Thu Oct 16 11:26:16 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 49  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,          SCAN_NEW_ARTICLE,
# Line 68  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 90  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 136  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 145  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 161  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 235  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:
281                          igetch_reset();                          igetch_reset();
# Line 257  static enum select_cmd_t section_list_se Line 283  static enum select_cmd_t section_list_se
283                  case KEY_RIGHT:                  case KEY_RIGHT:
284                          if (item_count > 0)                          if (item_count > 0)
285                          {                          {
                                 BBS_last_access_tm = time(NULL);  
286                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
287                          }                          }
288                          break;                          break;
# Line 281  static enum select_cmd_t section_list_se Line 306  static enum select_cmd_t section_list_se
306                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
307                          }                          }
308                          break;                          break;
309                    case 'F':
310                            if (item_count > 0)
311                            {
312                                    return SET_FAVOR_ARTICLE;
313                            }
314                            break;
315                    case '-':
316                            if (item_count > 0)
317                            {
318                                    return UNSET_FAVOR_ARTICLE;
319                            }
320                            break;
321                  case KEY_HOME:                  case KEY_HOME:
322                          *p_page_id = 0;                          *p_page_id = 0;
323                  case 'P':                  case 'P':
# Line 393  static enum select_cmd_t section_list_se Line 430  static enum select_cmd_t section_list_se
430                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
431                  }                  }
432    
                 BBS_last_access_tm = time(NULL);  
433                  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)
434                  {                  {
435                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 514  int section_list_display(const char *sna Line 550  int section_list_display(const char *sna
550          int page_id_cur;          int page_id_cur;
551          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
552    
553          p_section = section_list_find_by_name(sname, &section_index);          p_section = section_list_find_by_name(sname);
554          if (p_section == NULL)          if (p_section == NULL)
555          {          {
556                  log_error("Section %s not found\n", sname);                  log_error("Section %s not found\n", sname);
557                  return -1;                  return -1;
558          }          }
559    
560            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
561            {
562                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
563                                      p_section->sid, BBS_priv.uid);
564                    return -1;
565            }
566    
567            section_index = get_section_index(p_section);
568    
569          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
570          {          {
571                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 545  int section_list_display(const char *sna Line 590  int section_list_display(const char *sna
590          else          else
591          {          {
592                  aid_location = aid;                  aid_location = aid;
593          }                }
594    
595          // Locate at article with aid_locate          // Locate at article with aid_locate
596          if (aid_location > 0)          if (aid_location > 0)
# Line 898  int section_list_display(const char *sna Line 943  int section_list_display(const char *sna
943                                  return -2;                                  return -2;
944                          }                          }
945                          break;                          break;
946                    case SET_FAVOR_ARTICLE:
947                            ret = article_favor_set(p_articles[selected_index]->tid == 0
948                                                                                    ? p_articles[selected_index]->aid
949                                                                                    : p_articles[selected_index]->tid,
950                                                                            &BBS_article_favor, 1);
951                            if (ret < 0)
952                            {
953                                    log_error("article_favor_set(aid=%d, 1) error\n",
954                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
955                            }
956                            break;
957                    case UNSET_FAVOR_ARTICLE:
958                            ret = article_favor_set(p_articles[selected_index]->tid == 0
959                                                                                    ? p_articles[selected_index]->aid
960                                                                                    : p_articles[selected_index]->tid,
961                                                                            &BBS_article_favor, 0);
962                            if (ret < 0)
963                            {
964                                    log_error("article_favor_set(aid=%d, 0) error\n",
965                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
966                            }
967                            break;
968                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
969                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
970                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 1027  int section_list_ex_dir_display(SECTION_ Line 1094  int section_list_ex_dir_display(SECTION_
1094                  {                  {
1095                          iflush();                          iflush();
1096                          ch = igetch(100);                          ch = igetch(100);
1097    
1098                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1099                            {
1100                                    BBS_last_access_tm = time(NULL);
1101                            }
1102    
1103                          switch (ch)                          switch (ch)
1104                          {                          {
1105                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1106                                    log_error("KEY_NULL\n");
1107                                  return 0;                                  return 0;
1108                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1109                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1110                                  {                                  {
1111                                            log_error("User input timeout\n");
1112                                          return 0;                                          return 0;
1113                                  }                                  }
1114                                  continue;                                  continue;
# Line 1057  int section_list_ex_dir_display(SECTION_ Line 1132  int section_list_ex_dir_display(SECTION_
1132                                  }                                  }
1133                          }                          }
1134    
                         BBS_last_access_tm = time(NULL);  
   
1135                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1136                          {                          {
1137                                  break;                                  break;


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

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