Add push notifications for GNU + Friendica
This commit is contained in:
parent
7be79ed5de
commit
14080458fb
|
@ -48,6 +48,7 @@ import app.fedilab.android.client.API;
|
||||||
import app.fedilab.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.Notification;
|
import app.fedilab.android.client.Entities.Notification;
|
||||||
|
import app.fedilab.android.client.GNUAPI;
|
||||||
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
@ -139,11 +140,15 @@ public class NotificationsSyncJob extends Job {
|
||||||
return;
|
return;
|
||||||
//Retrieve users in db that owner has.
|
//Retrieve users in db that owner has.
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA")) {
|
APIResponse apiResponse;
|
||||||
|
if(account.getSocial().compareTo("FRIENDICA") != 0 && account.getSocial().compareTo("GNU") != 0 ) {
|
||||||
API api = new API(getContext(), account.getInstance(), account.getToken());
|
API api = new API(getContext(), account.getInstance(), account.getToken());
|
||||||
APIResponse apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
||||||
onRetrieveNotifications(apiResponse, account);
|
}else{
|
||||||
|
GNUAPI gnuApi = new GNUAPI(getContext(), account.getInstance(), account.getToken());
|
||||||
|
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
|
||||||
}
|
}
|
||||||
|
onRetrieveNotifications(apiResponse, account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import app.fedilab.android.client.API;
|
||||||
import app.fedilab.android.client.APIResponse;
|
import app.fedilab.android.client.APIResponse;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.client.Entities.Notification;
|
import app.fedilab.android.client.Entities.Notification;
|
||||||
|
import app.fedilab.android.client.GNUAPI;
|
||||||
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
import app.fedilab.android.fragments.DisplayNotificationsFragment;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
@ -103,11 +104,9 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
totalAccount = 0;
|
totalAccount = 0;
|
||||||
if( accountStreams != null) {
|
if( accountStreams != null) {
|
||||||
for (Account account : accountStreams) {
|
for (Account account : accountStreams) {
|
||||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA") || account.getSocial().equals("PIXELFED")) {
|
boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + account.getId() + account.getInstance(), true);
|
||||||
boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + account.getId() + account.getInstance(), true);
|
if (allowStream) {
|
||||||
if (allowStream) {
|
totalAccount++;
|
||||||
totalAccount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,15 +239,22 @@ public class LiveNotificationDelayedService extends Service {
|
||||||
private void taks(Account account) {
|
private void taks(Account account) {
|
||||||
String key = account.getUsername() + "@" + account.getInstance();
|
String key = account.getUsername() + "@" + account.getInstance();
|
||||||
APIResponse apiResponse;
|
APIResponse apiResponse;
|
||||||
API api;
|
|
||||||
api = new API(getApplicationContext(), account.getInstance(), account.getToken());
|
|
||||||
String last_notifid = null;
|
String last_notifid = null;
|
||||||
if (since_ids.containsKey(key)) {
|
if (since_ids.containsKey(key)) {
|
||||||
last_notifid = since_ids.get(key);
|
last_notifid = since_ids.get(key);
|
||||||
}
|
}
|
||||||
apiResponse = null;
|
apiResponse = null;
|
||||||
try {
|
try {
|
||||||
apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid, false);
|
if(account.getSocial().compareTo("FRIENDICA") != 0 && account.getSocial().compareTo("GNU") != 0 ) {
|
||||||
|
API api;
|
||||||
|
api = new API(getApplicationContext(), account.getInstance(), account.getToken());
|
||||||
|
apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid, false);
|
||||||
|
}else{
|
||||||
|
GNUAPI gnuApi;
|
||||||
|
gnuApi = new GNUAPI(getApplicationContext(), account.getInstance(), account.getToken());
|
||||||
|
apiResponse = gnuApi.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, last_notifid, false);
|
||||||
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue