This should fix NPE due to WebCalendar chain being empty

With Mono.zip, it will skip the zip if one of the values is an empty Mono. So this should fix that by adding a default value in the event the guild does not have a calendar while building the WebGUild object
This commit is contained in:
NovaFox161
2020-08-12 04:10:34 -05:00
parent 0387d8f43f
commit 37358be00c
2 changed files with 6 additions and 1 deletions

View File

@@ -14,6 +14,10 @@ import reactor.core.publisher.Mono;
*/
public class WebCalendar {
public static WebCalendar empty() {
return new WebCalendar("primary", "primary", "N/a", "N/a", "N/a", "N/a", false);
}
//TODO: Make a reactive version of this method...
public static Mono<WebCalendar> fromCalendar(final CalendarData cd, final GuildSettings gs) {
if ("primary".equalsIgnoreCase(cd.getCalendarAddress())) {

View File

@@ -68,7 +68,8 @@ public class WebGuild {
final Mono<WebCalendar> calendar = settings.flatMap(s ->
DatabaseManager.getMainCalendar(id)
.flatMap(d -> WebCalendar.fromCalendar(d, s))
);
)
.defaultIfEmpty(WebCalendar.empty());
return Mono.zip(botNick, settings, roles, webChannels, announcements, calendar)
.map(TupleUtils.function((bn, s, r, wc, a, c) -> {