6
6
using System . Threading . Tasks ;
7
7
8
8
using Microsoft . AspNetCore . SignalR ;
9
+
9
10
using UpSkill . Data . Common . Repositories ;
10
11
using UpSkill . Data . Models ;
11
12
using UpSkill . Web . ViewModels . Chat ;
12
13
13
14
public class ChatHub : Hub
14
15
{
16
+ private const string Room = "devs" ;
15
17
private readonly string bot ;
16
- private const string room = "devs" ;
17
-
18
18
19
19
private readonly IRepository < Message > messages ;
20
20
@@ -32,13 +32,13 @@ public ChatHub(
32
32
public async Task JoinRoom ( UserConnection userConnection )
33
33
{
34
34
await this . Groups
35
- . AddToGroupAsync ( this . Context . ConnectionId , room ) ;
35
+ . AddToGroupAsync ( this . Context . ConnectionId , Room ) ;
36
36
37
37
this . connections [ this . Context . ConnectionId ] = userConnection ;
38
38
39
39
await this . Clients
40
- . Group ( room )
41
- . SendAsync ( "ReceiveMessage" , this . bot , $ "{ userConnection . Name } has joined the { room } room!", DateTime . UtcNow . ToString ( ) , userConnection . Name ) ;
40
+ . Group ( Room )
41
+ . SendAsync ( "ReceiveMessage" , this . bot , $ "{ userConnection . Name } has joined the { Room } room!", DateTime . UtcNow . ToString ( ) , userConnection . Name ) ;
42
42
}
43
43
44
44
public async Task Send ( string message , string user )
@@ -56,7 +56,7 @@ public async Task Send(string message, string user)
56
56
await this . messages . AddAsync ( messageDb ) ;
57
57
await this . messages . SaveChangesAsync ( ) ;
58
58
59
- await this . Clients . Group ( room )
59
+ await this . Clients . Group ( Room )
60
60
. SendAsync ( "ReceiveMessage" , userConnection . Name , message , currentTime . ToString ( "H:mm" ) , user ) ;
61
61
}
62
62
}
@@ -83,12 +83,11 @@ public override async Task OnDisconnectedAsync(Exception exception)
83
83
{
84
84
this . connections . Remove ( this . Context . ConnectionId ) ;
85
85
86
- await this . Clients . Group ( room )
86
+ await this . Clients . Group ( Room )
87
87
. SendAsync ( "ReceiveMessage" , this . bot , $ "{ userConnection . Name } has left!", DateTime . UtcNow . ToString ( ) , this . bot ) ;
88
88
}
89
89
90
90
await base . OnDisconnectedAsync ( exception ) ;
91
91
}
92
-
93
92
}
94
93
}
0 commit comments