Пример #1
0
        private async Task DisablePushAsync()
        {
            PushAccountModel push = CLIENT.dbAccount.push;

            if (string.IsNullOrEmpty(push.bareJid))
            {
                Logger.Info("No need to disable push. Has never been activated on this device (push bare JID is null).");
                return;
            }

            MessageResponseHelperResult <IQMessage> result = await CLIENT.xmppClient.GENERAL_COMMAND_HELPER.disablePushNotificationsAsync(push.bareJid);

            if (result.STATE == MessageResponseHelperResultState.SUCCESS)
            {
                if (result.RESULT is IQErrorMessage errorMessage)
                {
                    Logger.Error($"Failed to disable push notifications for '{CLIENT.dbAccount.bareJid}' - " + errorMessage.ERROR_OBJ.ToString());
                }
                else if (result.RESULT.TYPE != IQMessage.RESULT)
                {
                    Logger.Error($"Failed to disable push notifications for '{CLIENT.dbAccount.bareJid}' - server responded with: " + result.RESULT.TYPE);
                }
                else
                {
                    push.state = PushState.DISABLED;
                    push.Update();
                    Logger.Info($"Successfully disabled push notifications for: '{CLIENT.dbAccount.bareJid}'");
                }
            }
            else
            {
                Logger.Error($"Failed to disable push notifications for '{CLIENT.dbAccount.bareJid}' - " + result.STATE);
            }
        }
Пример #2
0
        private async Task EnablePushAsync()
        {
            PushAccountModel push = CLIENT.dbAccount.push;

            if (string.IsNullOrEmpty(push.bareJid) || string.IsNullOrEmpty(push.node))
            {
                Logger.Info($"Skipping push initialization for '{CLIENT.dbAccount.bareJid}' - server JID or node is empty.");
                return;
            }

            MessageResponseHelperResult <IQMessage> result = await CLIENT.xmppClient.GENERAL_COMMAND_HELPER.enablePushNotificationsAsync(push.bareJid, push.node, push.secret);

            if (result.STATE == MessageResponseHelperResultState.SUCCESS)
            {
                if (result.RESULT is IQErrorMessage errorMessage)
                {
                    Logger.Error($"Failed to enable push notifications for '{CLIENT.dbAccount.bareJid}' - " + errorMessage.ERROR_OBJ.ToString());
                }
                else if (result.RESULT.TYPE != IQMessage.RESULT)
                {
                    Logger.Error($"Failed to enable push notifications for '{CLIENT.dbAccount.bareJid}' - server responded with: " + result.RESULT.TYPE);
                }
                else
                {
                    push.state = PushState.ENABLED;
                    push.Update();
                    Logger.Info($"Successfully enabled push notifications for: '{CLIENT.dbAccount.bareJid}'");
                }
            }
            else
            {
                Logger.Error($"Failed to enable push notifications for '{CLIENT.dbAccount.bareJid}' - " + result.STATE);
            }
        }
Пример #3
0
        private async Task UpdateClientPushAsync()
        {
            PushAccountModel push = CLIENT.dbAccount.push;

            // Check if push is supported by the server:
            if (push.state != PushState.DISABLED && push.state != PushState.DISABLING && !CLIENT.xmppClient.connection.DISCO_HELPER.HasFeature(Consts.XML_XEP_0357_NAMESPACE, CLIENT.dbAccount.bareJid))
            {
                if (push.state != PushState.NOT_SUPPORTED)
                {
                    push.state = PushState.NOT_SUPPORTED;
                    push.Update();
                }
                Logger.Info($"Failed to enable push for account '{CLIENT.dbAccount.bareJid}' - not supported by the server.");
                return;
            }

            if (push.state == PushState.NOT_SUPPORTED)
            {
                push.state = PushState.ENABLING;
                push.Update();
            }

            switch (push.state)
            {
            case PushState.DISABLING:
                await DisablePushAsync();

                break;

            case PushState.ENABLING:
                await EnablePushAsync();

                break;

            case PushState.DISABLED:
                Logger.Info($"Push for account '{CLIENT.dbAccount.bareJid}' already disabled.");
                break;

            case PushState.ENABLED:
                Logger.Info($"Push for account '{CLIENT.dbAccount.bareJid}' already enabled.");
                break;

            // Should not happen:
            default:
                throw new InvalidOperationException($"Should not happen! {nameof(PushState)} == {push.state}");
            }
        }