@@ -32,6 +32,20 @@ import {
3232} from "./filter" ;
3333import { atProcess } from "./at" ;
3434
35+ var lastModifies :{ [ key :string ] :Date } = { } ;
36+
37+ export const initlastModifies = async function ( ) {
38+ try {
39+ ( await prisma . forums ( ) ) . forEach ( async item => {
40+ let fid = item . id ;
41+ lastModifies [ fid ] = new Date ( ) ;
42+ } ) ;
43+
44+ } catch ( e ) {
45+ console . log ( e ) ;
46+ }
47+ }
48+
3549export const threadList = async function ( req : Request , res : Response ) {
3650 try {
3751 const authObj = verifyJWT ( req . header ( "Authorization" ) ) ;
@@ -605,6 +619,8 @@ export const threadReply = async function(req: Request, res: Response) {
605619 last : 1
606620 } ) ;
607621
622+ lastModifies [ forumInfo . id ] = new Date ( ) ;
623+
608624 forumLastPostUpdate ( forumInfo . id , resultThread [ 0 ] . id ) ;
609625 let havePushMessage = 0 ;
610626 if ( uid !== authorInfo . id ) {
@@ -673,7 +689,11 @@ export const threadDelete = async function(req: Request, res: Response) {
673689 id : tid
674690 } )
675691 . user ( ) ;
676-
692+ const forumInfo = await prisma
693+ . thread ( {
694+ id : tid
695+ } )
696+ . forum ( ) ;
677697 if ( threadAuthInfo . id !== uid && ! authObj . isAdmin ) {
678698 res . json ( { code : - 1 , msg : "您无权操作此帖子!" } ) ;
679699 return ;
@@ -686,7 +706,7 @@ export const threadDelete = async function(req: Request, res: Response) {
686706 active : false
687707 }
688708 } ) ;
689-
709+ lastModifies [ forumInfo . id ] = new Date ( ) ;
690710 res . json ( { code : 1 } ) ;
691711 }
692712 } catch ( e ) {
@@ -749,7 +769,12 @@ export const threadDiamond = async function(req: Request, res: Response) {
749769 diamond : setDiamond === "1"
750770 }
751771 } ) ;
752-
772+ const forumInfo = await prisma
773+ . thread ( {
774+ id : tid
775+ } )
776+ . forum ( ) ;
777+ lastModifies [ forumInfo . id ] = new Date ( ) ;
753778 const threadAuthor = await prisma
754779 . thread ( {
755780 id : tid
@@ -794,6 +819,12 @@ export const threadTop = async function(req: Request, res: Response) {
794819 top : Number . parseInt ( setTop )
795820 }
796821 } ) ;
822+ const forumInfo = await prisma
823+ . thread ( {
824+ id : tid
825+ } )
826+ . forum ( ) ;
827+ lastModifies [ forumInfo . id ] = new Date ( ) ;
797828 res . json ( { code : 1 } ) ;
798829 }
799830 } catch ( e ) {
@@ -818,6 +849,12 @@ export const threadClose = async function(req: Request, res: Response) {
818849 closed : setClose === "1"
819850 }
820851 } ) ;
852+ const forumInfo = await prisma
853+ . thread ( {
854+ id : tid
855+ } )
856+ . forum ( ) ;
857+ lastModifies [ forumInfo . id ] = new Date ( ) ;
821858 res . json ( { code : 1 } ) ;
822859 }
823860 } catch ( e ) {
@@ -841,7 +878,12 @@ export const threadRecovery = async function(req: Request, res: Response) {
841878 active : true
842879 }
843880 } ) ;
844-
881+ const forumInfo = await prisma
882+ . thread ( {
883+ id : tid
884+ } )
885+ . forum ( ) ;
886+ lastModifies [ forumInfo . id ] = new Date ( ) ;
845887 await prisma . updateManyPosts ( {
846888 where : {
847889 thread : {
@@ -996,6 +1038,69 @@ export const threadUpdate = async function(req: Request, res: Response) {
9961038 }
9971039} ;
9981040
1041+ export const threadGetNew = async function ( req : Request , res : Response ) {
1042+ try {
1043+ let { fid } = req . params ;
1044+ const authObj = verifyJWT ( req . header ( "Authorization" ) ) ;
1045+ const { timestamp } = req . body ;
1046+ if ( parseInt ( timestamp ) < lastModifies [ fid ] . getTime ( ) ) {
1047+ res . json ( { code : 1 , msg : { haveModified : true } } ) ;
1048+ return ;
1049+ }
1050+
1051+
1052+ const whereArr = {
1053+ forum : {
1054+ id : fid
1055+ } ,
1056+ active : authObj . isAdmin ? undefined : true ,
1057+ top : 0
1058+ } ;
1059+
1060+
1061+ let page = 1 ;
1062+ let okFlag = false ;
1063+ let resultArr = [ ] ;
1064+ for ( ; okFlag === false ; ) {
1065+ const resultArrRaw : Array < Thread > = await prisma . threads ( {
1066+ where : whereArr ,
1067+ skip : ( page - 1 ) * pagesize ,
1068+ first : pagesize ,
1069+ orderBy : "lastDate_DESC"
1070+ } ) ;
1071+
1072+ let i = 0 ;
1073+ for ( ; i < resultArrRaw . length ; i ++ ) {
1074+ let item = resultArrRaw [ i ] ;
1075+ if ( ( new Date ( item . lastDate ) ) < ( new Date ( timestamp ) ) ) {
1076+ okFlag = true ;
1077+ break ;
1078+ }
1079+ resultArr . push ( {
1080+ thread : item ,
1081+ user : filterUserInfo (
1082+ await prisma . thread ( { id : item . id } ) . user ( )
1083+ ) ,
1084+ lastReply : await prisma . posts ( {
1085+ where : {
1086+ thread : {
1087+ id : item . id ,
1088+ active : authObj . isAdmin ? undefined : true
1089+ }
1090+ } ,
1091+ orderBy : "createDate_DESC" ,
1092+ first : 1
1093+ } )
1094+ } )
1095+ }
1096+ if ( okFlag === true || i === resultArrRaw . length ) break ;
1097+ }
1098+ res . json ( { code : 1 , msg : { list : resultArr } } ) ;
1099+ } catch ( e ) {
1100+ res . json ( { code : - 1 } ) ;
1101+ }
1102+ }
1103+
9991104export const threadMove = async function ( req : Request , res : Response ) {
10001105 try {
10011106 const { uid, isAdmin } = verifyJWT ( req . header ( "Authorization" ) ) ;
@@ -1058,6 +1163,8 @@ export const threadMove = async function(req: Request, res: Response) {
10581163 }
10591164 }
10601165 } ) ;
1166+ lastModifies [ previousForum . id ] = new Date ( ) ;
1167+ lastModifies [ newForum . id ] = new Date ( ) ;
10611168 res . json ( { code : 1 } ) ;
10621169 } catch ( e ) {
10631170 res . json ( { code : - 1 , msg : e . message } ) ;
0 commit comments