File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 830
830
}
831
831
}
832
832
},
833
+ "/chat.message/getMessage" : {
834
+ "post" : {
835
+ "requestBody" : {
836
+ "content" : {
837
+ "application/json" : {
838
+ "schema" : {
839
+ "type" : " object" ,
840
+ "properties" : {
841
+ "messageId" : {
842
+ "type" : " string"
843
+ }
844
+ }
845
+ }
846
+ }
847
+ }
848
+ }
849
+ }
850
+ },
833
851
"/chat.message/deleteMessage" : {
834
852
"post" : {
835
853
"requestBody" : {
Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ class MessageService extends TcService {
59
59
messageId : 'string' ,
60
60
} ,
61
61
} ) ;
62
+ this . registerAction ( 'getMessage' , this . getMessage , {
63
+ params : {
64
+ messageId : 'string' ,
65
+ } ,
66
+ } ) ;
62
67
this . registerAction ( 'deleteMessage' , this . deleteMessage , {
63
68
params : {
64
69
messageId : 'string' ,
@@ -332,6 +337,35 @@ class MessageService extends TcService {
332
337
return json ;
333
338
}
334
339
340
+ /**
341
+ * 获取消息
342
+ */
343
+ async getMessage ( ctx : TcContext < { messageId : string } > ) {
344
+ const { messageId } = ctx . params ;
345
+ const { t, userId } = ctx . meta ;
346
+ const message = await this . adapter . model . findById ( messageId ) ;
347
+ if ( ! message ) {
348
+ throw new DataNotFoundError ( t ( '该消息未找到' ) ) ;
349
+ }
350
+ const converseId = String ( message . converseId ) ;
351
+ const groupId = message . groupId ;
352
+ // 鉴权
353
+ if ( ! groupId ) {
354
+ // 私人会话
355
+ const converseInfo = await call ( ctx ) . getConverseInfo ( converseId ) ;
356
+ if ( ! converseInfo . members . map ( ( m ) => String ( m ) ) . includes ( userId ) ) {
357
+ throw new NoPermissionError ( t ( '没有当前会话权限' ) ) ;
358
+ }
359
+ } else {
360
+ // 群组会话
361
+ const groupInfo = await call ( ctx ) . getGroupInfo ( String ( groupId ) ) ;
362
+ if ( ! groupInfo . members . map ( ( m ) => m . userId ) . includes ( userId ) ) {
363
+ throw new NoPermissionError ( t ( '没有当前会话权限' ) ) ;
364
+ }
365
+ }
366
+ return message ;
367
+ }
368
+
335
369
/**
336
370
* 删除消息
337
371
* 仅支持群组
You can’t perform that action at this time.
0 commit comments