Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

android {
compileSdkVersion 26
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "eu.droogers.smsmatrix"
minSdkVersion 23
targetSdkVersion 26
targetSdkVersion 27
versionCode 10
versionName "0.0.10"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -23,23 +26,32 @@ android {
dir 'libs'
}
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

dependencies {
implementation 'com.android.support:appcompat-v7:26.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'

implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testCompile 'junit:junit:4.12'

compile(name: 'matrix-sdk', ext: 'aar')
compile(name: 'olm-sdk', ext: 'aar')
implementation(name: 'matrix-sdk', ext: 'aar')
implementation(name: 'olm-sdk', ext: 'aar')

compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
}
Binary file modified app/libs/matrix-sdk.aar
Binary file not shown.
Binary file modified app/libs/olm-sdk.aar
Binary file not shown.
62 changes: 54 additions & 8 deletions app/src/main/java/eu/droogers/smsmatrix/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand Down Expand Up @@ -69,7 +70,7 @@ public void onBingEvent(Event event, RoomState roomState, BingRule bingRule) {
}

@Override
public void onEventEncrypted(Event event) {
public void onEventSentStateUpdated(Event event) {

}

Expand All @@ -83,11 +84,6 @@ public void onEventSent(Event event, String s) {

}

@Override
public void onFailedSendingEvent(Event event) {

}

@Override
public void onBingRulesUpdate() {

Expand All @@ -100,6 +96,11 @@ public void onInitialSyncComplete(String s) {
mx.getUnreadEvents();
}

@Override
public void onSyncError(MatrixError matrixError) {

}

@Override
public void onCryptoSyncComplete() {

Expand All @@ -121,12 +122,12 @@ public void onRoomFlush(String s) {
}

@Override
public void onRoomInitialSyncComplete(String s) {
public void onRoomInternalUpdate(String s) {

}

@Override
public void onRoomInternalUpdate(String s) {
public void onNotificationCountUpdate(String s) {

}

Expand All @@ -135,6 +136,11 @@ public void onLeaveRoom(String s) {

}

@Override
public void onRoomKick(String s) {

}

@Override
public void onReceiptEvent(String s, List<String> list) {

Expand All @@ -154,4 +160,44 @@ public void onReadMarkerEvent(String s) {
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() {

}
}
76 changes: 57 additions & 19 deletions app/src/main/java/eu/droogers/smsmatrix/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
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;
Expand Down Expand Up @@ -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;
Expand All @@ -83,11 +87,10 @@ public Matrix(final Context context, String url, String botUsername, String botP
}

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);
}
});
Expand All @@ -103,7 +106,7 @@ public void startEventStream() {


if (false) {
store = new MXFileStore(hsConfig, context);
store = new MXFileStore(hsConfig, false, context);
} else {
store = new MXMemoryStore(hsConfig.getCredentials(), context);
}
Expand All @@ -112,15 +115,16 @@ public void startEventStream() {

// 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());



if (store.isReady()) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
} else {
Expand All @@ -132,7 +136,6 @@ public void postProcess(String s) {

@Override
public void onStoreReady(String s) {
session.getDataHandler().checkPermanentStorageData();
session.startEventStream(store.getEventStreamToken());
session.getDataHandler().addListener(evLis);
}
Expand Down Expand Up @@ -161,11 +164,16 @@ public void sendMessage(final String phoneNumber, final String body, final Strin
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);
Expand All @@ -191,7 +199,7 @@ public void sendFile(
) {
String uploadID = String.valueOf(transaction);
transaction++;
session.getMediasCache().uploadContent(
session.getMediaCache().uploadContent(
new ByteArrayInputStream(body),
fileName,
contentType,
Expand All @@ -213,7 +221,12 @@ public void onUploadComplete(final String uploadId, final String contentUri) {
room.getRoomId(),
"m.room.message",
json,
new SimpleApiCallback<Event>()
new SimpleApiCallback<CreatedEvent>() {
@Override
public void onSuccess(CreatedEvent createdEvent) {

}
}
);
transaction++;
}
Expand All @@ -225,14 +238,24 @@ private void changeDisplayname(String roomId, String displayname) {
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++;
}

Expand All @@ -250,7 +273,7 @@ public void getUnreadEvents() {
}

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();
Expand All @@ -265,16 +288,31 @@ public void sendEvent(Event event) {
}
} 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) {

}
});
}
}

Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.10'

repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "io.realm:realm-gradle-plugin:5.8.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down