Skip to content

Commit

Permalink
Prettify fix for #73
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf104a committed Mar 5, 2024
1 parent 32759a9 commit c0a18ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static private PendingIntent getReplyIntent(Context context,
intent.putExtra("notification_id", rawNotification.getInt("notification_id"));
intent.putExtra("notification_event", NOTIFICATION_EVENT_FASTREPLY);
String[] link = rawNotification.getString("link").split("/"); // use provided link to extract talk chatroom id
intent.putExtra("talk_chatroom", cleanUpChatroom(link[link.length-1]));
intent.putExtra("talk_link", cleanUpChatroom(rawNotification.getString("link")));
intent.putExtra("talk_chatroom", CommonUtil.cleanUpURLParams(link[link.length-1]));
intent.putExtra("talk_link", CommonUtil.cleanUpURLParams(rawNotification.getString("link")));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
return PendingIntent.getBroadcast(
Expand Down Expand Up @@ -175,7 +175,7 @@ private NotificationBuilderResult setMessagingChatStyle(NotificationController c
NotificationBuilderResult builderResult,
@NonNull JSONObject rawNotification) throws Exception {
Person person = getPersonFromNotification(controller, rawNotification);
final String room = cleanUpChatroom(rawNotification.getString("link"));
final String room = CommonUtil.cleanUpURLParams(rawNotification.getString("link"));
final String title = rawNotification.getJSONObject("subjectRichParameters")
.getJSONObject("call").getString("name");
final String text = rawNotification.getString("message");
Expand Down Expand Up @@ -252,20 +252,11 @@ public NotificationBuilderResult updateNotification(int id, NotificationBuilderR
return builderResult;
}

private static String cleanUpChatroom(@NonNull String chatroom){
String[] splits = chatroom.split("#");
if(splits.length == 0){
return null;
} else {
return splits[0];
}
}

private void onFastReply(Intent intent, NotificationController controller){
final String chatroom =
cleanUpChatroom(
CommonUtil.cleanUpURLParams(
Objects.requireNonNull(intent.getStringExtra("talk_chatroom"))); // the string send by spreed is chatroomid
final String chatroom_link = cleanUpChatroom(
final String chatroom_link = CommonUtil.cleanUpURLParams(
Objects.requireNonNull(intent.getStringExtra("talk_link")));
final int notification_id = intent.getIntExtra("notification_id", -1);
if (notification_id < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.annotation.NonNull;

import java.net.URI;
import java.net.URISyntaxException;

Expand Down Expand Up @@ -71,6 +73,15 @@ public static void safeSleep(long millis){
}
}

public static String cleanUpURLParams(@NonNull String chatroom){
String[] splits = chatroom.split("#");
if(splits.length == 0){
return null;
} else {
return splits[0];
}
}

public static long getTimestamp(){
return System.currentTimeMillis();
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/test/java/com/polar/nextcloudservices/CommonUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ public void testInArray(){
assertTrue(CommonUtil.isInArray(foo, items));
assertFalse(CommonUtil.isInArray(bar, items));
}

@Test
public void testCleanUpURLParams(){
assertEquals(CommonUtil.cleanUpURLParams(""), "");
assertEquals(CommonUtil.cleanUpURLParams("https://example.com/#abcdef"),
"https://example.com/");
assertEquals(CommonUtil.cleanUpURLParams("https://example.com/url/example#abcdef"),
"https://example.com/url/example");
assertEquals(CommonUtil.cleanUpURLParams(
"https://example.com/url/example?a=b&c=d&f=42#abcdef"),
"https://example.com/url/example?a=b&c=d&f=42");
}
}

0 comments on commit c0a18ea

Please sign in to comment.