Esempio n. 1
0
        public void Handle(UpdateNewMessage update)
        {
            if (update.DisableNotification || !_settings.Notifications.InAppPreview)
            {
                return;
            }

            var difference = DateTime.Now.ToTimestamp() - update.Message.Date;

            if (difference > 180)
            {
                return;
            }

            // Adding some delay to be 110% the message hasn't been read already
            ThreadPoolTimer.CreateTimer(timer =>
            {
                var chat = _protoService.GetChat(update.Message.ChatId);
                if (chat == null || chat.LastReadInboxMessageId >= update.Message.Id)
                {
                    return;
                }

                var caption = GetCaption(chat);
                var content = GetContent(chat, update.Message);
                var sound   = "";
                var launch  = GetLaunch(chat);
                var tag     = GetTag(update.Message);
                var group   = GetGroup(chat);
                var picture = GetPhoto(chat);
                var date    = BindConvert.Current.DateTime(update.Message.Date).ToString("o");
                var loc_key = chat.Type is ChatTypeSupergroup super && super.IsChannel ? "CHANNEL" : string.Empty;

                Execute.BeginOnUIThread(() =>
                {
                    var service = WindowWrapper.Current().NavigationServices.GetByFrameId("Main");
                    if (service == null)
                    {
                        return;
                    }

                    if (WindowContext.GetForCurrentView().ActivationState != Windows.UI.Core.CoreWindowActivationState.Deactivated && service.CurrentPageType == typeof(ChatPage) && (long)service.CurrentPageParam == chat.Id)
                    {
                        return;
                    }

                    NotificationTask.UpdateToast(caption, content, sound, launch, tag, group, picture, date, loc_key);
                    NotificationTask.UpdatePrimaryTile(caption, content, picture);
                });
            }, TimeSpan.FromSeconds(3));
        }
Esempio n. 2
0
        public void Handle(UpdateNewMessage update)
        {
            var chat = _chat;

            if (chat == null || chat.Id != update.Message.ChatId)
            {
                return;
            }

            if (update.Message.Content is MessageLocation location && location.LivePeriod > 0)
            {
                Items.Add(update.Message);
            }
        }
Esempio n. 3
0
        public void Handle(UpdateNewMessage update)
        {
            if (update.DisableNotification || !_settings.Notifications.InAppPreview)
            {
                return;
            }

            var difference = DateTime.Now.ToTimestamp() - update.Message.Date;

            if (difference > 180)
            {
                return;
            }

            // Adding some delay to be 110% the message hasn't been read already
            ThreadPoolTimer.CreateTimer(timer =>
            {
                var chat = _protoService.GetChat(update.Message.ChatId);
                if (chat == null || chat.LastReadInboxMessageId >= update.Message.Id)
                {
                    return;
                }

                var caption = GetCaption(chat);
                var content = GetContent(chat, update.Message);
                var sound   = "";
                var launch  = GetLaunch(chat);
                var tag     = GetTag(update.Message);
                var group   = GetGroup(chat);
                var picture = GetPhoto(chat);
                var date    = BindConvert.Current.DateTime(update.Message.Date).ToString("o");
                var loc_key = chat.Type is ChatTypeSupergroup super && super.IsChannel ? "CHANNEL" : string.Empty;

                var user = _protoService.GetUser(_protoService.GetMyId());

                Update(chat, () =>
                {
                    NotificationTask.UpdateToast(caption, content, user?.GetFullName() ?? string.Empty, user?.Id.ToString() ?? string.Empty, sound, launch, tag, group, picture, date, loc_key);
                    NotificationTask.UpdatePrimaryTile($"{_protoService.SessionId}", caption, content, picture);
                });
            }, TimeSpan.FromSeconds(3));
        }