Example #1
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            BackgroundTaskDeferral deferral = args.TaskInstance.GetDeferral();

            switch (args.TaskInstance.Task.Name)
            {
            case BackgroundTaskHelper.TOAST_BACKGROUND_TASK_NAME:
                if (args.TaskInstance.TriggerDetails is ToastNotificationActionTriggerDetail details)
                {
                    InitLogger();

                    string   arguments = details.Argument;
                    ValueSet userInput = details.UserInput;

                    Logger.Debug("App activated in background through toast with: " + arguments);
                    AbstractToastActivation abstractToastActivation = ToastActivationArgumentParser.ParseArguments(arguments);

                    if (abstractToastActivation is null)
                    {
                        Logger.Warn("Unable to evaluate toast activation string - unknown format");
                    }
                    else if (abstractToastActivation is MarkChatAsReadToastActivation markChatAsRead)
                    {
                        ToastHelper.RemoveToastGroup(markChatAsRead.CHAT_ID.ToString());
                        DataCache.INSTANCE.MarkAllChatMessagesAsRead(markChatAsRead.CHAT_ID);
                    }
                    else if (abstractToastActivation is MarkMessageAsReadToastActivation markMessageAsRead)
                    {
                        DataCache.INSTANCE.MarkChatMessageAsRead(markMessageAsRead.CHAT_ID, markMessageAsRead.CHAT_MESSAGE_ID);
                    }
                    else if (abstractToastActivation is SendReplyToastActivation sendReply)
                    {
                        ChatModel chat;
                        using (SemaLock semaLock = DataCache.INSTANCE.NewChatSemaLock())
                        {
                            chat = DataCache.INSTANCE.GetChat(sendReply.CHAT_ID, semaLock);
                        }
                        if (chat is not null && userInput[ToastHelper.TEXT_BOX_ID] is string text)
                        {
                            string trimedText = text.Trim(UiUtils.TRIM_CHARS);
                            await SendChatMessageAsync(chat, trimedText);
                        }
                        DataCache.INSTANCE.MarkChatMessageAsRead(sendReply.CHAT_ID, sendReply.CHAT_MESSAGE_ID);
                    }

                    ToastHelper.UpdateBadgeNumber();
                }
                break;

            default:
                break;
            }

            deferral.Complete();
        }
Example #2
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            var deferral = args.TaskInstance.GetDeferral();

            switch (args.TaskInstance.Task.Name)
            {
            case BackgroundTaskHelper.TOAST_BACKGROUND_TASK_NAME:
                ToastNotificationActionTriggerDetail details = args.TaskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
                if (details != null)
                {
                    initLogLevel();

                    string arguments = details.Argument;
                    var    userInput = details.UserInput;

                    Logger.Debug("App activated in background through toast with: " + arguments);
                    AbstractToastActivation abstractToastActivation = ToastActivationArgumentParser.parseArguments(arguments);

                    if (abstractToastActivation is MarkChatAsReadToastActivation markChatAsRead)
                    {
                        ToastHelper.removeToastGroup(markChatAsRead.CHAT_ID);
                        ChatDBManager.INSTANCE.markAllMessagesAsRead(markChatAsRead.CHAT_ID);
                    }
                    else if (abstractToastActivation is MarkMessageAsReadToastActivation markMessageAsRead)
                    {
                        ChatDBManager.INSTANCE.markMessageAsRead(markMessageAsRead.CHAT_MESSAGE_ID);
                    }
                    else if (abstractToastActivation is SendReplyToastActivation sendReply)
                    {
                        ChatTable chat = ChatDBManager.INSTANCE.getChat(sendReply.CHAT_ID);
                        if (chat != null && userInput[ToastHelper.TEXT_BOX_ID] != null)
                        {
                            if (isRunning)
                            {
                            }
                            else
                            {
                            }
                        }
                    }
                }
                break;
            }

            deferral.Complete();
        }