コード例 #1
0
        private bool onChangeNickMessage(PresenceMessage msg)
        {
            if (msg is MUCMemberPresenceMessage)
            {
                // Success:
                MUCMemberPresenceMessage mPMessage = msg as MUCMemberPresenceMessage;
                if (mPMessage.STATUS_CODES.Contains(MUCPresenceStatusCode.PRESENCE_SELFE_REFERENCE) && (mPMessage.STATUS_CODES.Contains(MUCPresenceStatusCode.MEMBER_NICK_CHANGED) || mPMessage.STATUS_CODES.Contains(MUCPresenceStatusCode.ROOM_NICK_CHANGED)))
                {
                    Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        MUCInfo.nickname      = mPMessage.NICKNAME;
                        MUCChatInfoTable info = MUCInfo;
                        Task.Run(() => MUCDBManager.INSTANCE.setMUCChatInfo(info, false, false));

                        nickname_stbx.Text = mPMessage.NICKNAME;
                        nickname_stbx.onSavingDone();
                        notificationBanner_ian.Show("Successfully changed nickname to: " + mPMessage.NICKNAME, 5000);
                    }).AsTask();
                    return(true);
                }
            }
            // Error:
            else if (msg is MUCErrorMessage && Equals(msg.ID, changeNickHelper.sendId))
            {
                MUCErrorMessage errorMessage = msg as MUCErrorMessage;
                Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    nickname_stbx.Text = MUCInfo.nickname;
                    nickname_stbx.onSavingDone();
                    notificationBanner_ian.Show("Changing nickname failed:\nCode: " + errorMessage.ERROR_CODE + "\nType: " + errorMessage.ERROR_TYPE + "\nMessage:\n" + errorMessage.ERROR_MESSAGE);
                }).AsTask();
            }
            return(false);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
                    }
                }
            }
        }