Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor notifications #4883

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Lakoja
Copy link
Collaborator

@Lakoja Lakoja commented Jan 18, 2025

Also fixes #4858.
But apart from that there should be no functional change.

If this is ok I would also move the current push code to the NotificationService in this PR.

// "Post failed" dialog should display in this activity
draftsAlert.observeInContext(this@MainActivity, true)
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bug fix.

@@ -75,6 +75,7 @@ class TuskyApplication : Application(), Configuration.Provider {
NEW_INSTALL_SCHEMA_VERSION
)
if (oldVersion != SCHEMA_VERSION) {
// TODO SCHEMA_VERSION is outdated / not updated in code
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collateral find.

if (!NotificationHelper.areNotificationsEnabled(context, accountManager)) {
NotificationHelper.disablePullNotifications(context)
if (!notificationService.areNotificationsEnabled()) {
// TODO this is working very wrong
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would then be a next step.

Copy link
Collaborator

@connyduck connyduck Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give some more details what the problem is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly with the "thinking" behind it (or lack thereof). Earlier I had "worded very wrong" there.
It's "if notifications are disabled then disable them"?

@Lakoja Lakoja requested a review from connyduck January 18, 2025 15:56
Copy link
Collaborator

@connyduck connyduck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is a very good idea, thank you!

I have mostly Kotlin style complaints, and I think NotificationHelper can now be deleted?


when (notification.type) {
Notification.Type.FOLLOW, Notification.Type.FOLLOW_REQUEST, Notification.Type.SIGN_UP -> return "@" + notification.account.username
Notification.Type.MENTION, Notification.Type.FAVOURITE, Notification.Type.REBLOG, Notification.Type.STATUS -> return if (!TextUtils.isEmpty(notification.status!!.spoilerText) && !alwaysOpenSpoiler) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the !! is unnecessary as you checked already for null above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted (already removed).

Log.d(TAG, "Enabled pull checks with " + PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS + "ms interval.")
}

fun disablePullNotifications(context: Context) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the context parameter, there is already a Context injected

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bit of a question still: Does it matter which context is used (somewhere)?

90% of locations in the old code worked directly or indirectly with application context. But some did and do not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can matter, yes, for example when taking theme attributes from a context, then you need to use the Activity Context as each Activity can have a different theme. But here it shouldn't 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All removed.

// "Post failed" dialog should display in this activity
draftsAlert.observeInContext(this@MainActivity, true)
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the newer ActivityResultContracts api instead. See ViewMediaActivity for an example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notifications are always disabled on first application run
2 participants