private async Task <bool> DiscoAsync(string discoTarget, CheckDiscoResponseAsync action, DiscoType discoType) { MessageResponseHelperResult <IQMessage> result = await CONNECTION.GENERAL_COMMAND_HELPER.discoAsync(discoTarget, discoType); if (result.STATE != MessageResponseHelperResultState.SUCCESS) { Logger.Error($"Failed to perform server DISCO#{discoType} for '{CONNECTION.account.getBareJid()}' - {result.STATE}"); return(false); } if (result.RESULT is IQErrorMessage errorMessage) { Logger.Error($"Failed to perform server DISCO#{discoType} for '{CONNECTION.account.getBareJid()}' - {errorMessage.ERROR_OBJ}"); return(false); } // Success: if (result.RESULT is DiscoResponseMessage disco) { await OnDiscoResponseMessage(disco, action, discoTarget); return(true); } Logger.Error($"Failed to perform server DISCO#{discoType} for '{CONNECTION.account.getBareJid()}' - invalid response."); return(false); }
private async Task OnDiscoResponseMessage(DiscoResponseMessage disco, CheckDiscoResponseAsync action, string discoTarget) { // Print a list of all supported features: if (Logger.logLevel >= LogLevel.DEBUG) { StringBuilder sb = new StringBuilder("Disco#"); sb.Append(disco.DISCO_TYPE); sb.Append(" for '"); sb.Append(CONNECTION.account.getBareJid()); if (disco.DISCO_TYPE == DiscoType.INFO) { sb.Append("' reported the following features:\n"); foreach (string s in disco.FEATURES.Select(x => x.VAR)) { sb.Append(s); sb.Append("\n"); } } else { sb.Append("' reported the following items:\n"); foreach (DiscoItem i in disco.ITEMS) { sb.Append(i.JID); if (!string.IsNullOrEmpty(i.NODE)) { sb.Append(" -> "); sb.Append(i.NODE); } if (!string.IsNullOrEmpty(i.NAME)) { sb.Append($" ({i.NAME})"); } sb.Append("\n"); } } Logger.Debug(sb.ToString()); } await action(disco, discoTarget); }