Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Magne.Stenseng
inf226-2021-inchat
Commits
f79dbb14
Commit
f79dbb14
authored
Nov 14, 2021
by
Magne.Stenseng
Browse files
Replace InChat.java
parent
f4cf8482
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/inf226/inchat/InChat.java
View file @
f79dbb14
...
...
@@ -30,14 +30,10 @@ public class InChat {
private
final
EventStorage
eventStore
;
private
final
AccountStorage
accountStore
;
private
final
SessionStorage
sessionStore
;
private
final
Map
<
UUID
,
List
<
Consumer
<
Channel
.
Event
>>>
eventCallbacks
=
new
TreeMap
<
UUID
,
List
<
Consumer
<
Channel
.
Event
>>>();
private
final
Map
<
UUID
,
List
<
Consumer
<
Channel
.
Event
>>>
eventCallbacks
=
new
TreeMap
<
UUID
,
List
<
Consumer
<
Channel
.
Event
>>>();
public
InChat
(
UserStorage
userStore
,
ChannelStorage
channelStore
,
AccountStorage
accountStore
,
SessionStorage
sessionStore
,
Connection
connection
)
{
public
InChat
(
UserStorage
userStore
,
ChannelStorage
channelStore
,
AccountStorage
accountStore
,
SessionStorage
sessionStore
,
Connection
connection
)
{
this
.
userStore
=
userStore
;
this
.
channelStore
=
channelStore
;
this
.
eventStore
=
channelStore
.
eventStore
;
...
...
@@ -83,14 +79,15 @@ public class InChat {
/**
* Log in a user to the chat.
*/
public
Maybe
<
Stored
<
Session
>>
login
(
final
String
username
,
final
String
password
)
{
public
Maybe
<
Stored
<
Session
>>
login
(
final
String
username
,
final
String
password1
)
{
Password
password
=
new
Password
(
password1
);
return
atomic
(
result
->
{
final
Stored
<
Account
>
account
=
accountStore
.
lookup
(
username
);
final
Stored
<
Session
>
session
=
sessionStore
.
save
(
new
Session
(
account
,
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
)));
// Check that password is not incorrect and not too long.
if
(!(!
account
.
value
.
password
.
equals
(
password
)
&&
!(
password
.
l
ength
()
>
1000
)))
{
if
(!(!
account
.
value
.
password
.
equals
(
password
)
&&
!(
password
.
getL
ength
()
>
1000
)))
{
result
.
accept
(
session
);
}
});
...
...
@@ -100,7 +97,8 @@ public class InChat {
* Register a new user.
*/
public
Maybe
<
Stored
<
Session
>>
register
(
final
String
username
,
final
String
password
)
{
final
String
password1
)
{
Password
password
=
new
Password
(
password1
);
return
atomic
(
result
->
{
final
Stored
<
User
>
user
=
userStore
.
save
(
User
.
create
(
username
));
...
...
@@ -149,18 +147,12 @@ public class InChat {
UUID
channelID
)
{
return
atomic
(
result
->
{
Stored
<
Channel
>
channel
=
channelStore
.
get
(
channelID
);
Util
.
updateSingle
(
account
,
accountStore
,
a
->
a
.
value
.
joinChannel
(
channel
.
value
.
name
,
channel
));
Stored
<
Channel
.
Event
>
joinEvent
=
channelStore
.
eventStore
.
save
(
Channel
.
Event
.
createJoinEvent
(
channelID
,
Instant
.
now
(),
account
.
value
.
user
.
value
.
name
));
result
.
accept
(
Util
.
updateSingle
(
channel
,
channelStore
,
c
->
c
.
value
.
postEvent
(
joinEvent
)));
Util
.
updateSingle
(
account
,
accountStore
,
a
->
a
.
value
.
joinChannel
(
channel
.
value
.
name
,
channel
));
Stored
<
Channel
.
Event
>
joinEvent
=
channelStore
.
eventStore
.
save
(
Channel
.
Event
.
createJoinEvent
(
channelID
,
Instant
.
now
(),
account
.
value
.
user
.
value
.
name
.
getUserName
()));
result
.
accept
(
Util
.
updateSingle
(
channel
,
channelStore
,
c
->
c
.
value
.
postEvent
(
joinEvent
)));
});
}
...
...
@@ -174,7 +166,7 @@ public class InChat {
Stored
<
Channel
.
Event
>
event
=
channelStore
.
eventStore
.
save
(
Channel
.
Event
.
createMessageEvent
(
channel
.
identity
,
Instant
.
now
(),
account
.
value
.
user
.
value
.
name
,
message
));
account
.
value
.
user
.
value
.
name
.
getUserName
()
,
message
));
result
.
accept
(
Util
.
updateSingle
(
channel
,
channelStore
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment