File tree Expand file tree Collapse file tree 5 files changed +28
-11
lines changed
Expand file tree Collapse file tree 5 files changed +28
-11
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ export default async function handler(
8888 pageId : string
8989 }
9090
91+ const timezoneOffsetInHour = req . headers [ 'x-timezone-offset' ]
92+
9193 const isDeleted = await projectService . isDeleted ( query . appId )
9294
9395 if ( isDeleted ) {
@@ -121,15 +123,19 @@ export default async function handler(
121123 } ,
122124 )
123125
124- const comments = await commentService . getComments ( query . appId , {
125- approved : true ,
126- parentId : null ,
127- pageSlug : query . pageId ,
128- page : Number ( query . page ) || 1 ,
129- select : {
130- by_nickname : true ,
126+ const comments = await commentService . getComments (
127+ query . appId ,
128+ Number ( timezoneOffsetInHour ) ,
129+ {
130+ approved : true ,
131+ parentId : null ,
132+ pageSlug : query . pageId ,
133+ page : Number ( query . page ) || 1 ,
134+ select : {
135+ by_nickname : true ,
136+ } ,
131137 } ,
132- } )
138+ )
133139
134140 queryCommentStat . end ( )
135141
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ export default async function handler(
1818 page : string
1919 }
2020
21+ const timezoneOffsetInHour = req . headers [ 'x-timezone-offset' ] || 0
22+
2123 // only owner can get comments
2224 const project = ( await projectService . get ( projectId , {
2325 select : {
@@ -36,7 +38,7 @@ export default async function handler(
3638 }
3739 } )
3840
39- const comments = await commentService . getComments ( projectId , {
41+ const comments = await commentService . getComments ( projectId , Number ( timezoneOffsetInHour ) , {
4042 parentId : null ,
4143 page : Number ( page ) ,
4244 onlyOwn : true ,
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import { statService } from './stat.service'
99import { EmailService } from './email.service'
1010import { TokenService } from './token.service'
1111import { makeConfirmReplyNotificationTemplate } from '../templates/confirm_reply_notification'
12+ import utc from 'dayjs/plugin/utc'
13+ dayjs . extend ( utc )
1214
1315export const markdown = MarkdownIt ( {
1416 linkify : true ,
@@ -39,6 +41,7 @@ export class CommentService extends RequestScopeService {
3941
4042 async getComments (
4143 projectId : string ,
44+ timezoneOffset : number ,
4245 options ?: {
4346 parentId ?: string
4447 page ?: number
@@ -105,7 +108,7 @@ export class CommentService extends RequestScopeService {
105108 const allComments = await Promise . all (
106109 comments . map ( async ( comment : Comment ) => {
107110 // get replies
108- const replies = await this . getComments ( projectId , {
111+ const replies = await this . getComments ( projectId , timezoneOffset , {
109112 ...options ,
110113 page : 1 ,
111114 // hard code 100 because we havent implement pagination in nested comment
@@ -115,7 +118,7 @@ export class CommentService extends RequestScopeService {
115118 select,
116119 } )
117120
118- const parsedCreatedAt = dayjs ( comment . createdAt ) . format (
121+ const parsedCreatedAt = dayjs . utc ( comment . createdAt ) . utcOffset ( timezoneOffset ) . format (
119122 'YYYY-MM-DD HH:mm' ,
120123 )
121124 const parsedContent = markdown . render ( comment . content ) as string
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import axios from "axios";
22
33export const apiClient = axios . create ( {
44 baseURL : "/api" ,
5+ headers : {
6+ 'x-timezone-offset' : - new Date ( ) . getTimezoneOffset ( )
7+ }
58} ) ;
69
710export const VERSION = '1.1.4'
Original file line number Diff line number Diff line change 3939 loadingComments = true
4040 try {
4141 const res = await api .get (` /api/open/comments` , {
42+ headers: {
43+ ' x-timezone-offset' : - new Date ().getTimezoneOffset ()
44+ },
4245 params: {
4346 page: p,
4447 appId: attrs .appId ,
You can’t perform that action at this time.
0 commit comments