Skip to content

Commit

Permalink
merging browser push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandosborne committed Jun 6, 2024
2 parents 054284a + 18ca575 commit 8503786
Show file tree
Hide file tree
Showing 75 changed files with 3,502 additions and 3,751 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ Databag is designed for efficiency, consuming minimal hosting resources. Notable
- Lightweight (server can run on a raspberry pi zero v1.3)
- Low latency (use of websockets for push events to avoid polling)
- Unlimited accounts per node (host for your whole family)
- Mobile alerts for new contacts, messages, and calls (supports UnifiedPush, FCM, APN)
- Mobile alerts (push notifications on new contacts, messages, and calls)
- Multi-Factor Authentication (integrates with TOTP apps)

<br>
<p align="center">
<a href="https://f-droid.org/en/packages/com.databag/">
<img src="/doc/fdroid.png" width="18%">
</a>
<a href="https://apps.apple.com/us/app/databag/id6443741428">
<img src="/doc/astore.png" width="18%">
</a>
Expand All @@ -50,7 +47,7 @@ Databag is designed for efficiency, consuming minimal hosting resources. Notable
</a>
</p>

The app is available on fdroid as well as the google and apple stores. You can test out the project [here](https://databag.coredb.org/#/create), but don't post anything important as this server is regularly wiped. Feedback on the UI/UX, bugs or features is greatly appreciated.
The app is available in the google and apple stores. You can also test out the project [here](https://databag.coredb.org/#/create), but don't post anything important as this server is regularly wiped. Feedback on the UI/UX, bugs or features is greatly appreciated.

## Installation

Expand All @@ -64,7 +61,7 @@ From the net/container sub directory:
### Example with Portainer and Nginx Proxy Manager

From Portainer:
- In the volume view, click add volume:
- In the volume view, click add volumen:
- Enter a name, then click 'Create the volume'
- In the container view, click add container:
- In the 'Image' field enter 'balzack/databag:latest'
Expand Down
9 changes: 3 additions & 6 deletions app/mobile/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Dashboard } from 'src/dashboard/Dashboard';
import { Session } from 'src/session/Session';
import { Prompt } from 'utils/Prompt';
import ReceiveSharingIntent from 'react-native-receive-sharing-intent';
import { Platform, PermissionsAndroid } from 'react-native';
import {PermissionsAndroid} from 'react-native';
import { initUnifiedPush } from 'react-native-unifiedpush-connector';
import { MenuProvider } from 'react-native-popup-menu';

Expand All @@ -32,11 +32,8 @@ export default function App() {
const [sharing, setSharing] = useState();

useEffect(() => {

if (Platform.OS !== 'ios') {
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
initUnifiedPush();
}

PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);

ReceiveSharingIntent.getReceivedFiles(files => {
setSharing(files);
Expand Down
18 changes: 9 additions & 9 deletions app/mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: "com.facebook.react"

import com.android.build.OutputFile
Expand Down Expand Up @@ -59,7 +58,7 @@ react {
* use App Bundles (https://developer.android.com/guide/app-bundle/)
* and want to have separate APKs to upload to the Play Store.
*/
def enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true

/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
Expand Down Expand Up @@ -94,18 +93,18 @@ android {

compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

namespace "com.databag"
defaultConfig {
applicationId "com.databag"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1018
versionName "1.5"
versionCode 1020
versionName "1.1"
}

splits {
Expand All @@ -116,6 +115,7 @@ compileOptions {
include (*reactNativeArchitectures())
}
}

signingConfigs {
release {
storeFile file('balzack.keystore')
Expand All @@ -124,6 +124,7 @@ compileOptions {
keyPassword 'balzack'
}
}

buildTypes {
debug {
signingConfig signingConfigs.debug
Expand Down Expand Up @@ -158,7 +159,6 @@ dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")


implementation 'androidx.core:core:1.8.0'

implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
Expand Down
39 changes: 0 additions & 39 deletions app/mobile/android/app/google-services.json

This file was deleted.

5 changes: 3 additions & 2 deletions app/mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission tools:node="remove" android:name="android.vending.CHECK_LICENSE" />
<uses-permission tools:node="remove" android:name="com.android.vending.CHECK_LICENSE" />

<application
android:usesCleartextTraffic="true"
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
Expand Down Expand Up @@ -78,7 +79,7 @@

<receiver
android:enabled="true"
android:name="com.unifiedpushconnector.CustomReceiver"
android:name=".CustomReceiver"
android:exported="true">
<intent-filter>
<action android:name="org.unifiedpush.android.connector.MESSAGE"/>
Expand Down
103 changes: 103 additions & 0 deletions app/mobile/android/app/src/main/java/com/databag/CustomReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.databag;

import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.unifiedpush.android.connector.MessagingReceiver;
import android.util.Log;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;

import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManager;
import android.os.Build;
import android.net.Uri;
import android.media.RingtoneManager;
import androidx.core.app.NotificationCompat;
import java.nio.charset.StandardCharsets;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class CustomReceiver extends MessagingReceiver {
public CustomReceiver() {
super();
}

private boolean forgrounded () {
ActivityManager.RunningAppProcessInfo appProcessInfo = new ActivityManager.RunningAppProcessInfo();
ActivityManager.getMyMemoryState(appProcessInfo);
return (appProcessInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || appProcessInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE);
}

@Override
public void onNewEndpoint(@NotNull Context context, @NotNull String endpoint, @NotNull String instance) {

final ReactInstanceManager reactInstanceManager =
((ReactApplication) context.getApplicationContext())
.getReactNativeHost()
.getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();

WritableMap params = Arguments.createMap();
params.putString("instance", instance);
params.putString("endpoint", endpoint);
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("unifiedPushURL", params);

// Called when a new endpoint be used for sending push messages
}

@Override
public void onRegistrationFailed(@NotNull Context context, @NotNull String instance) {
// called when the registration is not possible, eg. no network
}

@Override
public void onUnregistered(@NotNull Context context, @NotNull String instance) {
// called when this application is unregistered from receiving push messages
}

@Override
public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String instance) {

if (forgrounded()) {
return;
}

String strMessage = new String(message, StandardCharsets.UTF_8);


Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
PendingIntent.FLAG_IMMUTABLE);

String channelId = "fcm_default_channel";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(strMessage).setAutoCancel(true).setSound(
defaultSoundUri).setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}

notificationManager.notify(0, notificationBuilder.build());
}
}

19 changes: 19 additions & 0 deletions app/mobile/android/app/src/main/java/com/databag/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ protected String getMainComponentName() {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
MainActivity activityContext = this;

this.getSharedPreferences("unifiedpush.connector", Context.MODE_PRIVATE).edit().putBoolean("unifiedpush.no_distrib_dialog", true).apply();


ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext validContext) {

UnifiedPush.registerAppWithDialog(
activityContext,
"default",
new RegistrationDialogContent(),
new ArrayList<String>(),
getApplicationContext().getPackageName()
);

}
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/mobile/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
classpath("com.android.tools.build:gradle:7.3.1")
classpath("com.facebook.react:react-native-gradle-plugin")
}
Expand All @@ -32,3 +31,4 @@ allprojects {
}
}
}

5 changes: 0 additions & 5 deletions app/mobile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@ import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

messaging().registerDeviceForRemoteMessages().then(() => {});

messaging().setBackgroundMessageHandler(async remoteMessage => {});

AppRegistry.registerComponent(appName, () => App);
Loading

0 comments on commit 8503786

Please sign in to comment.