Skip to content

Commit

Permalink
Merge branch 'develop' into fix.password-protected-channel
Browse files Browse the repository at this point in the history
  • Loading branch information
DanMke authored Oct 1, 2020
2 parents 0ff3842 + 2b3a5f8 commit 561fe68
Show file tree
Hide file tree
Showing 252 changed files with 42,554 additions and 27,004 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
if [[ $KEYSTORE ]]; then
echo $GOOGLE_SERVICES_ANDROID | base64 --decode > google-services.json
fi
working_directory: android/app
working_directory: android/app/src/play

- run:
name: Config variables
Expand Down
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ yarn

Run the app:
```sh
npx react-native run-ios
yarn ios
```

or

```sh
npx react-native run-android
yarn android
```

At this point, the app should be running on the simulator or on your device!

*Note: npm won't work on this project*

### How to inspect the app

We use [Reactotron](https://github.com/infinitered/reactotron) to inspect logs, redux state, redux-sagas, HTTP requests, etc.

## Issues needing help

Didn't find a bug or want a new feature not already reported? Check out the [help wanted](https://github.com/RocketChat/Rocket.Chat.ReactNative/issues?q=is%3Aissue+is%3Aopen+label%3A%22%F0%9F%91%8B+help+wanted%22) or the [good first issue](https://github.com/RocketChat/Rocket.Chat.ReactNative/issues?q=is%3Aissue+is%3Aopen+label%3A%22%F0%9F%8D%AD+good+first+issue%22) labels.
Expand Down
159 changes: 159 additions & 0 deletions __tests__/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,165 @@ exports[`Storyshots Message list message 1`] = `
>
Edited
</Text>
<Text
style={
Array [
Object {
"fontSize": 20,
"fontWeight": "300",
"marginLeft": 10,
"marginVertical": 30,
},
Object {
"color": "#0d0e12",
},
Object {
"marginBottom": 0,
"marginTop": 30,
},
]
}
>
Encrypted
</Text>
<View>
<View
style={
Array [
Object {
"flexDirection": "column",
"paddingHorizontal": 14,
"paddingVertical": 4,
"width": "100%",
},
undefined,
]
}
>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Array [
Object {
"borderRadius": 4,
"height": 36,
"width": 36,
},
Object {
"marginTop": 4,
},
]
}
/>
<View
style={
Array [
Object {
"flex": 1,
"marginLeft": 46,
},
Object {
"marginLeft": 10,
},
]
}
>
<View
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
}
}
>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 12,
"fontWeight": "300",
"lineHeight": 22,
"paddingLeft": 10,
},
Object {
"color": "#9ca2a8",
},
]
}
>
10:00 AM
</Text>
</View>
<View>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Object {
"flex": 1,
}
}
>
<Text
numberOfLines={0}
style={
Array [
undefined,
Object {
"color": "#2f343d",
},
]
}
>
<Text
accessibilityLabel="This message has error and is encrypted"
numberOfLines={0}
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
},
Array [
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginTop": 0,
},
],
]
}
>
This message has error and is encrypted
</Text>
</Text>
</View>
</View>
</View>
</View>
</View>
</View>
</View>
<Text
style={
Array [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chat.rocket.reactnative;

import android.os.Bundle;

import androidx.annotation.Nullable;

public class Callback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import android.os.Build;
import android.os.Bundle;
import android.app.Person;

import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.concurrent.ExecutionException;
import java.lang.InterruptedException;

Expand Down Expand Up @@ -84,6 +86,15 @@ public void call(@Nullable Bundle bundle) {
boolean hasSender = loadedEjson.sender != null;
String title = bundle.getString("title");

// If it has a encrypted message
if (loadedEjson.msg != null) {
// Override message with the decrypted content
String decrypted = Encryption.shared.decryptMessage(loadedEjson, reactApplicationContext);
if (decrypted != null) {
bundle.putString("message", decrypted);
}
}

bundle.putLong("time", new Date().getTime());
bundle.putString("username", hasSender ? loadedEjson.sender.username : title);
bundle.putString("senderId", hasSender ? loadedEjson.sender._id : "1");
Expand Down Expand Up @@ -114,12 +125,12 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
Ejson ejson = new Gson().fromJson(bundle.getString("ejson", "{}"), Ejson.class);

notification
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);

Integer notificationId = Integer.parseInt(notId);
notificationColor(notification);
Expand All @@ -132,7 +143,7 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) {
notificationStyle(notification, notificationId, bundle);
notificationReply(notification, notificationId, bundle);

// message couldn't be loaded from server (Fallback notification)
// message couldn't be loaded from server (Fallback notification)
} else {
Gson gson = new Gson();
// iterate over the current notification ids to dismiss fallback notifications from same server
Expand Down Expand Up @@ -163,11 +174,11 @@ private void notifyReceivedToJS() {
private Bitmap getAvatar(String uri) {
try {
return Glide.with(mContext)
.asBitmap()
.apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))
.load(uri)
.submit(100, 100)
.get();
.asBitmap()
.apply(RequestOptions.bitmapTransform(new RoundedCorners(10)))
.load(uri)
.submit(100, 100)
.get();
} catch (final ExecutionException | InterruptedException e) {
return largeIcon();
}
Expand Down Expand Up @@ -203,8 +214,8 @@ private void notificationChannel(Notification.Builder notification) {
String CHANNEL_NAME = "All";

NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);

final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
Expand Down Expand Up @@ -253,9 +264,9 @@ private void notificationStyle(Notification.Builder notification, int notId, Bun
messageStyle = new Notification.MessagingStyle("");
} else {
Person sender = new Person.Builder()
.setKey("")
.setName("")
.build();
.setKey("")
.setName("")
.build();
messageStyle = new Notification.MessagingStyle(sender);
}

Expand All @@ -279,9 +290,14 @@ private void notificationStyle(Notification.Builder notification, int notId, Bun
} else {
Bitmap avatar = getAvatar(avatarUri);

String name = username;
if (ejson.senderName != null) {
name = ejson.senderName;
}

Person.Builder sender = new Person.Builder()
.setKey(senderId)
.setName(username);
.setKey(senderId)
.setName(name);

if (avatar != null) {
sender.setIcon(Icon.createWithBitmap(avatar));
Expand Down Expand Up @@ -317,18 +333,18 @@ private void notificationReply(Notification.Builder notification, int notificati
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

RemoteInput remoteInput = new RemoteInput.Builder(KEY_REPLY)
.setLabel(label)
.build();
.setLabel(label)
.build();

CharSequence title = label;
Notification.Action replyAction = new Notification.Action.Builder(smallIconResId, title, replyPendingIntent)
.addRemoteInput(remoteInput)
.setAllowGeneratedReplies(true)
.build();
.addRemoteInput(remoteInput)
.setAllowGeneratedReplies(true)
.build();

notification
.setShowWhen(true)
.addAction(replyAction);
.setShowWhen(true)
.addAction(replyAction);
}

private void notificationDismiss(Notification.Builder notification, int notificationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import android.content.Intent;

public class DismissNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int notId = intent.getExtras().getInt(CustomPushNotification.NOTIFICATION_ID);
CustomPushNotification.clearMessages(notId);
}
@Override
public void onReceive(Context context, Intent intent) {
int notId = intent.getExtras().getInt(CustomPushNotification.NOTIFICATION_ID);
CustomPushNotification.clearMessages(notId);
}
}
10 changes: 10 additions & 0 deletions android/app/src/play/java/chat/rocket/reactnative/Ejson.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Ejson {
Sender sender;
String messageId;
String notificationType;
String senderName;
String msg;

private MMKV mmkv;

Expand Down Expand Up @@ -82,6 +84,14 @@ public String userId() {
return "";
}

public String privateKey() {
String serverURL = serverURL();
if (mmkv != null && serverURL != null) {
return mmkv.decodeString(serverURL.concat("-RC_E2E_PRIVATE_KEY"));
}
return null;
}

public String serverURL() {
String url = this.host;
if (url != null && url.endsWith("/")) {
Expand Down
Loading

0 comments on commit 561fe68

Please sign in to comment.