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
Vetle.Hjelmtvedt
inf226-2021-inchat
Commits
46eb1063
Commit
46eb1063
authored
Nov 13, 2021
by
vehjelmtvedt
Browse files
updated channel list on setRole
parent
35e5fef5
Changes
2
Hide whitespace changes
Inline
Side-by-side
.idea/misc.xml
View file @
46eb1063
...
...
@@ -11,5 +11,5 @@
<component
name=
"PDMPlugin"
>
<option
name=
"skipTestSources"
value=
"false"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1
5
"
default=
"
tru
e"
project-jdk-name=
"15"
project-jdk-type=
"JavaSDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1
4
"
default=
"
fals
e"
project-jdk-name=
"15"
project-jdk-type=
"JavaSDK"
/>
</project>
\ No newline at end of file
src/main/java/inf226/inchat/InChat.java
View file @
46eb1063
...
...
@@ -226,16 +226,30 @@ public class InChat {
throw
new
IllegalAccessException
(
"Non-owner tried to change a role"
);
}
Stored
<
Account
>
targetAccount
=
accountStore
.
lookup
(
new
UserName
(
targetUserName
).
toString
());
List
<
Triple
<
String
,
Stored
<
Channel
>,
Role
>>
newChannels
=
Util
.
replaceTriple
(
targetAccount
.
value
.
channels
,
channel
,
targetRole
);
if
(
newChannels
.
equals
(
account
.
value
.
channels
))
{
newChannels
.
add
(
new
Triple
<>(
channel
.
value
.
name
,
channel
,
targetRole
));
// Update channel list of the account
List
<
Triple
<
String
,
Stored
<
Channel
>,
Role
>>
updatedChannels
=
targetAccount
.
value
.
channels
.
map
(
chan
->
{
// If matching channel, update the role
if
(
chan
.
second
.
identity
.
equals
(
channel
.
identity
))
{
return
new
Triple
<>(
chan
.
first
,
chan
.
second
,
targetRole
);
// Else, return the same channel with same role
}
else
{
return
chan
;
}
});
if
(
updatedChannels
.
equals
(
account
.
value
.
channels
))
{
updatedChannels
.
add
(
new
Triple
<>(
channel
.
value
.
name
,
channel
,
targetRole
));
}
accountStore
.
update
(
targetAccount
,
new
Account
(
account
.
value
.
user
,
new
Channels
,
account
.
value
.
hashedPassword
));
accountStore
.
update
(
targetAccount
,
new
Account
(
account
.
value
.
user
,
updated
Channels
,
account
.
value
.
hashedPassword
));
result
.
accept
(
channel
);
});
}
}
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