/[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.28 by sysadm, Mon Jun 16 03:08:29 2025 UTC Revision 1.31 by sysadm, Tue Jun 17 07:00:32 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #define _POSIX_C_SOURCE 200809L
18    
19  #include "section_list_display.h"  #include "section_list_display.h"
20  #include "section_list_loader.h"  #include "section_list_loader.h"
21  #include "article_cache.h"  #include "article_cache.h"
# Line 26  Line 28 
28  #include "user_priv.h"  #include "user_priv.h"
29  #include "article_view_log.h"  #include "article_view_log.h"
30  #include "str_process.h"  #include "str_process.h"
31    #include <string.h>
32  #include <time.h>  #include <time.h>
33  #include <sys/param.h>  #include <sys/param.h>
 #define _POSIX_C_SOURCE 200809L  
 #include <string.h>  
34    
35  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
36  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
# Line 39  enum select_cmd_t Line 40  enum select_cmd_t
40          EXIT_SECTION = 0,          EXIT_SECTION = 0,
41          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
42          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
43          REFRESH_SCREEN = 3,          SHOW_HELP = 3,
44          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY = 4,
45          POST_ARTICLE = 5,          POST_ARTICLE = 5,
46          EDIT_ARTICLE = 6,          EDIT_ARTICLE = 6,
47          DELETE_ARTICLE = 7,          DELETE_ARTICLE = 7,
48          SHOW_HELP = 8,          FIRST_TOPIC_ARTICLE = 8,
49            LAST_TOPIC_ARTICLE = 9,
50  };  };
51    
52  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)
# Line 164  static enum select_cmd_t section_list_se Line 166  static enum select_cmd_t section_list_se
166          int old_page_id = *p_page_id;          int old_page_id = *p_page_id;
167          int old_selected_index = *p_selected_index;          int old_selected_index = *p_selected_index;
168          int ch;          int ch;
169            time_t last_refresh_tm = time(NULL);
         BBS_last_access_tm = time(0);  
170    
171          if (item_count > 0 && *p_selected_index >= 0)          if (item_count > 0 && *p_selected_index >= 0)
172          {          {
# Line 180  static enum select_cmd_t section_list_se Line 181  static enum select_cmd_t section_list_se
181    
182                  switch (ch)                  switch (ch)
183                  {                  {
                 case KEY_NULL: // broken pipe  
184                  case KEY_ESC:                  case KEY_ESC:
185                  case KEY_LEFT:                  case KEY_LEFT:
186                            BBS_last_access_tm = time(NULL);
187                    case KEY_NULL:                   // broken pipe
188                          return EXIT_SECTION; // exit section                          return EXIT_SECTION; // exit section
189                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
190                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
191                          {                          {
192                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
193                          }                          }
194                          continue;                          continue;
195                  case 'n':                  case 'n':
196                            BBS_last_access_tm = time(NULL);
197                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
198                  case CR:                  case CR:
199                          igetch_reset();                          igetch_reset();
# Line 198  static enum select_cmd_t section_list_se Line 201  static enum select_cmd_t section_list_se
201                  case KEY_RIGHT:                  case KEY_RIGHT:
202                          if (item_count > 0)                          if (item_count > 0)
203                          {                          {
204                                    BBS_last_access_tm = time(NULL);
205                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
206                          }                          }
207                          break;                          break;
# Line 258  static enum select_cmd_t section_list_se Line 262  static enum select_cmd_t section_list_se
262                                  (*p_selected_index)++;                                  (*p_selected_index)++;
263                          }                          }
264                          break;                          break;
265                    case '=':
266                            return FIRST_TOPIC_ARTICLE;
267                    case '\\':
268                            return LAST_TOPIC_ARTICLE;
269                  case 'h':                  case 'h':
270                          return SHOW_HELP;                          return SHOW_HELP;
271                  default:                  default:
# Line 285  static enum select_cmd_t section_list_se Line 293  static enum select_cmd_t section_list_se
293                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
294                  }                  }
295    
296                  BBS_last_access_tm = time(0);                  BBS_last_access_tm = time(NULL);
297                    if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
298                    {
299                            return CHANGE_PAGE; // force section list refresh
300                    }
301          }          }
302    
303          return EXIT_SECTION;          return EXIT_SECTION;
# Line 317  static int display_article_key_handler(i Line 329  static int display_article_key_handler(i
329                  break;                  break;
330          case 'r': // Reply article          case 'r': // Reply article
331                  return 1;                  return 1;
332            case '=': // First topic article
333                    return 1;
334            case '\\': // Last topic article
335                    return 1;
336          case KEY_UP:          case KEY_UP:
337          case KEY_PGUP:          case KEY_PGUP:
338          case KEY_HOME:          case KEY_HOME:
# Line 392  int section_list_display(const char *sna Line 408  int section_list_display(const char *sna
408          int loop;          int loop;
409          int direction;          int direction;
410          ARTICLE article_new;          ARTICLE article_new;
411            int page_id_cur;
412    
413          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
414          if (p_section == NULL)          if (p_section == NULL)
# Line 565  int section_list_display(const char *sna Line 582  int section_list_display(const char *sna
582                                  case KEY_PGUP:                                  case KEY_PGUP:
583                                  case KEY_PGDN:                                  case KEY_PGDN:
584                                          direction = (ret == KEY_PGUP ? -1 : 1);                                          direction = (ret == KEY_PGUP ? -1 : 1);
585                                          ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count);                                          ret = locate_article_in_section(p_section, p_articles[selected_index], direction, 1,
586                                                                                                            &page_id, &selected_index, &article_count);
587                                          if (ret < 0)                                          if (ret < 0)
588                                          {                                          {
589                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n",                                                  log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n",
590                                                                    p_section->sid, p_articles[selected_index]->aid, direction);                                                                    p_section->sid, p_articles[selected_index]->aid, direction);
591                                                  return -3;                                                  return -3;
592                                          }                                          }
593                                          else if (ret > 0)                                          else if (ret > 0) // found
594                                          {                                          {
595                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);                                                  ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
596                                                  if (ret < 0)                                                  if (ret < 0)
# Line 590  int section_list_display(const char *sna Line 608  int section_list_display(const char *sna
608                                          }                                          }
609                                          loop = 1;                                          loop = 1;
610                                          break;                                          break;
611                                    case '=':  // First topic article
612                                    case '\\': // Last topic article
613                                            page_id_cur = page_id;
614                                            direction = (ret == '=' ? -1 : 1);
615                                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
616                                                                                                            &page_id, &selected_index, &article_count);
617                                            if (ret < 0)
618                                            {
619                                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
620                                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
621                                                    return -3;
622                                            }
623                                            else if (ret > 0) // found
624                                            {
625                                                    if (page_id != page_id_cur) // page changed
626                                                    {
627                                                            ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
628                                                            if (ret < 0)
629                                                            {
630                                                                    log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
631                                                                    return -3;
632                                                            }
633                                                    }
634                                                    loop = 1;
635                                            }
636                                            break;
637                                  }                                  }
638                          } while (loop);                          } while (loop);
639    
640                          // Update current topic                          // Update current topic
641                          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);
                 case REFRESH_SCREEN:  
                         if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)  
                         {  
                                 log_error("section_list_draw_screen() error\n");  
                                 return -2;  
                         }  
                         break;  
