Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ class ConversationInfoActivity : BaseActivity() {
this,
user.baseUrl,
state.conversationToken,
state.conversation?.name,
CapabilitiesUtil.canGeneratePrettyURL(user)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,6 @@ class ConversationsListActivity : BaseActivity() {
this,
currentUser?.baseUrl,
conversation.token,
conversation.name,
canGeneratePrettyURL
)
}
Expand Down
48 changes: 19 additions & 29 deletions app/src/main/java/com/nextcloud/talk/utils/ShareUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
*/
package com.nextcloud.talk.utils

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import androidx.annotation.VisibleForTesting
import androidx.core.net.toUri
import com.nextcloud.talk.R

object ShareUtils {

@SuppressLint("StringFormatMatches")
fun shareConversationLink(
context: Activity,
baseUrl: String?,
roomToken: String?,
conversationName: String?,
canGeneratePrettyURL: Boolean
) {
if (baseUrl.isNullOrBlank() || roomToken.isNullOrBlank() || conversationName.isNullOrBlank()) {
return
fun shareConversationLink(context: Activity, baseUrl: String?, roomToken: String?, canGeneratePrettyURL: Boolean) {
val conversationLink = buildConversationLink(baseUrl, roomToken, canGeneratePrettyURL) ?: return

val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, conversationLink)
type = "text/plain"
}

val shareIntent = Intent.createChooser(sendIntent, context.getString(R.string.nc_share_link))
context.startActivity(shareIntent)
}

@VisibleForTesting
fun buildConversationLink(baseUrl: String?, roomToken: String?, canGeneratePrettyURL: Boolean): String? {
if (baseUrl.isNullOrBlank() || roomToken.isNullOrBlank()) {
return null
}

val uriBuilder = baseUrl.toUri()
Expand All @@ -36,23 +43,6 @@ object ShareUtils {
uriBuilder.appendPath("call")
uriBuilder.appendPath(roomToken)

val uriToShareConversation = uriBuilder.build()

val shareConversationLink = String.format(
context.getString(
R.string.share_link_to_conversation,
conversationName,
uriToShareConversation.toString()
)
)

val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, shareConversationLink)
type = "text/plain"
}

val shareIntent = Intent.createChooser(sendIntent, context.getString(R.string.nc_share_link))
context.startActivity(shareIntent)
return uriBuilder.build().toString()
}
}
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ How to translate with transifex:
<string name="nc_edit_icon">Edit</string>
<string name="get_invitations_error">Failed to fetch pending invitations</string>
<string name="message_last_edited_by">Edited by %1$s</string>
<string name="share_link_to_conversation">Join conversation %1$s at %2$s</string>
<string name="nc_conversation_settings">Conversation settings</string>
<string name="ban_participant">Ban participant</string>
<string name="show_banned_participants">Show banned participants</string>
Expand Down
56 changes: 56 additions & 0 deletions app/src/test/java/com/nextcloud/talk/utils/ShareUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.utils

import android.app.Application
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(application = Application::class, sdk = [33])
class ShareUtilsTest {

@Test
fun `builds pretty URL when capability is available`() {
val link = ShareUtils.buildConversationLink(BASE_URL, ROOM_TOKEN, canGeneratePrettyURL = true)
assertEquals("$BASE_URL/call/$ROOM_TOKEN", link)
}

@Test
fun `builds index_php URL when pretty URL capability is missing`() {
val link = ShareUtils.buildConversationLink(BASE_URL, ROOM_TOKEN, canGeneratePrettyURL = false)
assertEquals("$BASE_URL/index.php/call/$ROOM_TOKEN", link)
}

@Test
fun `link is the bare URL with no extra text`() {
val link = ShareUtils.buildConversationLink(BASE_URL, ROOM_TOKEN, canGeneratePrettyURL = true)
// The shared text must be only the URL — no "Join conversation … at …" wrapper.
assertEquals("$BASE_URL/call/$ROOM_TOKEN", link)
}

@Test
fun `returns null when baseUrl is blank`() {
assertNull(ShareUtils.buildConversationLink("", ROOM_TOKEN, canGeneratePrettyURL = true))
assertNull(ShareUtils.buildConversationLink(null, ROOM_TOKEN, canGeneratePrettyURL = true))
}

@Test
fun `returns null when roomToken is blank`() {
assertNull(ShareUtils.buildConversationLink(BASE_URL, "", canGeneratePrettyURL = true))
assertNull(ShareUtils.buildConversationLink(BASE_URL, null, canGeneratePrettyURL = true))
}

companion object {
private const val BASE_URL = "https://server.example.com"
private const val ROOM_TOKEN = "abc123"
}
}
Loading