/[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.13 by sysadm, Sat May 31 12:38:35 2025 UTC Revision 1.26 by sysadm, Sun Jun 15 04:45:13 2025 UTC
# Line 17  Line 17 
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 "article_del.h"
22  #include "common.h"  #include "common.h"
23  #include "io.h"  #include "io.h"
24  #include "screen.h"  #include "screen.h"
25  #include "log.h"  #include "log.h"
26    #include "user_priv.h"
27    #include "article_view_log.h"
28  #include "str_process.h"  #include "str_process.h"
29  #include <time.h>  #include <time.h>
30  #include <sys/param.h>  #include <sys/param.h>
# Line 37  enum select_cmd_t Line 41  enum select_cmd_t
41          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
42          REFRESH_SCREEN = 3,          REFRESH_SCREEN = 3,
43          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY = 4,
44            POST_ARTICLE = 5,
45            EDIT_ARTICLE = 6,
46            DELETE_ARTICLE = 7,
47  };  };
48    
49  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 49  static int section_list_draw_items(int p Line 56  static int section_list_draw_items(int p
56          int len;          int len;
57          int i;          int i;
58          char article_flag;          char article_flag;
59            int is_viewed;
60          time_t tm_now;          time_t tm_now;
61    
62          time(&tm_now);          time(&tm_now);
# Line 57  static int section_list_draw_items(int p Line 65  static int section_list_draw_items(int p
65    
66          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
67          {          {
68                  article_flag = ' ';                  if (p_articles[i]->uid == BBS_priv.uid)
69                    {
70                            is_viewed = 1;
71                    }
72                    else
73                    {
74                            is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);
75                            if (is_viewed < 0)
76                            {
77                                    log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid);
78                                    is_viewed = 0;
79                            }
80                    }
81    
82                    article_flag = (is_viewed ? ' ' : 'N');
83    
84                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
85                  {                  {
86                          article_flag = 'm';                          article_flag = (is_viewed ? 'm' : 'M');
87                  }                  }
88                  else if (p_articles[i]->lock)                  else if (p_articles[i]->lock && is_viewed)
89                  {                  {
90                          article_flag = 'x';                          article_flag = 'x';
91                  }                  }
# Line 90  static int section_list_draw_items(int p Line 112  static int section_list_draw_items(int p
112    
113                  moveto(4 + i, 1);                  moveto(4 + i, 1);
114                  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",
115                             (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" : "")),
116                             p_articles[i]->aid,                             p_articles[i]->aid,
117                             article_flag,                             article_flag,
118                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
# Line 98  static int section_list_draw_items(int p Line 120  static int section_list_draw_items(int p
120                                                                   : 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))),
121                             "",                             "",
122                             str_time,                             str_time,
123                             (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" : "")),
124                             title_f);                             title_f);
125          }          }
126    
# Line 120  static int section_list_draw_screen(cons Line 142  static int section_list_draw_screen(cons
142          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
143          moveto(2, 0);          moveto(2, 0);
144          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] "
145                     "阅读[\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] "
146                       "修改[\033[1;32mE\033[0;37m] 删除[\033[1;32md\033[0;37m] %s[\033[1;32mn\033[0;37m]\033[m",
147                     (display_nickname ? "显示用户名" : "显示昵称"));                     (display_nickname ? "显示用户名" : "显示昵称"));
148          moveto(3, 0);          moveto(3, 0);
149          if (display_nickname)          if (display_nickname)
# Line 176  static enum select_cmd_t section_list_se Line 199  static enum select_cmd_t section_list_se
199                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
200                          }                          }
201                          break;                          break;
202                    case Ctrl('P'):
203                            return POST_ARTICLE;
204                    case 'E':
205                            return EDIT_ARTICLE;
206                    case 'd':
207                            return DELETE_ARTICLE;
208                  case KEY_HOME:                  case KEY_HOME:
209                          *p_page_id = 0;                          *p_page_id = 0;
210                  case KEY_PGUP:                  case KEY_PGUP:
# Line 212  static enum select_cmd_t section_list_se Line 241  static enum select_cmd_t section_list_se
241                                          (*p_page_id)++;                                          (*p_page_id)++;
242                                          *p_selected_index = 0;                                          *p_selected_index = 0;
243                                  }                                  }
244                                    else // end of last page
245                                    {
246                                            return CHANGE_PAGE; // force refresh pages
247                                    }
248                          }                          }
249                          else                          else
250                          {                          {
# Line 259  static int display_article_key_handler(i Line 292  static int display_article_key_handler(i
292                  if (section_topic_view_mode)                  if (section_topic_view_mode)
293                  {                  {
294                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
295                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
296                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
297                                           "模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
298                  }                  }
299                  else                  else
300                  {                  {
301                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
302                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
303                                           "移动[\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] "
304                                           "模式[\033[32mp\033[33m] | 帮助[\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
305                  }                  }
306                  *p_key = 0;                  *p_key = 0;
307                  break;                  break;
308            case 'r': // Reply article
309                    return 1;
310          case KEY_UP:          case KEY_UP:
311            case KEY_PGUP:
312            case KEY_HOME:
313                  if (p_ctx->reach_begin)                  if (p_ctx->reach_begin)
314                  {                  {
315                          if (section_topic_view_mode)                          if (section_topic_view_mode)
316                          {                          {
317                                  *p_key = KEY_PGUP;                                  *p_key = KEY_PGUP;
318                          }                          }
319                            else
320                            {
321                                    *p_key = KEY_UP;
322                            }
323                          return 1;                          return 1;
324                  }                  }
325                  break;                  break;
326          case KEY_DOWN:          case KEY_DOWN:
327            case KEY_PGDN:
328            case KEY_END:
329                  if (p_ctx->reach_end)                  if (p_ctx->reach_end)
330                  {                  {
331                          if (section_topic_view_mode)                          if (section_topic_view_mode)
332                          {                          {
333                                  *p_key = KEY_PGDN;                                  *p_key = KEY_PGDN;
334                          }                          }
335                            else
336                            {
337                                    *p_key = KEY_DOWN;
338                            }
339                          return 1;                          return 1;
340                  }                  }
341                  break;                  break;
# Line 314  int section_list_display(const char *sna Line 361  int section_list_display(const char *sna
361          int ret;          int ret;
362          int loop;          int loop;
363          int direction;          int direction;
364            ARTICLE article_new;
365    
366          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
367          if (p_section == NULL)          if (p_section == NULL)
# Line 405  int section_list_display(const char *sna Line 453  int section_list_display(const char *sna
453                                          break;                                          break;
454                                  }                                  }
455    
456                                  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,
457                                                                     display_article_key_handler, DATA_READ_HELP);                                                                     display_article_key_handler, DATA_READ_HELP);
458    
459                                  if (article_cache_unload(&cache) < 0)                                  if (article_cache_unload(&cache) < 0)
# Line 414  int section_list_display(const char *sna Line 462  int section_list_display(const char *sna
462                                          break;                                          break;
463                                  }                                  }
464    
465                                    // Update article_view_log
466                                    if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0)
467                                    {
468                                            log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid);
469                                    }
470    
471                                  switch (ret)                                  switch (ret)
472                                  {                                  {
473                                  case KEY_UP:                                  case KEY_UP:
# Line 499  int section_list_display(const char *sna Line 553  int section_list_display(const char *sna
553                                                  loop = 1;                                                  loop = 1;
554                                          }                                          }
555                                          break;                                          break;
556                                    case 'r': // Reply article
557                                            if (article_reply(p_section, p_articles[selected_index], &article_new) < 0)
558                                            {
559                                                    log_error("article_post(aid=%d, REPLY) error\n", p_articles[selected_index]->aid);
560                                            }
561                                            loop = 1;
562                                            break;
563                                  }                                  }
564                          } while (loop);                          } while (loop);
565    
# Line 516  int section_list_display(const char *sna Line 577  int section_list_display(const char *sna
577                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
578                          {                          {
579                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
580                                    return -2;
581                            }
582                            break;
583                    case POST_ARTICLE:
584                            ret = article_post(p_section, &article_new);
585                            if (ret < 0)
586                            {
587                                    log_error("article_post(sid=%d) error\n", p_section->sid);
588                            }
589                            else if (ret > 0) // New article posted
590                            {
591                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count);
592                                    if (ret < 0)
593                                    {
594                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
595                                            return -3;
596                                    }
597                            }
598                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
599                            {
600                                    log_error("section_list_draw_screen() error\n");
601                                    return -2;
602                            }
603                            break;
604                    case EDIT_ARTICLE:
605                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
606                                    p_articles[selected_index]->uid != BBS_priv.uid)
607                            {
608                                    break; // No permission
609                            }
610                            if (article_modify(p_section, p_articles[selected_index], &article_new) < 0)
611                            {
612                                    log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid);
613                            }
614                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
615                            {
616                                    log_error("section_list_draw_screen() error\n");
617                                    return -2;
618                            }
619                            break;
620                    case DELETE_ARTICLE:
621                            if (!checkpriv(&BBS_priv, p_section->sid, S_POST) ||
622                                    (!checkpriv(&BBS_priv, p_section->sid, S_MAN_S) && p_articles[selected_index]->uid != BBS_priv.uid))
623                            {
624                                    break; // No permission
625                            }
626                            if (article_del(p_section, p_articles[selected_index]) < 0)
627                            {
628                                    log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid);
629                            }
630                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
631                            {
632                                    log_error("section_list_draw_screen() error\n");
633                                  return -2;                                  return -2;
634                          }                          }
635                          break;                          break;


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

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