mirror of
https://github.com/tijder/SmsMatrix.git
synced 2026-03-02 03:40:08 +00:00
Upgrade to matrix-android-sdk 0.9.14.
There's a bunch of changes, required, to move to the latest SDK: 1. Update AAR's. The matrix-sdk.aar in this commit was built from the v0.9.14 tag of the matrix-android-sdk git repository. olm-sdk.jar is pulled from the same place. 2. Updates to the build scripts. matrix-android-sdk added kotlin as a dependency, moved to okhttp3, added io.realm, and so on. 3. Code modifications to support new SDK itself. The changes, here, are a grab bag, and you're best off just reading the commit. Of particular note, here, is that LoginRestClient.loginWithUser takes a device name *and* a device ID, now (the previous API only took a device name). As a wicked had, right now, I'm just using the name as the ID, but I have no doubt that's wrong and this should be cleaned up to include a randomly generated, persisted device ID, as I believe this is used by Synapse to track login sessions.
This commit is contained in:
@@ -6,6 +6,7 @@ import org.matrix.androidsdk.data.MyUser;
|
||||
import org.matrix.androidsdk.data.RoomState;
|
||||
import org.matrix.androidsdk.listeners.IMXEventListener;
|
||||
import org.matrix.androidsdk.rest.model.Event;
|
||||
import org.matrix.androidsdk.rest.model.MatrixError;
|
||||
import org.matrix.androidsdk.rest.model.User;
|
||||
import org.matrix.androidsdk.rest.model.bingrules.BingRule;
|
||||
|
||||
@@ -69,7 +70,7 @@ public class EventListener implements IMXEventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEventEncrypted(Event event) {
|
||||
public void onEventSentStateUpdated(Event event) {
|
||||
|
||||
}
|
||||
|
||||
@@ -83,11 +84,6 @@ public class EventListener implements IMXEventListener {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailedSendingEvent(Event event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBingRulesUpdate() {
|
||||
|
||||
@@ -100,6 +96,11 @@ public class EventListener implements IMXEventListener {
|
||||
mx.getUnreadEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSyncError(MatrixError matrixError) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoSyncComplete() {
|
||||
|
||||
@@ -120,21 +121,26 @@ public class EventListener implements IMXEventListener {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomInitialSyncComplete(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomInternalUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationCountUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaveRoom(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoomKick(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiptEvent(String s, List<String> list) {
|
||||
|
||||
@@ -154,4 +160,44 @@ public class EventListener implements IMXEventListener {
|
||||
public void onToDeviceEvent(Event event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewGroupInvitation(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoinGroup(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaveGroup(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupProfileUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupRoomsListUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupUsersListUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupInvitedUsersListUpdate(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountDataUpdated() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ import org.matrix.androidsdk.listeners.IMXEventListener;
|
||||
import org.matrix.androidsdk.listeners.MXMediaUploadListener;
|
||||
import org.matrix.androidsdk.rest.callback.SimpleApiCallback;
|
||||
import org.matrix.androidsdk.rest.client.LoginRestClient;
|
||||
import org.matrix.androidsdk.rest.model.CreatedEvent;
|
||||
import org.matrix.androidsdk.rest.model.Event;
|
||||
import org.matrix.androidsdk.rest.model.Message;
|
||||
import org.matrix.androidsdk.rest.model.message.Message;
|
||||
import org.matrix.androidsdk.rest.model.login.Credentials;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -70,7 +71,10 @@ public class Matrix {
|
||||
|
||||
public Matrix(final Context context, String url, String botUsername, String botPassword, String username, String device, String syncDelay, String syncTimeout) {
|
||||
this.context = context;
|
||||
hsConfig = new HomeServerConnectionConfig(Uri.parse(url));
|
||||
|
||||
HomeServerConnectionConfig.Builder builder = new HomeServerConnectionConfig.Builder();
|
||||
|
||||
hsConfig = builder.withHomeServerUri(Uri.parse(url)).build();
|
||||
|
||||
realUserid = username;
|
||||
deviceName = device;
|
||||
@@ -83,11 +87,10 @@ public class Matrix {
|
||||
}
|
||||
|
||||
private void login(String username, String password) {
|
||||
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, new SimpleApiCallback<Credentials>() {
|
||||
new LoginRestClient(hsConfig).loginWithUser(username, password, deviceName, deviceName, new SimpleApiCallback<Credentials>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Credentials credentials) {
|
||||
super.onSuccess(credentials);
|
||||
onLogin(credentials);
|
||||
}
|
||||
});
|
||||
@@ -103,7 +106,7 @@ public class Matrix {
|
||||
|
||||
|
||||
if (false) {
|
||||
store = new MXFileStore(hsConfig, context);
|
||||
store = new MXFileStore(hsConfig, false, context);
|
||||
} else {
|
||||
store = new MXMemoryStore(hsConfig.getCredentials(), context);
|
||||
}
|
||||
@@ -112,7 +115,9 @@ public class Matrix {
|
||||
|
||||
// NetworkConnectivityReceiver nwMan = new NetworkConnectivityReceiver();
|
||||
|
||||
session = new MXSession(hsConfig, dh, context);
|
||||
MXSession.Builder builder = new MXSession.Builder(hsConfig, dh, context);
|
||||
|
||||
session = builder.build();
|
||||
session.setSyncDelay(syncDelay * 1000);
|
||||
session.setSyncTimeout(syncTimeout * 60 * 1000);
|
||||
Log.e(TAG, "onLogin:" + session.getSyncTimeout());
|
||||
@@ -120,7 +125,6 @@ public class Matrix {
|
||||
|
||||
|
||||
if (store.isReady()) {
|
||||
session.getDataHandler().checkPermanentStorageData();
|
||||
session.startEventStream(store.getEventStreamToken());
|
||||
session.getDataHandler().addListener(evLis);
|
||||
} else {
|
||||
@@ -132,7 +136,6 @@ public class Matrix {
|
||||
|
||||
@Override
|
||||
public void onStoreReady(String s) {
|
||||
session.getDataHandler().checkPermanentStorageData();
|
||||
session.startEventStream(store.getEventStreamToken());
|
||||
session.getDataHandler().addListener(evLis);
|
||||
}
|
||||
@@ -161,11 +164,16 @@ public class Matrix {
|
||||
if (room == null) {
|
||||
if (!type.equals("m.notice")) {
|
||||
Log.e(TAG, "sendMessage: not found" );
|
||||
session.createRoomDirectMessage(realUserid, new SimpleApiCallback<String>() {
|
||||
session.createDirectMessageRoom(realUserid, new SimpleApiCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String info) {
|
||||
super.onSuccess(info);
|
||||
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>());
|
||||
session.getRoomsApiClient().updateTopic(info, phoneNumber, new SimpleApiCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
changeDisplayname(info, getContactName(phoneNumber, context));
|
||||
Room room = store.getRoom(info);
|
||||
SendMesageToRoom(room, body, type);
|
||||
@@ -191,7 +199,7 @@ public class Matrix {
|
||||
) {
|
||||
String uploadID = String.valueOf(transaction);
|
||||
transaction++;
|
||||
session.getMediasCache().uploadContent(
|
||||
session.getMediaCache().uploadContent(
|
||||
new ByteArrayInputStream(body),
|
||||
fileName,
|
||||
contentType,
|
||||
@@ -213,7 +221,12 @@ public class Matrix {
|
||||
room.getRoomId(),
|
||||
"m.room.message",
|
||||
json,
|
||||
new SimpleApiCallback<Event>()
|
||||
new SimpleApiCallback<CreatedEvent>() {
|
||||
@Override
|
||||
public void onSuccess(CreatedEvent createdEvent) {
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
transaction++;
|
||||
}
|
||||
@@ -225,14 +238,24 @@ public class Matrix {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("displayname", displayname);
|
||||
params.put("membership", "join");
|
||||
session.getRoomsApiClient().sendStateEvent(roomId, "m.room.member", session.getMyUserId(), params, new SimpleApiCallback<Void>());
|
||||
session.getRoomsApiClient().sendStateEvent(roomId, "m.room.member", session.getMyUserId(), params, new SimpleApiCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void SendMesageToRoom(Room room, String body, String type) {
|
||||
Message msg = new Message();
|
||||
msg.body = body;
|
||||
msg.msgtype = type;
|
||||
session.getRoomsApiClient().sendMessage(String.valueOf(transaction), room.getRoomId(), msg, new SimpleApiCallback<Event>());
|
||||
session.getRoomsApiClient().sendMessage(String.valueOf(transaction), room.getRoomId(), msg, new SimpleApiCallback<CreatedEvent>() {
|
||||
@Override
|
||||
public void onSuccess(CreatedEvent createdEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
transaction++;
|
||||
}
|
||||
|
||||
@@ -250,7 +273,7 @@ public class Matrix {
|
||||
}
|
||||
|
||||
public void sendEvent(Event event) {
|
||||
if (event.sender.equals(realUserid)) {
|
||||
if ((event.sender != null) && (event.sender.equals(realUserid))) {
|
||||
Room room = store.getRoom(event.roomId);
|
||||
SmsManager smsManager = SmsManager.getDefault();
|
||||
JsonObject json = event.getContent().getAsJsonObject();
|
||||
@@ -265,16 +288,31 @@ public class Matrix {
|
||||
}
|
||||
} else if (event.type.equals("m.room.member")) {
|
||||
if (json.get("membership").getAsString().equals("leave")) {
|
||||
room.leave(new SimpleApiCallback<Void>());
|
||||
room.leave(new SimpleApiCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
|
||||
}
|
||||
});
|
||||
} else if (json.get("membership").getAsString().equals("invite")) {
|
||||
room.join(new SimpleApiCallback<Void>());
|
||||
room.join(new SimpleApiCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "sendEvent: Event type not supported ");
|
||||
}
|
||||
|
||||
|
||||
room.markAllAsRead(new SimpleApiCallback<Void>());
|
||||
room.markAllAsRead(new SimpleApiCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user