From 685f0b806df7f4cb5d4f9ac87aa43aa901aade45 Mon Sep 17 00:00:00 2001 From: zedonboy Date: Wed, 20 Jan 2021 21:55:04 +0100 Subject: [PATCH 1/2] Created a Notification and Messaging Client Backend(connects to server) --- settings.gradle | 2 +- socketManagerLib/.gitignore | 1 + socketManagerLib/README.md | 12 + socketManagerLib/build.gradle | 43 ++ socketManagerLib/consumer-rules.pro | 0 socketManagerLib/proguard-rules.pro | 21 + .../ExampleInstrumentedTest.kt | 24 ++ socketManagerLib/src/main/AndroidManifest.xml | 4 + .../socketmanagerlib/SocketComponent.kt | 399 ++++++++++++++++++ .../socketmanagerlib/wsTypes.kt | 59 +++ .../socketmanagerlib/ExampleUnitTest.kt | 17 + 11 files changed, 581 insertions(+), 1 deletion(-) create mode 100644 socketManagerLib/.gitignore create mode 100644 socketManagerLib/README.md create mode 100644 socketManagerLib/build.gradle create mode 100644 socketManagerLib/consumer-rules.pro create mode 100644 socketManagerLib/proguard-rules.pro create mode 100644 socketManagerLib/src/androidTest/java/com/fightpandemics/socketmanagerlib/ExampleInstrumentedTest.kt create mode 100644 socketManagerLib/src/main/AndroidManifest.xml create mode 100644 socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt create mode 100644 socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt create mode 100644 socketManagerLib/src/test/java/com/fightpandemics/socketmanagerlib/ExampleUnitTest.kt diff --git a/settings.gradle b/settings.gradle index 4998912a..b5489bf7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ - +include ':socketManagerLib' rootProject.name='Fight Pandemics' include ':app' include ':core' diff --git a/socketManagerLib/.gitignore b/socketManagerLib/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/socketManagerLib/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/socketManagerLib/README.md b/socketManagerLib/README.md new file mode 100644 index 00000000..685fa8d9 --- /dev/null +++ b/socketManagerLib/README.md @@ -0,0 +1,12 @@ +This Library contains. + +1. A backend file that handles Realtime Messaging + and Notifications. + +2. The backend file is not tested yet. but needs +a frontend that implements business Logic and UI reactions + frontends listens to event from the eventBus + and updates WebSocket. + +3. IF YOU ARE NEW, DO NOT WORK ON THIS DIRECTLY, CONTACT ME(Zedoniz@gmail.com) FIRST!!! +I WILL DIRECT YOU WHERE YOU SHOULD WORK ON, ESPECIALLY THE TEST CASES \ No newline at end of file diff --git a/socketManagerLib/build.gradle b/socketManagerLib/build.gradle new file mode 100644 index 00000000..a55771fa --- /dev/null +++ b/socketManagerLib/build.gradle @@ -0,0 +1,43 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + testImplementation 'junit:junit:4.13.1' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + // Socket Libs + implementation 'com.github.nkzawa:socket.io-client:0.6.0' + //Gson + implementation 'com.google.code.gson:gson:2.8.6' + //Eventbus + implementation 'org.greenrobot:eventbus:3.2.0' + +} \ No newline at end of file diff --git a/socketManagerLib/consumer-rules.pro b/socketManagerLib/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/socketManagerLib/proguard-rules.pro b/socketManagerLib/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/socketManagerLib/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/socketManagerLib/src/androidTest/java/com/fightpandemics/socketmanagerlib/ExampleInstrumentedTest.kt b/socketManagerLib/src/androidTest/java/com/fightpandemics/socketmanagerlib/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..b49d9965 --- /dev/null +++ b/socketManagerLib/src/androidTest/java/com/fightpandemics/socketmanagerlib/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.fightpandemics.socketmanagerlib + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.fightpandemics.socketmanagerlib.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/socketManagerLib/src/main/AndroidManifest.xml b/socketManagerLib/src/main/AndroidManifest.xml new file mode 100644 index 00000000..fafb8495 --- /dev/null +++ b/socketManagerLib/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt new file mode 100644 index 00000000..fee47b7f --- /dev/null +++ b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt @@ -0,0 +1,399 @@ +package com.fightpandemics.socketmanagerlib + +import com.github.nkzawa.emitter.Emitter +import com.github.nkzawa.socketio.client.Ack +import com.github.nkzawa.socketio.client.IO +import com.github.nkzawa.socketio.client.Socket +import com.google.gson.Gson +import com.google.gson.JsonElement +import org.greenrobot.eventbus.EventBus +import org.json.JSONObject + +/** + * Read Carefully + * 1. This class is the backend, that handle all realtime messaging and notification + * 2. Frontend Implementation should listen to its events. and update WebSocketStateView accordings + * 3. Make sure forceRoomUpdate is implemented or assigned a lambda. + * */ +class SocketComponentBackend { + private var _socket : Socket + private var _gson : Gson + private var _eventBus : EventBus + + constructor(url : String){ + _socket = IO.socket(url) + _gson = Gson() + _eventBus = EventBus.getDefault() + } + + constructor(socket: Socket, gson : Gson, eventBus : EventBus){ + _socket = socket + _gson = gson + _eventBus = eventBus + } + + /** + * This property is a function that is in charge of a situation if a user is blocked + * */ + var forceRoomUpdate = fun(_: String){ + throw Exception("You must implement a forceUpdateListener. " + + ".forceRoomUpdate = ") + } + fun stop() { + _socket.close() + } + + fun getEventBus() : EventBus{ + return _eventBus + } + fun getSocket() : Socket{ + return _socket + } + + + /** + * This Function posts IDENTIFY_SUCCESS and IDENTIFY_ERROR Events, + * passes a nothing + * respectively + * */ + fun identify(organisationId : String, oldRoomId : String, cb : wsCallBack) { + val jsonObject = JSONObject() + jsonObject.put("organisationId", organisationId) + _socket.emit(IDENTIFY, jsonObject, Ack{ + if(it.isEmpty()) return@Ack + val responseJSONObject = it[0] as JSONObject + val jsondata = responseJSONObject.toString() + val response = _gson.fromJson(jsondata, Response::class.java) + if(response.code == 200){ + getUserRooms() + getNotifications() + joinRoom(JoinRoom(oldRoomId)) + _eventBus.post(WSEvent(wsEventsTypes.IDENTIFY_SUCCESS)) + cb.onSuccess(true) + } else { + _eventBus.post(WSEvent(wsEventsTypes.IDENTIFY_ERROR)) + cb.onError(Error(response.message)) + } + }) + } + + /** + * This Functions sends messsage to Server. onSuccess is called and passed true or false + * if the request is successful or error respectively + * @param messageData + * @param callBack + * + * */ + + fun sendMessage(messageData : Message, callBack: wsCallBack) { + val jsonedMssg = _gson.toJson(messageData) + _socket.emit(SEND_MESSAGE, JSONObject(jsonedMssg), Ack{ + if(it.isEmpty()) return@Ack + val responseJSONObject = it[0] as JSONObject + val jsondata = responseJSONObject.toString() + val response = _gson.fromJson(jsondata, Response::class.java) + if(response.code == 200){ + callBack.onSuccess(true) + } else { + callBack.onSuccess(false) + } + }) + } + + fun deleteMessage(messageId : String, cb : wsCallBack? = null){ + _socket.emit(DELETE_MESSAGE, messageId) + } + + fun editMessage(data : Message, cb : wsCallBack? = null){ + val jsonedMssg = _gson.toJson(data) + _socket.emit(EDIT_MESSAGE, JSONObject(jsonedMssg)) + } + + /** + * This Function posts JOIN_ROOM_SUCCESS and JOIN_ROOM_ERROR Events, + * passes a payload of JsonElement type from Gson library and null + * respectively + * */ + fun joinRoom(data : JoinRoom, cb : wsCallBack? = null){ + val jsoned = _gson.toJson(data) + _socket.emit(JOIN_ROOM, JSONObject(jsoned), Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + _eventBus.post(WSEvent(wsEventsTypes.JOIN_ROOM_SUCCESS, response.data)) + cb?.onSuccess?.invoke(response.data) + } else { + _eventBus.post(WSEvent(wsEventsTypes.JOIN_ROOM_ERROR)) + cb?.onError?.invoke(Error(response.message)) + } + }) + } + + fun leaveAllRooms(wsCallBack: wsCallBack? = null) { + joinRoom(JoinRoom(), wsCallBack) + } + + /** + * This Function posts GET_ROOMS_SUCCESS and GET_ROOMS_ERROR Events, + * passes a payload of JsonElement type from Gson library and null respectively + * */ + fun getUserRooms(cb : wsCallBack? = null){ + _socket.emit(GET_USER_THREADS, null, Ack{ + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + _eventBus.post(WSEvent(wsEventsTypes.GET_ROOMS_SUCCESS, response.data)) + cb?.onSuccess?.invoke(response.data) + } else { + _eventBus.post(WSEvent(wsEventsTypes.GET_ROOMS_ERROR)) + cb?.onError?.invoke(Error(response.message)) + } + }) + } + + /** + * This Function posts GET_MESSAGE_HISTORY and GET_MESSAGE_HISTORY_ERROR Events, + * passes a payload of JsonElement type from Gson library and null respectively + * */ + fun getChatLog(data : GetChatLog, cb: wsCallBack? = null) { + val jsonedMssg = _gson.toJson(data) + _socket.emit(GET_CHAT_LOG, JSONObject(jsonedMssg), Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + _eventBus.post(WSEvent(wsEventsTypes.GET_MESSAGES_HISTORY, response.data)) + cb?.onSuccess?.invoke(response.data) + } else { + _eventBus.post(WSEvent(wsEventsTypes.GET_MESSAGES_HISTORY_ERROR)) + cb?.onError?.invoke(Error(response.message)) + } + }) + } + + /** + * This Function posts GET_MORE_MESSAGE_HISTORY events + * passes a payload of JsonElement type from Gson library + * */ + fun loadMore(data : LoadMore, cb: wsCallBack? = null){ + val jsonedMssg = _gson.toJson(data) + _socket.emit(GET_CHAT_LOG_MORE, JSONObject(jsonedMssg), Ack{ + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + _eventBus.post(WSEvent(wsEventsTypes.GET_MORE_MESSAGES_HISTORY, response.data)) + cb?.onSuccess?.invoke(true) + } else cb?.onSuccess?.invoke(false) + }) + } + + + fun getUserStatus(userId : String, cb: wsCallBack? = null) { + _socket.emit(GET_USER_STATUS, userId, Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + cb?.onSuccess?.invoke(response.data) + } else cb?.onError?.invoke(Error(response.message)) + }) + } + + fun blockThread(threadId : String, cb: wsCallBack? = null){ + val jsondata = JSONObject() + jsondata.put("threadId", threadId) + jsondata.put("newStatus", "blocked") + _socket.emit(UPDATE_THREAD_STATUS, jsondata, Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + joinRoom(JoinRoom(threadId), cb) + } else cb?.onError?.invoke(Error(response.message)) + }) + } + + fun archiveThread(threadId : String, cb: wsCallBack? = null) { + val jsondata = JSONObject() + jsondata.put("threadId", threadId) + jsondata.put("newStatus", "archived") + _socket.emit(UPDATE_THREAD_STATUS, jsondata, Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + joinRoom(JoinRoom(threadId)) + leaveAllRooms(cb) + } else cb?.onError?.invoke(Error(response.message)) + }) + } + + fun ignoreThread(threadId : String, cb: wsCallBack? = null){ + val jsondata = JSONObject() + jsondata.put("threadId", threadId) + jsondata.put("newStatus", "ignored") + _socket.emit(UPDATE_THREAD_STATUS, jsondata, Ack { + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + joinRoom(JoinRoom(threadId)) + leaveAllRooms(cb) + } else cb?.onError?.invoke(Error(response.message)) + }) + } + + fun postShared(data : PostShared){ + val jsonedMssg = _gson.toJson(data) + _socket.emit(POST_SHARED, JSONObject(jsonedMssg)) + } + + fun getNotifications() { + _socket.emit(GET_NOTIFICATIONS, null, Ack{ + if (it.isEmpty()) return@Ack // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val response = _gson.fromJson(jsonobj.toString(), Response::class.java) + if(response.code == 200){ + _eventBus.post(WSEvent(wsEventsTypes.GET_NOTIFICATIONS_SUCCESS, response.data)) + } + }) + } + + fun markNotificationsAsRead(notificationId : String) { + val json = JSONObject() + json.put("notificationId", notificationId) + _socket.emit(MARK_NOTIFICATIONS_AS_READ, json) + } + + fun clearNotification(){ + _socket.emit(CLEAR_NOTIFICATION) + } + + fun clearAllNotification(){ + _socket.emit(CLEAR_ALL_NOTIFICATIONS) + } + + fun activateAllListeners() { + _socket.on(MESSAGE_RECEIVED, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val message = _gson.fromJson(jsonobj.toString(), Message::class.java) + _eventBus.post(WSEvent(wsEventsTypes.MESSAGE_RECEIVED, message)) + _eventBus.post(WSEvent(wsEventsTypes.SET_LAST_MESSAGE, message)) + }) + + _socket.on(MESSAGE_DELETED, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val message = _gson.fromJson(jsonobj.toString(), Message::class.java) + _eventBus.post(WSEvent(wsEventsTypes.MESSAGE_DELETED, message)) + }) + + _socket.on(MESSAGE_EDITED, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val message = _gson.fromJson(jsonobj.toString(), Message::class.java) + _eventBus.post(WSEvent(wsEventsTypes.MESSAGE_EDITED, message)) + }) + + _socket.on(NEW_MESSAGE_NOTIFICATION, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val message = _gson.fromJson(jsonobj.toString(), Message::class.java) + _eventBus.post(WSEvent(wsEventsTypes.MESSAGE_RECEIVED, arrayOf(message, true))) + }) + + _socket.on(USER_STATUS_UPDATE, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val data = _gson.fromJson(jsonobj.toString(), UserStatusUpdate::class.java) + _eventBus.post(WSEvent(wsEventsTypes.MESSAGE_RECEIVED, data)) + }) + + _socket.on(FORCE_ROOM_UPDATE, Emitter.Listener { + if (it.isEmpty()) return@Listener + forceRoomUpdate(it[0] as String) + getUserRooms() + }) + + _socket.on(NEW_NOTIFICATION, Emitter.Listener { + if (it.isEmpty()) return@Listener // I hate nonsense!! + val jsonobj = it[0] as JSONObject + val data = _gson.fromJson(jsonobj.toString(), Notification::class.java) + _eventBus.post(WSEvent(wsEventsTypes.NEW_NOTIFICATION, data)) + }) + } + + + companion object { + fun buider() : SocketComponentBackendBuilder{ + return SocketComponentBackendBuilder() + } + const val SEND_MESSAGE = "SEND_MESSAGE" + const val DELETE_MESSAGE = "DELETE_MESSAGE" + const val EDIT_MESSAGE = "EDIT_MESSAGE" + const val JOIN_ROOM = "JOIN_ROOM" + const val GET_USER_THREADS = "GET_USER_THREADS" + const val GET_CHAT_LOG = "GET_CHAT_LOG" + const val GET_CHAT_LOG_MORE = "GET_CHAT_LOG_MORE" + const val GET_USER_STATUS = "GET_USER_STATUS" + const val UPDATE_THREAD_STATUS = "UPDATE_THREAD_STATUS" + const val POST_SHARED = "POST_SHARED" + const val GET_NOTIFICATIONS = "GET_NOTIFICATIONS" + const val MARK_NOTIFICATIONS_AS_READ = "MARK_NOTIFICATIONS_AS_READ" + const val CLEAR_NOTIFICATION = "CLEAR_NOTIFICATION" + const val CLEAR_ALL_NOTIFICATIONS = "CLEAR_ALL_NOTIFICATIONS" + const val MESSAGE_RECEIVED = "MESSAGE_RECEIVED" + const val MESSAGE_DELETED = "MESSAGE_DELETED" + const val MESSAGE_EDITED = "MESSAGE_EDITED" + const val NEW_MESSAGE_NOTIFICATION = "NEW_MESSAGE_NOTIFICATION" + const val USER_STATUS_UPDATE = "USER_STATUS_UPDATE" + const val FORCE_ROOM_UPDATE = "FORCE_ROOM_UPDATE" + const val NEW_NOTIFICATION = "NEW_NOTIFICATION" + const val IDENTIFY = "IDENTIFY" + } +} + +class SocketComponentBackendBuilder { + private var _url : String = "" + private var _socket = IO.socket(_url) + private var _gson = Gson() + private var _eventBus = EventBus.getDefault() + private var _forceRoomUpdate : ((String) -> Unit)? = null + + fun setHTTPUrl(url : String) : SocketComponentBackendBuilder{ + _url = url + return this + } + + fun setSocket(s : Socket) : SocketComponentBackendBuilder{ + _socket = s + return this + } + + fun setGson(g : Gson) : SocketComponentBackendBuilder{ + _gson = g + return this + } + + fun setEventBus(ev : EventBus) : SocketComponentBackendBuilder{ + _eventBus = ev + return this + } + + fun createForceRoomUpdate(cb : (String) -> Unit){ + _forceRoomUpdate = cb + } + + fun build() : SocketComponentBackend{ + return SocketComponentBackend(_socket, _gson, _eventBus).apply { + if(_forceRoomUpdate != null){ + this.forceRoomUpdate = _forceRoomUpdate!! + } + } + } + +} \ No newline at end of file diff --git a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt new file mode 100644 index 00000000..8a6476b5 --- /dev/null +++ b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt @@ -0,0 +1,59 @@ +package com.fightpandemics.socketmanagerlib + +import com.google.gson.JsonElement + +//TODO("fill up the Object properties") +data class Message(val content : String? = null, val authorId : String? = null){ + val _id : String? = null +} + +data class wsCallBack(val onSuccess : (data : T) -> Unit, val onError : (Error?) -> Unit) +data class Notification(val _id : Long, + val action : String, + val contentText : String, + val isCleared : Boolean = false) +data class Response(val code : Int = 0, val data : JsonElement? = null, val message : String? = null) +data class Room(val topic : String? = null, + val lastMessage: Message? = null){ + val _id : String? = null +} +enum class wsEventsTypes{ + IDENTIFY_SUCCESS, + IDENTIFY_ERROR, + JOIN_ROOM_SUCCESS, + JOIN_ROOM_ERROR, + LEAVE_ALL_ROOMS, + GET_ROOMS_SUCCESS, + GET_ROOMS_ERROR, + MESSAGE_RECEIVED, + SET_LAST_MESSAGE, + MESSAGE_DELETED, + MESSAGE_EDITED, + GET_MESSAGES_HISTORY, + GET_MESSAGES_HISTORY_ERROR, + GET_MORE_MESSAGES_HISTORY, + USER_STATUS_UPDATE, + NEW_NOTIFICATION, + GET_NOTIFICATIONS_SUCCESS, + LOCAL_NOTIFICATIONS_MARK_AS_READ, + LOCAL_NOTIFICATION_MARK_AS_CLEARED, + CLEAR_ALL_LOCAL_NOTIFICATIONS +} +data class WSEvent(val action : wsEventsTypes, val payload : Any? = null) +data class LoadMore(val threadId: String? = null, val skip : Int = 0) +data class GetChatLog(val threadId : String? = null) +data class Participant(val id : String) +data class Thread(val participants : List){ + val _id : String? = null +} + +data class PostShared(val postId : String, val sharedVia : String) +data class UserStatusUpdate(val id : String? = null, val status : String? = null) +data class JoinRoom(val threadId : String? = null, val receiverId : String? = null) +data class WebSocketStateView( + val room : Room? = null, + val rooms : List = emptyList(), + val notification: List = emptyList(), + val chatLog: List = emptyList(), + val isIdentified : Boolean = false +) diff --git a/socketManagerLib/src/test/java/com/fightpandemics/socketmanagerlib/ExampleUnitTest.kt b/socketManagerLib/src/test/java/com/fightpandemics/socketmanagerlib/ExampleUnitTest.kt new file mode 100644 index 00000000..9290e2ae --- /dev/null +++ b/socketManagerLib/src/test/java/com/fightpandemics/socketmanagerlib/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.fightpandemics.socketmanagerlib + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file From 32de74b1834befd75c5e06642a6b22d2ca0cac99 Mon Sep 17 00:00:00 2001 From: zedonboy Date: Thu, 21 Jan 2021 23:33:09 +0100 Subject: [PATCH 2/2] Changed Generic Exception to Concrete Exception --- .../com/fightpandemics/socketmanagerlib/SocketComponent.kt | 6 +++--- .../java/com/fightpandemics/socketmanagerlib/wsTypes.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt index fee47b7f..7f00b3ca 100644 --- a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt +++ b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/SocketComponent.kt @@ -36,7 +36,7 @@ class SocketComponentBackend { * This property is a function that is in charge of a situation if a user is blocked * */ var forceRoomUpdate = fun(_: String){ - throw Exception("You must implement a forceUpdateListener. " + + throw UninitializedPropertyAccessException("You must implement a forceUpdateListener. " + ".forceRoomUpdate = ") } fun stop() { @@ -100,11 +100,11 @@ class SocketComponentBackend { }) } - fun deleteMessage(messageId : String, cb : wsCallBack? = null){ + fun deleteMessage(messageId : String){ _socket.emit(DELETE_MESSAGE, messageId) } - fun editMessage(data : Message, cb : wsCallBack? = null){ + fun editMessage(data : Message){ val jsonedMssg = _gson.toJson(data) _socket.emit(EDIT_MESSAGE, JSONObject(jsonedMssg)) } diff --git a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt index 8a6476b5..aec1fce3 100644 --- a/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt +++ b/socketManagerLib/src/main/java/com/fightpandemics/socketmanagerlib/wsTypes.kt @@ -2,7 +2,7 @@ package com.fightpandemics.socketmanagerlib import com.google.gson.JsonElement -//TODO("fill up the Object properties") +//TODO("fill up the Object properties from Backend Models") data class Message(val content : String? = null, val authorId : String? = null){ val _id : String? = null }