From 38b6720a90f1ef290f118b28d07866149dca661b Mon Sep 17 00:00:00 2001 From: untidylamp_gitlab <44341286+untidylamp@users.noreply.github.com> Date: Thu, 1 Nov 2018 17:35:50 -0400 Subject: [PATCH] Join and Leave rooms Join a room if invited by user Leave the room when the user leaves --- .../java/eu/droogers/smsmatrix/Matrix.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java index 93481fc..3f5a09d 100644 --- a/app/src/main/java/eu/droogers/smsmatrix/Matrix.java +++ b/app/src/main/java/eu/droogers/smsmatrix/Matrix.java @@ -254,15 +254,27 @@ public class Matrix { Room room = store.getRoom(event.roomId); SmsManager smsManager = SmsManager.getDefault(); JsonObject json = event.getContent().getAsJsonObject(); + + if (event.type.equals("m.room.message")) { - if (json.get("msgtype").getAsString().equals(MESSAGE_TYPE_TEXT)) { - String body = json.get("body").getAsString(); - smsManager.sendTextMessage(room.getTopic(), null, body, null, null); + if (json.get("msgtype").getAsString().equals(MESSAGE_TYPE_TEXT)) { + String body = json.get("body").getAsString(); + smsManager.sendTextMessage(room.getTopic(), null, body, null, null); + } else { + String url = session.getContentManager().getDownloadableUrl(json.get("url").getAsString()); + smsManager.sendTextMessage(room.getTopic(), null, url, null, null); + } + } else if (event.type.equals("m.room.member")) { + if (json.get("membership").getAsString().equals("leave")) { + room.leave(new SimpleApiCallback()); + } else if (json.get("membership").getAsString().equals("invite")) { + room.join(new SimpleApiCallback()); + } } else { - String url = session.getContentManager().getDownloadableUrl(json.get("url").getAsString()); - smsManager.sendTextMessage(room.getTopic(), null, url, null, null); + Log.e(TAG, "sendEvent: Event type not supported "); } + room.markAllAsRead(new SimpleApiCallback()); } }