From d87dedc48d7a9995679e5ed6e71f845a3380aaf1 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Fri, 12 Mar 2021 02:53:35 +0400 Subject: [PATCH] Temp notifications --- src/lib/appManagers/appMessagesManager.ts | 160 ++---------------- .../appManagers/appNotificationsManager.ts | 5 +- 2 files changed, 14 insertions(+), 151 deletions(-) diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 6e2e913d..a0553a72 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -2476,7 +2476,7 @@ export class AppMessagesManager { } } - public getRichReplyText(message: any, text: string = message.message, usingMids?: number[]) { + public getRichReplyText(message: any, text: string = message.message, usingMids?: number[], plain = false) { let messageText = ''; if(message.media) { @@ -2511,13 +2511,13 @@ export class AppMessagesManager { messageText += 'Photo' + (message.message ? ', ' : '') + ''; break; case 'messageMediaDice': - messageText += RichTextProcessor.wrapEmojiText(media.emoticon); + messageText += plain ? media.emoticon : RichTextProcessor.wrapEmojiText(media.emoticon); break; case 'messageMediaGeo': messageText += 'Geolocation'; break; case 'messageMediaPoll': - messageText += '' + media.poll.rReply + ''; + messageText += '' + (plain ? '📊' + ' ' + media.poll.question || 'poll' : media.poll.rReply) + ''; break; case 'messageMediaContact': messageText += 'Contact'; @@ -2562,7 +2562,7 @@ export class AppMessagesManager { const entities = RichTextProcessor.parseEntities(text.replace(/\n/g, ' ')); - messageWrapped = RichTextProcessor.wrapRichText(text, { + messageWrapped = plain ? text : RichTextProcessor.wrapRichText(text, { noLinebreaks: true, entities, noLinks: true, @@ -2570,6 +2570,10 @@ export class AppMessagesManager { }); } + if(plain) { + messageText = messageText.replace(//g, '').replace(/<\/i>/g, ''); + } + return messageText + messageWrapped; } @@ -4626,152 +4630,10 @@ export class AppMessagesManager { const localSettings = appNotificationsManager.getLocalSettings(); if(options.peerTypeNotifySettings.show_previews) { - if(message._ === 'message') { - if(message.fwd_from && options.fwdCount) { - notificationMessage = 'Forwarded ' + options.fwdCount + ' messages';//fwdMessagesPluralize(options.fwd_count); - } else if(message.message) { - if(localSettings.nopreview) { - notificationMessage = _('conversation_message_sent'); - } else { - notificationMessage = RichTextProcessor.wrapPlainText(message.message); - } - } else if(message.media) { - var captionEmoji: string; - switch (message.media._) { - case 'messageMediaPhoto': - notificationMessage = _('conversation_media_photo_raw'); - captionEmoji = '🖼'; - break; - case 'messageMediaDocument': - if(message.media.document._ === 'documentEmpty') break; - switch(message.media.document.type) { - case 'gif': - notificationMessage = _('conversation_media_gif_raw'); - captionEmoji = '🎬'; - break; - case 'sticker': - notificationMessage = _('conversation_media_sticker'); - var stickerEmoji = message.media.document.stickerEmojiRaw; - if(stickerEmoji !== undefined) { - notificationMessage = RichTextProcessor.wrapPlainText(stickerEmoji) + ' ' + notificationMessage; - } - break; - case 'video': - notificationMessage = _('conversation_media_video_raw'); - captionEmoji = '📹'; - break; - case 'round': - notificationMessage = _('conversation_media_round_raw'); - captionEmoji = '📹'; - break; - case 'voice': - case 'audio': - notificationMessage = _('conversation_media_audio_raw'); - break; - default: - if(message.media.document.file_name) { - notificationMessage = RichTextProcessor.wrapPlainText('📎 ' + message.media.document.file_name); - } else { - notificationMessage = _('conversation_media_document_raw'); - captionEmoji = '📎'; - } - break; - } - break; - - case 'messageMediaGeo': - case 'messageMediaVenue': - notificationMessage = _('conversation_media_location_raw'); - captionEmoji = '📍'; - break; - case 'messageMediaContact': - notificationMessage = _('conversation_media_contact_raw'); - break; - case 'messageMediaGame': - notificationMessage = RichTextProcessor.wrapPlainText('🎮 ' + message.media.game.title); - break; - case 'messageMediaUnsupported': - notificationMessage = _('conversation_media_unsupported_raw'); - break; - default: - notificationMessage = _('conversation_media_attachment_raw'); - break; - } - - if(captionEmoji !== undefined && (message.media as any).caption) { - notificationMessage = RichTextProcessor.wrapPlainText(captionEmoji + ' ' + (message.media as any).caption); - } - } + if(message._ === 'message' && message.fwd_from && options.fwdCount) { + notificationMessage = 'Forwarded ' + options.fwdCount + ' messages';//fwdMessagesPluralize(options.fwd_count); } else { - switch(message.action._) { - case 'messageActionChatCreate': - notificationMessage = _('conversation_group_created_raw') - break - case 'messageActionChatEditTitle': - notificationMessage = _('conversation_group_renamed_raw') - break - case 'messageActionChatEditPhoto': - notificationMessage = _('conversation_group_photo_updated_raw') - break - case 'messageActionChatDeletePhoto': - notificationMessage = _('conversation_group_photo_removed_raw') - break - case 'messageActionChatAddUser': - // @ts-ignore - case 'messageActionChatAddUsers': - notificationMessage = _('conversation_invited_user_message_raw') - break - /* case 'messageActionChatReturn': - notificationMessage = _('conversation_returned_to_group_raw') - break - case 'messageActionChatJoined': - notificationMessage = _('conversation_joined_group_raw') - break */ - case 'messageActionChatDeleteUser': - notificationMessage = _('conversation_kicked_user_message_raw') - break - /* case 'messageActionChatLeave': - notificationMessage = _('conversation_left_group_raw') - break */ - case 'messageActionChatJoinedByLink': - notificationMessage = _('conversation_joined_by_link_raw') - break - case 'messageActionChannelCreate': - notificationMessage = _('conversation_created_channel_raw') - break - /* case 'messageActionChannelEditTitle': - notificationMessage = _('conversation_changed_channel_name_raw') - break - case 'messageActionChannelEditPhoto': - notificationMessage = _('conversation_changed_channel_photo_raw') - break - case 'messageActionChannelDeletePhoto': - notificationMessage = _('conversation_removed_channel_photo_raw') - break */ - case 'messageActionPinMessage': - notificationMessage = _('conversation_pinned_message_raw') - break - /* case 'messageActionGameScore': - notificationMessage = gameScorePluralize(message.action.score) - break */ - - case 'messageActionPhoneCall': - switch((message.action as any).type) { - case 'out_missed': - notificationMessage = _('message_service_phonecall_canceled_raw') - break - case 'in_missed': - notificationMessage = _('message_service_phonecall_missed_raw') - break - case 'out_ok': - notificationMessage = _('message_service_phonecall_outgoing_raw') - break - case 'in_ok': - notificationMessage = _('message_service_phonecall_incoming_raw') - break - } - break - } + notificationMessage = this.getRichReplyText(message, undefined, undefined, true); } } else { notificationMessage = 'New notification'; diff --git a/src/lib/appManagers/appNotificationsManager.ts b/src/lib/appManagers/appNotificationsManager.ts index 5ff61939..40ead89c 100644 --- a/src/lib/appManagers/appNotificationsManager.ts +++ b/src/lib/appManagers/appNotificationsManager.ts @@ -538,7 +538,7 @@ export class AppNotificationsManager { const notification = this.notificationsShown[i]; if(notification && notification.tag === data.tag) { - notification.hidden = true + notification.hidden = true; } } } @@ -549,10 +549,11 @@ export class AppNotificationsManager { tag: data.tag || '', silent: data.silent || false }); + console.log('notify constructed notification'); } catch(e) { this.notificationsUiSupport = false; //WebPushApiManager.setLocalNotificationsDisabled(); - return + return; } } /* else if('mozNotification' in navigator) { notification = navigator.mozNotification.createNotification(data.title, data.message || '', data.image || '')