/[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.17 by sysadm, Sat Jun 7 10:00:10 2025 UTC Revision 1.27 by sysadm, Mon Jun 16 01:36:56 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"  #include "article_view_log.h"
28  #include "str_process.h"  #include "str_process.h"
29  #include <time.h>  #include <time.h>
# Line 38  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 59  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                  is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log);                  if (p_articles[i]->uid == BBS_priv.uid)
                 if (is_viewed < 0)  
69                  {                  {
70                          log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid);                          is_viewed = 1;
71                          is_viewed = 0;                  }
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');                  article_flag = (is_viewed ? ' ' : 'N');
# Line 91  static int section_list_draw_items(int p Line 104  static int section_list_draw_items(int p
104                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
105                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
106                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
107                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len);                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);
108                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
109                  {                  {
110                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 129  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 185  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 221  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 268  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:          case KEY_PGUP:
312          case KEY_HOME:          case KEY_HOME:
# Line 335  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 426  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 526  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 543  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