@@ -2,16 +2,39 @@ import 'reflect-metadata';
2
2
import { inject } from 'inversify' ;
3
3
import { TYPES } from '../../core/types.di' ;
4
4
import { UserService } from './service/user.service' ;
5
+ import { RedisService } from '../shared/redis/redis.service' ;
6
+ import { MessageService } from '../message/service/message.service' ;
5
7
6
8
export class User {
7
9
constructor (
8
10
@inject ( TYPES . UserService ) private readonly userService : UserService ,
11
+ @inject ( TYPES . MessageService )
12
+ private readonly messageService : MessageService ,
13
+ @inject ( TYPES . RedisService ) private readonly redisService : RedisService ,
9
14
) { }
10
15
11
16
async profile ( accessToken : string ) {
12
17
return this . userService . profile ( accessToken ) ;
13
18
}
14
19
20
+ /**This method uses only Redis as of now
21
+ * TODO - Add support for app cache!
22
+ */
23
+ async sendMessage ( userId : string , message : string ) {
24
+ let channelId : string ;
25
+
26
+ const getUserChannel = await this . redisService . get ( `userChannel:${ userId } ` ) ;
27
+ channelId = getUserChannel ;
28
+
29
+ if ( ! getUserChannel ) {
30
+ const channel = await this . userService . createChannel ( userId ) ;
31
+ channelId = channel . id ;
32
+
33
+ await this . redisService . set ( `userChannel:${ userId } ` , channel . id ) ;
34
+ }
35
+ return this . messageService . sendMessage ( channelId , message ) ;
36
+ }
37
+
15
38
async guilds ( accessToken : string ) {
16
39
return this . userService . guilds ( accessToken ) ;
17
40
}
0 commit comments