From 37db855170c1d27265dcbccf93b0b3da70f5142b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= <danxuliu@gmail.com>
Date: Mon, 24 Oct 2022 11:24:05 +0200
Subject: [PATCH] Use generic message rather than specific one for requesting
 offers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

"requestoffer" messages are compatible with the generic messages, so for
simplicity the generic message is used now instead of having specific
classes just for it.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
---
 .../RequestOfferOverallWebSocketMessage.kt    | 39 -------------------
 .../websocket/RequestOfferSignalingMessage.kt | 39 -------------------
 .../SignalingDataWebSocketMessageForOffer.kt  | 39 -------------------
 .../webrtc/WebSocketConnectionHelper.java     | 28 ++++---------
 4 files changed, 8 insertions(+), 137 deletions(-)
 delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferOverallWebSocketMessage.kt
 delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferSignalingMessage.kt
 delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/websocket/SignalingDataWebSocketMessageForOffer.kt

diff --git a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferOverallWebSocketMessage.kt b/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferOverallWebSocketMessage.kt
deleted file mode 100644
index deb11af47..000000000
--- a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferOverallWebSocketMessage.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Andy Scherzinger
- * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.nextcloud.talk.models.json.websocket
-
-import android.os.Parcelable
-import com.bluelinelabs.logansquare.annotation.JsonField
-import com.bluelinelabs.logansquare.annotation.JsonObject
-import kotlinx.android.parcel.Parcelize
-
-@Parcelize
-@JsonObject
-data class RequestOfferOverallWebSocketMessage(
-    @JsonField(name = ["type"])
-    var type: String? = null,
-    @JsonField(name = ["message"])
-    var requestOfferOverallWebSocketMessage: RequestOfferSignalingMessage? = null
-) : Parcelable {
-    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
-    constructor() : this(null, null)
-}
diff --git a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferSignalingMessage.kt b/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferSignalingMessage.kt
deleted file mode 100644
index d791cf7bd..000000000
--- a/app/src/main/java/com/nextcloud/talk/models/json/websocket/RequestOfferSignalingMessage.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Andy Scherzinger
- * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.nextcloud.talk.models.json.websocket
-
-import android.os.Parcelable
-import com.bluelinelabs.logansquare.annotation.JsonField
-import com.bluelinelabs.logansquare.annotation.JsonObject
-import kotlinx.android.parcel.Parcelize
-
-@Parcelize
-@JsonObject
-class RequestOfferSignalingMessage(
-    @JsonField(name = ["recipient"])
-    var actorWebSocketMessage: ActorWebSocketMessage? = null,
-    @JsonField(name = ["data"])
-    var signalingDataWebSocketMessageForOffer: SignalingDataWebSocketMessageForOffer? = null
-) : Parcelable {
-    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
-    constructor() : this(null, null)
-}
diff --git a/app/src/main/java/com/nextcloud/talk/models/json/websocket/SignalingDataWebSocketMessageForOffer.kt b/app/src/main/java/com/nextcloud/talk/models/json/websocket/SignalingDataWebSocketMessageForOffer.kt
deleted file mode 100644
index dbf2327fc..000000000
--- a/app/src/main/java/com/nextcloud/talk/models/json/websocket/SignalingDataWebSocketMessageForOffer.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Andy Scherzinger
- * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.nextcloud.talk.models.json.websocket
-
-import android.os.Parcelable
-import com.bluelinelabs.logansquare.annotation.JsonField
-import com.bluelinelabs.logansquare.annotation.JsonObject
-import kotlinx.android.parcel.Parcelize
-
-@Parcelize
-@JsonObject
-class SignalingDataWebSocketMessageForOffer(
-    @JsonField(name = ["type"])
-    var type: String? = null,
-    @JsonField(name = ["roomType"])
-    var roomType: String? = null
-) : Parcelable {
-    // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
-    constructor() : this(null, null)
-}
diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java
index e6ee105dc..41066e541 100644
--- a/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java
+++ b/app/src/main/java/com/nextcloud/talk/webrtc/WebSocketConnectionHelper.java
@@ -33,11 +33,8 @@ import com.nextcloud.talk.models.json.websocket.CallOverallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.CallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.HelloOverallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.HelloWebSocketMessage;
-import com.nextcloud.talk.models.json.websocket.RequestOfferOverallWebSocketMessage;
-import com.nextcloud.talk.models.json.websocket.RequestOfferSignalingMessage;
 import com.nextcloud.talk.models.json.websocket.RoomOverallWebSocketMessage;
 import com.nextcloud.talk.models.json.websocket.RoomWebSocketMessage;
-import com.nextcloud.talk.models.json.websocket.SignalingDataWebSocketMessageForOffer;
 import com.nextcloud.talk.utils.ApiUtils;
 
 import java.util.HashMap;
@@ -146,24 +143,15 @@ public class WebSocketConnectionHelper {
         return roomOverallWebSocketMessage;
     }
 
-    RequestOfferOverallWebSocketMessage getAssembledRequestOfferModel(String sessionId, String roomType) {
-        RequestOfferOverallWebSocketMessage requestOfferOverallWebSocketMessage = new RequestOfferOverallWebSocketMessage();
-        requestOfferOverallWebSocketMessage.setType("message");
+    CallOverallWebSocketMessage getAssembledRequestOfferModel(String sessionId, String roomType) {
+        NCSignalingMessage ncSignalingMessage = new NCSignalingMessage();
+        // "to" property is not actually needed in the "requestoffer" signaling message, but it is used to set the
+        // recipient session ID in the assembled call message.
+        ncSignalingMessage.setTo(sessionId);
+        ncSignalingMessage.setRoomType(roomType);
+        ncSignalingMessage.setType("requestoffer");
 
-        RequestOfferSignalingMessage requestOfferSignalingMessage = new RequestOfferSignalingMessage();
-
-        ActorWebSocketMessage actorWebSocketMessage = new ActorWebSocketMessage();
-        actorWebSocketMessage.setType("session");
-        actorWebSocketMessage.setSessionId(sessionId);
-        requestOfferSignalingMessage.setActorWebSocketMessage(actorWebSocketMessage);
-
-        SignalingDataWebSocketMessageForOffer signalingDataWebSocketMessageForOffer = new SignalingDataWebSocketMessageForOffer();
-        signalingDataWebSocketMessageForOffer.setRoomType(roomType);
-        signalingDataWebSocketMessageForOffer.setType("requestoffer");
-        requestOfferSignalingMessage.setSignalingDataWebSocketMessageForOffer(signalingDataWebSocketMessageForOffer);
-
-        requestOfferOverallWebSocketMessage.setRequestOfferOverallWebSocketMessage(requestOfferSignalingMessage);
-        return requestOfferOverallWebSocketMessage;
+        return getAssembledCallMessageModel(ncSignalingMessage);
     }
 
     CallOverallWebSocketMessage getAssembledCallMessageModel(NCSignalingMessage ncSignalingMessage) {