fedilab-Android-App/app/src/main/java/app/fedilab/android/services/UnifiedPushService.java

77 lines
2.7 KiB
Java
Raw Normal View History

2021-02-21 17:18:37 +01:00
package app.fedilab.android.services;
2021-02-28 10:38:49 +01:00
/* Copyright 2021 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
2021-02-21 17:18:37 +01:00
import android.content.Context;
2021-02-28 11:46:34 +01:00
import android.database.sqlite.SQLiteDatabase;
2021-02-21 17:18:37 +01:00
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.unifiedpush.android.connector.MessagingReceiver;
import org.unifiedpush.android.connector.MessagingReceiverHandler;
2021-02-28 11:46:34 +01:00
import app.fedilab.android.client.Entities.Account;
2021-03-03 14:30:45 +01:00
import app.fedilab.android.helper.ECDH;
2021-02-28 11:46:34 +01:00
import app.fedilab.android.helper.NotificationsHelper;
2021-02-21 17:18:37 +01:00
import app.fedilab.android.helper.PushNotifications;
2021-02-28 11:46:34 +01:00
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
2021-02-23 18:34:58 +01:00
class handler implements MessagingReceiverHandler {
2021-02-23 18:34:58 +01:00
2021-02-21 17:18:37 +01:00
@Override
2021-03-01 11:12:01 +01:00
public void onMessage(@Nullable Context context, @NotNull String s, @NotNull String slug) {
2021-03-02 11:59:49 +01:00
2021-02-28 11:46:34 +01:00
new Thread(() -> {
2021-03-03 11:32:43 +01:00
if (context != null) {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String[] slugArray = slug.split("@");
2021-03-03 14:30:45 +01:00
ECDH ecdh = ECDH.getInstance();
//ecdh.uncryptMessage(context, s, slug);
2021-03-03 11:32:43 +01:00
Account account = new AccountDAO(context, db).getUniqAccountUsernameInstance(slugArray[0], slugArray[1]);
NotificationsHelper.task(context, account);
}
2021-02-28 11:46:34 +01:00
}).start();
2021-02-28 10:38:49 +01:00
}
@Override
2021-03-01 11:12:01 +01:00
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
2021-03-03 11:32:43 +01:00
if (context != null) {
new PushNotifications()
.registerPushNotifications(context, endpoint, slug);
}
2021-02-21 17:18:37 +01:00
}
@Override
2021-03-01 11:12:01 +01:00
public void onRegistrationFailed(@Nullable Context context, @NotNull String s) {
2021-02-21 17:18:37 +01:00
}
@Override
2021-03-01 11:12:01 +01:00
public void onRegistrationRefused(@Nullable Context context, @NotNull String s) {
2021-02-21 17:18:37 +01:00
}
@Override
2021-03-01 11:12:01 +01:00
public void onUnregistered(@Nullable Context context, @NotNull String s) {
2021-02-23 18:34:58 +01:00
}
2021-02-21 17:18:37 +01:00
}
2021-02-23 18:34:58 +01:00
public class UnifiedPushService extends MessagingReceiver {
2021-02-21 17:18:37 +01:00
public UnifiedPushService() {
super(new handler());
}
}