예제 #1
0
        /// <summary>
        /// Sends the given message to the server or stores it until there is a connection to the server.
        /// </summary>
        /// <param name="msg">The message to send.</param>
        /// <param name="cacheIfNotConnected">Cache the message if the connection state does not equals 'CONNECTED', to ensure the message doesn't get lost.</param>
        /// <param name="sendIfNotConnected">Sends the message if the underlaying TCP connection is connected to the server and ignores the connection state of the XMPPConnection.</param>
        public async Task sendAsync(AbstractMessage msg, bool cacheIfNotConnected, bool sendIfNotConnected)
        {
            if (state == ConnectionState.CONNECTING)
            {
                resetConnectionTimer();
            }

            if (state != ConnectionState.CONNECTED && !sendIfNotConnected)
            {
                if (Logger.logLevel >= LogLevel.DEBUG)
                {
                    Logger.Warn("Did not send message, due to connection state is " + state + "\n" + msg.toXmlString());
                }
                else
                {
                    Logger.Warn("Did not send message, due to connection state is " + state);
                }

                if ((cacheIfNotConnected || msg.shouldSaveUntilSend()))
                {
                    MessageCacheDBManager.INSTANCE.addMessage(account.getIdAndDomain(), msg);
                }
                if (!sendIfNotConnected)
                {
                    return;
                }
            }

            if (msg is IQMessage && msg.ID != null)
            {
                messageIdCache.addTimed(msg.ID);
            }
            try
            {
                if (await TCP_CONNECTION.sendAsync(msg.toXmlString()))
                {
                    // Only trigger onMessageSend(...) for chat messages:
                    if (msg is MessageMessage m)
                    {
                        onMessageSend(msg.ID, m.chatMessageId, false);
                        return;
                    }
                }
                else
                {
                    Logger.Error("Error during sending message for account: " + account.getIdAndDomain());
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error during sending message for account: " + account.getIdAndDomain(), e);
            }

            if ((cacheIfNotConnected || msg.shouldSaveUntilSend()))
            {
                MessageCacheDBManager.INSTANCE.addMessage(account.getIdAndDomain(), msg);
            }
        }
예제 #2
0
        public async Task enterMUCAsync(XMPPClient client, ChatTable muc, MUCChatInfoTable info)
        {
            MUCJoinHelper helper = new MUCJoinHelper(client, muc, info);

            TIMED_LIST.addTimed(helper);

            await helper.enterRoomAsync();
        }
예제 #3
0
        /// <summary>
        /// Sends the given message to the server or stores it until there is a connection to the server.
        /// </summary>
        /// <param name="msg">The message to send.</param>
        /// <param name="sendIfNotConnected">Sends the message if the underlaying TCP connection is connected to the server and ignores the connection state of the XMPPConnection.</param>
        /// <returns>True if the message got send and didn't got cached.</returns>
        public async Task <bool> sendAsync(AbstractMessage msg, bool sendIfNotConnected)
        {
            if (state == ConnectionState.CONNECTING)
            {
                resetConnectionTimer();
            }

            if (state != ConnectionState.CONNECTED && !sendIfNotConnected)
            {
                if (Logger.logLevel >= LogLevel.DEBUG)
                {
                    Logger.Warn("[XMPPConnection2]: Did not send message, due to connection state is " + state + "\n" + msg.toXmlString());
                }
                else
                {
                    Logger.Warn("[XMPPConnection2]: Did not send message, due to connection state is " + state);
                }

                if (!sendIfNotConnected)
                {
                    return(false);
                }
            }

            if (msg is IQMessage && msg.ID != null)
            {
                messageIdCache.addTimed(msg.ID);
            }
            try
            {
                if (await TCP_CONNECTION.sendAsync(msg.toXmlString()))
                {
                    // Only trigger onMessageSend(...) for chat messages:
                    if (msg is MessageMessage m)
                    {
                        onMessageSend(msg.ID, m.chatMessageId, false);
                    }
                    return(true);
                }
                else
                {
                    Logger.Error("[XMPPConnection2]: Error during sending message for account: " + account.getBareJid());
                }
            }
            catch (Exception e)
            {
                Logger.Error("[XMPPConnection2]: Error during sending message for account: " + account.getBareJid(), e);
            }
            return(false);
        }
예제 #4
0
 private async Task addItemsAsync(List <DiscoItem> items, string from, XMPPClient client, bool requestInfo)
 {
     if (items != null)
     {
         dB.Execute("DELETE FROM " + DBTableConsts.DISCO_ITEM_TABLE + " WHERE fromServer = ?;", from);
         foreach (DiscoItem i in items)
         {
             if (from != null && i.JID != null)
             {
                 update(new DiscoItemTable()
                 {
                     id         = DiscoItemTable.generateId(from, i.JID),
                     fromServer = from,
                     jid        = i.JID,
                     name       = i.NAME
                 });
                 if (requestInfo)
                 {
                     messageIdCache.addTimed(await client.createDiscoAsync(i.JID, DiscoType.INFO));
                 }
             }
         }
     }
 }