Commit 46eb1063 authored by vehjelmtvedt's avatar vehjelmtvedt
Browse files

updated channel list on setRole

parent 35e5fef5
......@@ -11,5 +11,5 @@
<component name="PDMPlugin">
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="15" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
......@@ -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, newChannels, account.value.hashedPassword));
accountStore.update(targetAccount, new Account(account.value.user, updatedChannels, account.value.hashedPassword));
result.accept(channel);
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment