private async Task OnMucErrorMessageAsync(XMPPClient client, MUCErrorMessage errorMessage) { string room = Utils.getBareJidFromFullJid(errorMessage.getFrom()); if (room is null) { return; } ChatModel chat; using (SemaLock semaLock = DataCache.INSTANCE.NewChatSemaLock()) { chat = DataCache.INSTANCE.GetChat(client.getXMPPAccount().getBareJid(), room, semaLock); } if (chat is null || chat.muc is null) { return; } Logger.Error("Received an error message for MUC: " + chat.bareJid + "\n" + errorMessage.ERROR_MESSAGE); StopMucJoinHelper(chat); if (chat.muc.state != MucState.DISCONNECTED) { await SendMucLeaveMessageAsync(client, chat.muc); } using (SemaLock semaLock = chat.muc.NewSemaLock()) { switch (errorMessage.ERROR_CODE) { // No access - user got baned: case 403: chat.muc.state = MucState.BANED; AddChatInfoMessage(chat, room, "Unable to join room!\nYou are baned from this room."); return; default: chat.muc.state = MucState.ERROR; break; } chat.muc.Update(); } // Add an error chat message: ChatMessageModel msg = new ChatMessageModel() { stableId = errorMessage.ID ?? AbstractMessage.getRandomId(), chatId = chat.id, date = DateTime.Now, fromBareJid = Utils.getBareJidFromFullJid(errorMessage.getFrom()), isImage = false, message = "Code: " + errorMessage.ERROR_CODE + "\nType: " + errorMessage.ERROR_TYPE + "\nMessage:\n" + errorMessage.ERROR_MESSAGE, state = MessageState.UNREAD, type = MessageMessage.TYPE_ERROR }; DataCache.INSTANCE.AddChatMessage(msg, chat); }
private async Task onMUCErrorMessageAsync(XMPPClient client, MUCErrorMessage errorMessage) { string room = Utils.getBareJidFromFullJid(errorMessage.getFrom()); if (room != null) { string chatId = ChatTable.generateId(room, client.getXMPPAccount().getBareJid()); ChatTable muc = ChatDBManager.INSTANCE.getChat(chatId); if (muc != null) { MUCChatInfoTable info = MUCDBManager.INSTANCE.getMUCInfo(chatId); if (info != null) { Logger.Error("Received an error message for MUC: " + muc.chatJabberId + "\n" + errorMessage.ERROR_MESSAGE); stopMUCJoinHelper(muc); if (info.state != MUCState.DISCONNECTED) { await sendMUCLeaveMessageAsync(client, muc, info); } switch (errorMessage.ERROR_CODE) { // No access - user got baned: case 403: MUCDBManager.INSTANCE.setMUCState(info.chatId, MUCState.BANED, true); addChatInfoMessage(info.chatId, room, "Unable to join room!\nYou are baned from this room."); return; default: MUCDBManager.INSTANCE.setMUCState(info.chatId, MUCState.ERROR, true); break; } // Add an error chat message: ChatMessageTable msg = new ChatMessageTable() { id = ChatMessageTable.generateErrorMessageId(errorMessage.ID ?? AbstractMessage.getRandomId(), muc.id), chatId = muc.id, date = DateTime.Now, fromUser = errorMessage.getFrom(), isImage = false, message = "Code: " + errorMessage.ERROR_CODE + "\nType: " + errorMessage.ERROR_TYPE + "\nMessage:\n" + errorMessage.ERROR_MESSAGE, state = MessageState.UNREAD, type = MessageMessage.TYPE_ERROR }; ChatDBManager.INSTANCE.setChatMessage(msg, true, false); } } } }