642                  case CHANGE_NAME_DISPLAY:                  case CHANGE_NAME_DISPLAY:
643                          display_nickname = !display_nickname;                          display_nickname = !display_nickname;
644                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
# Line 611  int section_list_display(const char *sna Line 648  int section_list_display(const char *sna
648                          }                          }
649                          break;                          break;
650                  case POST_ARTICLE:                  case POST_ARTICLE:
651                          ret = article_post(p_section, &article_new);                          if ((ret = article_post(p_section, &article_new)) < 0)
                         if (ret < 0)  
652                          {                          {
653                                  log_error("article_post(sid=%d) error\n", p_section->sid);                                  log_error("article_post(sid=%d) error\n", p_section->sid);
654                          }                          }
# Line 653  int section_list_display(const char *sna Line 689  int section_list_display(const char *sna
689                          {                          {
690                                  break; // No permission                                  break; // No permission
691                          }                          }
692                          if (article_del(p_section, p_articles[selected_index]) < 0)                          if ((ret = article_del(p_section, p_articles[selected_index])) < 0)
693                          {                          {
694                                  log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);                                  log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
695                          }                          }
696                            else if (ret > 0) // Article deleted
697                            {
698                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
699                                    if (ret < 0)
700                                    {
701                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
702                                            return -3;
703                                    }
704                            }
705                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
706                          {                          {
707                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
708                                  return -2;                                  return -2;
709                          }                          }
710                          break;                          break;
711                    case FIRST_TOPIC_ARTICLE:
712                    case LAST_TOPIC_ARTICLE:
713                            page_id_cur = page_id;
714                            direction = (ret == FIRST_TOPIC_ARTICLE ? -1 : 1);
715                            ret = locate_article_in_section(p_section, p_articles[selected_index], direction, BBS_article_limit_per_section,
716                                                                                            &page_id, &selected_index, &article_count);
717                            if (ret < 0)
718                            {
719                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n",
720                                                      p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section);
721                                    return -3;
722                            }
723                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
724                            {
725                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
726                                    if (ret < 0)
727                                    {
728                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
729                                            return -3;
730                                    }
731                            }
732                            break;
733                  case SHOW_HELP:                  case SHOW_HELP:
734                          // Display help information                          // Display help information
735                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);


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

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