From fc86308b21663f334b5c2a6b5f13a6a293b7ac3a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 4 Aug 2020 11:14:36 +0200 Subject: [PATCH 1/3] MOBILE-3509 notifications: Display forum digest notification html --- src/addon/notifications/pages/list/list.html | 2 +- src/addon/notifications/pages/list/list.scss | 64 +++++++++++++++++-- src/addon/notifications/pages/list/list.ts | 17 ++++- .../notifications/providers/notifications.ts | 1 + src/assets/lang/en.json | 1 + 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/addon/notifications/pages/list/list.html b/src/addon/notifications/pages/list/list.html index 951c63659..1bb618eaa 100644 --- a/src/addon/notifications/pages/list/list.html +++ b/src/addon/notifications/pages/list/list.html @@ -30,7 +30,7 @@

{{ notification.userfromfullname }}

-

+

diff --git a/src/addon/notifications/pages/list/list.scss b/src/addon/notifications/pages/list/list.scss index 122b8e4dc..9a476511c 100644 --- a/src/addon/notifications/pages/list/list.scss +++ b/src/addon/notifications/pages/list/list.scss @@ -1,5 +1,61 @@ -page-addon-notifications-list .core-notification-icon { - width: 34px; - height: 34px; - margin: 10px !important; +page-addon-notifications-list { + .core-notification-icon { + width: 34px; + height: 34px; + margin: 10px !important; + } + + .item core-format-text { + .forumpost { + border: 1px solid #dee2e6; + display: block; + padding: 6px; + margin: 0 0 1em 0; + + td { + padding: 3px; + } + + .header { + padding: 5px; + border-bottom: 1px solid #e3e3e3; + margin-bottom: 3px; + } + + .picture { + width: auto; + + img { + margin: 3px; + + &.userpicture { + margin-left: 3px; + margin-right: 10px; + } + } + } + + .subject { + font-weight: 700; + } + } + + a { + text-decoration: none; + } + + .userpicture { + border-radius: 50%; + } + + .mdl-right { + text-align: right; + } + + hr { + margin-top: 1.5rem; + margin-bottom: 1.5rem; + background-color: #e3e3e3; + } + } } \ No newline at end of file diff --git a/src/addon/notifications/pages/list/list.ts b/src/addon/notifications/pages/list/list.ts index 2046b00bc..49fbdb209 100644 --- a/src/addon/notifications/pages/list/list.ts +++ b/src/addon/notifications/pages/list/list.ts @@ -204,8 +204,21 @@ export class AddonNotificationsListPage { * @param notification The notification object. */ protected formatText(notification: AddonNotificationsAnyNotification): void { - const text = notification.mobiletext.replace(/-{4,}/ig, ''); - notification.mobiletext = this.textUtils.replaceNewLines(text, '
'); + notification.displayfullhtml = this.shouldDisplayFullHtml(notification); + + notification.mobiletext = notification.displayfullhtml ? + notification.fullmessagehtml : + this.textUtils.replaceNewLines(notification.mobiletext.replace(/-{4,}/ig, ''), '
'); + } + + /** + * Check whether we should display full HTML of the notification. + * + * @param notification Notification. + * @return Whether to display full HTML. + */ + protected shouldDisplayFullHtml(notification: AddonNotificationsAnyNotification): boolean { + return notification.component == 'mod_forum' && notification.eventtype == 'digests'; } /** diff --git a/src/addon/notifications/providers/notifications.ts b/src/addon/notifications/providers/notifications.ts index 3a2234ada..8a96d1f68 100644 --- a/src/addon/notifications/providers/notifications.ts +++ b/src/addon/notifications/providers/notifications.ts @@ -616,4 +616,5 @@ export type AddonNotificationsNotificationCalculatedData = { courseid?: number; // Calculated in the app. Course the notification belongs to. profileimageurlfrom?: string; // Calculated in the app. Avatar of user that sent the notification. userfromfullname?: string; // Calculated in the app in some cases. User from full name. + displayfullhtml?: boolean; // Whether to display the full HTML of the notification. }; diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index ec064e2dd..93dcadfc1 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1914,6 +1914,7 @@ "core.openmodinbrowser": "Open {{$a}} in browser", "core.othergroups": "Other groups", "core.pagea": "Page {{$a}}", + "core.parentlanguage": "", "core.paymentinstant": "Use the button below to pay and be enrolled within minutes!", "core.percentagenumber": "{{$a}}%", "core.phone": "Phone", From 8b45f1c62429dd85d5983ab645f186fb0a4d1e9e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 4 Aug 2020 12:09:26 +0200 Subject: [PATCH 2/3] MOBILE-3509 forum: Support parent param in discussion links --- .../mod/forum/pages/discussion/discussion.ts | 69 ++++++++++++------- .../providers/discussion-link-handler.ts | 3 + 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index adf2ebbe2..7ef3aa4de 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -85,6 +85,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { protected forumId: number; protected postId: number; + protected parent: number; protected onlineObserver: any; protected syncObserver: any; protected syncManualObserver: any; @@ -120,6 +121,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { this.discussionId = this.discussion ? this.discussion.discussion : navParams.get('discussionId'); this.trackPosts = navParams.get('trackPosts'); this.postId = navParams.get('postId'); + this.parent = navParams.get('parent'); this.isOnline = this.appProvider.isOnline(); this.onlineObserver = network.onchange().subscribe(() => { @@ -136,41 +138,56 @@ export class AddonModForumDiscussionPage implements OnDestroy { /** * View loaded. */ - ionViewDidLoad(): void { - this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort').catch(() => { - this.userProvider.getUserPreference('forum_displaymode').catch(() => { - // Ignore errors. - }).then((value) => { - const sortValue = value && parseInt(value, 10); + async ionViewDidLoad(): Promise { + if (this.parent) { + this.sort = 'nested'; // Force nested order. + } else { + this.sort = await this.getUserSort(); + } - switch (sortValue) { + await this.fetchPosts(true, false, true); + + const scrollTo = this.postId || this.parent; + if (scrollTo) { + // Scroll to the post. + setTimeout(() => { + this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + scrollTo); + }); + } + } + + /** + * Get sort type configured by the current user. + * + * @return Promise resolved with the sort type. + */ + protected async getUserSort(): Promise { + try { + const value = await this.sitesProvider.getCurrentSite().getLocalSiteConfig('AddonModForumDiscussionSort'); + + return value; + } catch (error) { + try { + const value = await this.userProvider.getUserPreference('forum_displaymode'); + + switch (Number(value)) { case 1: - this.sort = 'flat-oldest'; - break; + return 'flat-oldest'; case -1: - this.sort = 'flat-newest'; - break; + return 'flat-newest'; case 3: - this.sort = 'nested'; - break; + return 'nested'; case 2: // Threaded not implemented. default: // Not set, use default sort. // @TODO add fallback to $CFG->forum_displaymode. } - }); - }).then((value) => { - this.sort = value; - }).finally(() => { - this.fetchPosts(true, false, true).then(() => { - if (this.postId) { - // Scroll to the post. - setTimeout(() => { - this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + this.postId); - }); - } - }); - }); + } catch (error) { + // Ignore errors. + } + } + + return 'flat-oldest'; } /** diff --git a/src/addon/mod/forum/providers/discussion-link-handler.ts b/src/addon/mod/forum/providers/discussion-link-handler.ts index 546e477f0..cb6866dd7 100644 --- a/src/addon/mod/forum/providers/discussion-link-handler.ts +++ b/src/addon/mod/forum/providers/discussion-link-handler.ts @@ -60,6 +60,9 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB if (data.postid || params.urlHash) { pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); } + if (params.parent) { + pageParams.parent = parseInt(params.parent); + } this.linkHelper.goInSite(navCtrl, 'AddonModForumDiscussionPage', pageParams, siteId); } From 4fe4284677bc476ed829e44980f72a2f3882beb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 7 Aug 2020 11:14:36 +0200 Subject: [PATCH 3/3] MOBILE-3509 notifications: Improve styles for digests --- src/addon/notifications/pages/list/list.scss | 39 ++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/addon/notifications/pages/list/list.scss b/src/addon/notifications/pages/list/list.scss index 9a476511c..15f586332 100644 --- a/src/addon/notifications/pages/list/list.scss +++ b/src/addon/notifications/pages/list/list.scss @@ -6,37 +6,28 @@ page-addon-notifications-list { } .item core-format-text { + .forumpost { - border: 1px solid #dee2e6; - display: block; - padding: 6px; + border: 1px solid $gray-light; + width: 100%; margin: 0 0 1em 0; td { - padding: 3px; + padding: $content-padding; } .header { - padding: 5px; - border-bottom: 1px solid #e3e3e3; - margin-bottom: 3px; + background-color: $gray-lighter; } .picture { width: auto; - - img { - margin: 3px; - - &.userpicture { - margin-left: 3px; - margin-right: 10px; - } - } + text-align: center; } .subject { font-weight: 700; + margin-bottom: 1rem; } } @@ -49,13 +40,23 @@ page-addon-notifications-list { } .mdl-right { - text-align: right; + @include text-align('end'); + a { + display: none; + } + font { + font-size: 0.9em; + } + } + + .commands { + display: none; } hr { margin-top: 1.5rem; margin-bottom: 1.5rem; - background-color: #e3e3e3; + background-color: $gray-light; } } -} \ No newline at end of file +}