myTeamSpeak: import TeamSpeak 6 contacts; bookmark myTeamSpeak switch
TeamSpeak 6 syncs chat contacts as item class 8 (Item_Data field 25). They are imported as friends keyed by myTeamSpeak ID, taken from the item or from the partner's chat ID (@<base32 id>:<homeserver>), the same bytes servers report as base64 client_myteamspeak_id. The contact list matches them to clients through the ID each client carries. Bookmarks gain TeamSpeak's "Enable myTeamSpeak features" switch (send_mytsid_on_server), stored and imported but not yet sent; what is still missing is noted in docs/myteamspeak/myteamspeak_server_signin.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -438,7 +438,7 @@ class SessionController(private val context: Context) {
|
||||
|
||||
/** The account the app stays signed in to; its reads block, so they run on [Dispatchers.IO]. */
|
||||
val myTeamSpeak: MyTeamSpeakLogin = MyTeamSpeakLogin.load()
|
||||
private val importer = TeamSpeakImporter(identityStore, bookmarkStore, settings)
|
||||
private val importer = TeamSpeakImporter(identityStore, bookmarkStore, settings, contactStore)
|
||||
|
||||
private val _myTeamSpeakSignedIn = MutableStateFlow(myTeamSpeak.isSignedIn)
|
||||
val myTeamSpeakSignedIn: StateFlow<Boolean> = _myTeamSpeakSignedIn
|
||||
@@ -504,7 +504,7 @@ class SessionController(private val context: Context) {
|
||||
|
||||
fun isImported(item: SyncItem): Boolean = importer.isPresent(item)
|
||||
|
||||
/** Imports [chosen] out of the account's [all] items, with the identities the chosen bookmarks use. */
|
||||
/** Imports [chosen] out of the account's [all] items, with the identities the chosen bookmarks use; contacts announce themselves. */
|
||||
suspend fun importMyTeamSpeak(all: List<SyncItem>, chosen: List<SyncItem>): TeamSpeakImporter.Result =
|
||||
withContext(Dispatchers.IO) { importer.importSelected(all, chosen) }
|
||||
.also {
|
||||
|
||||
@@ -42,7 +42,8 @@ val BookmarkEditSaver = listSaver<BookmarkEdit?, Any>(
|
||||
save = { edit ->
|
||||
val b = edit?.bookmark ?: return@listSaver emptyList()
|
||||
listOf(edit.index, b.label.orEmpty(), b.address.orEmpty(), b.port, b.nickname.orEmpty(), b.password,
|
||||
b.identityId, b.channel, b.channelPassword, b.connectOnStartup, b.iconId, b.id)
|
||||
b.identityId, b.channel, b.channelPassword, b.connectOnStartup, b.iconId, b.id,
|
||||
b.myTeamSpeakFeatures)
|
||||
},
|
||||
restore = { saved ->
|
||||
if (saved.isEmpty()) null
|
||||
@@ -54,6 +55,7 @@ val BookmarkEditSaver = listSaver<BookmarkEdit?, Any>(
|
||||
connectOnStartup = saved[9] as Boolean
|
||||
iconId = saved[10] as Long
|
||||
id = saved[11] as String
|
||||
myTeamSpeakFeatures = saved[12] as Boolean
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -73,6 +75,7 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
|
||||
var channel by rememberSaveable { mutableStateOf(b.channel.orEmpty()) }
|
||||
var channelPassword by rememberSaveable { mutableStateOf(b.channelPassword.orEmpty()) }
|
||||
var connectOnStartup by rememberSaveable { mutableStateOf(b.connectOnStartup) }
|
||||
var myTeamSpeakFeatures by rememberSaveable { mutableStateOf(b.myTeamSpeakFeatures) }
|
||||
|
||||
val save = {
|
||||
val (host, port) = SessionController.parseAddress(address)
|
||||
@@ -86,6 +89,7 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
|
||||
it.channel = channel.trim()
|
||||
it.channelPassword = channelPassword
|
||||
it.connectOnStartup = connectOnStartup
|
||||
it.myTeamSpeakFeatures = myTeamSpeakFeatures
|
||||
})
|
||||
onDone()
|
||||
}
|
||||
@@ -120,6 +124,11 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
|
||||
Text("Connect on startup", Modifier.weight(1f))
|
||||
Switch(connectOnStartup, { connectOnStartup = it })
|
||||
}
|
||||
Row(Modifier.fillMaxWidth().clickable { myTeamSpeakFeatures = !myTeamSpeakFeatures },
|
||||
verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("Enable myTeamSpeak features", Modifier.weight(1f))
|
||||
Switch(myTeamSpeakFeatures, { myTeamSpeakFeatures = it })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,11 +117,11 @@ fun ContactsScreen(vm: SessionController, editing: String?, onEdit: (String?) ->
|
||||
val group = contacts.filter { it.type == type }.sortedBy { label(it).lowercase() }
|
||||
if (group.isEmpty()) continue
|
||||
item(key = type) { Section(title) }
|
||||
items(group, key = { it.uniqueId }) { contact ->
|
||||
items(group, key = { it.key() }) { contact ->
|
||||
ListItem(
|
||||
headlineContent = { Text(label(contact), color = typeColor(contact.type)) },
|
||||
supportingContent = { Text(lastSeen(contact)) },
|
||||
modifier = Modifier.clickable { onEdit(contact.uniqueId) },
|
||||
modifier = Modifier.clickable { onEdit(contact.key()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -133,14 +133,16 @@ fun ContactsScreen(vm: SessionController, editing: String?, onEdit: (String?) ->
|
||||
@Composable
|
||||
private fun ContactScreen(vm: SessionController, uniqueId: String, onBack: () -> Unit) {
|
||||
val contacts by vm.contacts.collectAsStateWithLifecycle()
|
||||
val contact = contacts.firstOrNull { it.uniqueId == uniqueId }
|
||||
// A client's unique id may stand for a contact filed under its myTeamSpeak ID.
|
||||
val key = remember(uniqueId) { vm.contact(uniqueId)?.key() ?: uniqueId }
|
||||
val contact = contacts.firstOrNull { it.key() == key }
|
||||
if (contact == null) {
|
||||
LaunchedEffect(Unit) { onBack() }
|
||||
return
|
||||
}
|
||||
// Starts from the stored entry, which may have been seen again since this page opened.
|
||||
fun edit(change: Contact.() -> Unit) {
|
||||
vm.contact(uniqueId)?.let { vm.saveContact(it.apply(change)) }
|
||||
vm.contact(key)?.let { vm.saveContact(it.apply(change)) }
|
||||
}
|
||||
var customName by rememberSaveable(uniqueId) { mutableStateOf(contact.nickname) }
|
||||
var phoneticName by rememberSaveable(uniqueId) { mutableStateOf(contact.phoneticNickname) }
|
||||
@@ -191,10 +193,11 @@ private fun ContactScreen(vm: SessionController, uniqueId: String, onBack: () ->
|
||||
|
||||
Section("Details")
|
||||
val context = LocalContext.current
|
||||
LinkRow("Unique ID", contact.uniqueId) {
|
||||
val idLabel = if (contact.uniqueId.isEmpty()) "myTeamSpeak ID" else "Unique ID"
|
||||
LinkRow(idLabel, contact.shownId()) {
|
||||
// The system confirms the copy itself.
|
||||
context.getSystemService(ClipboardManager::class.java)
|
||||
.setPrimaryClip(ClipData.newPlainText("Unique ID", contact.uniqueId))
|
||||
.setPrimaryClip(ClipData.newPlainText(idLabel, contact.shownId()))
|
||||
}
|
||||
ListItem(headlineContent = { Text(lastSeen(contact)) })
|
||||
}
|
||||
@@ -208,7 +211,7 @@ private fun ContactScreen(vm: SessionController, uniqueId: String, onBack: () ->
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
removing = false
|
||||
vm.removeContact(uniqueId)
|
||||
vm.removeContact(key)
|
||||
onBack()
|
||||
}) { Text("Remove") }
|
||||
},
|
||||
@@ -251,7 +254,7 @@ private fun ContactDefaultsScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun label(contact: Contact) = contact.nickname.ifBlank { contact.uniqueId }
|
||||
private fun label(contact: Contact) = contact.label()
|
||||
|
||||
private fun lastSeen(contact: Contact): String {
|
||||
val seen = contact.lastSeen ?: return "Never seen"
|
||||
|
||||
@@ -48,6 +48,7 @@ import eu.lixko.ts3j.client.myts.AccountInfo
|
||||
import eu.lixko.ts3j.client.myts.MyTeamSpeak
|
||||
import eu.lixko.ts3j.client.myts.MyTsException
|
||||
import eu.lixko.ts3j.client.teamspeak.SyncItem
|
||||
import eu.lixko.ts3j.client.teamspeak.TeamSpeakImporter
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.IOException
|
||||
import java.time.ZoneId
|
||||
@@ -79,11 +80,11 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
fun show(account: MyTeamSpeak.Account) {
|
||||
info = account.info()
|
||||
all = account.items()
|
||||
rows = all.filter { it !is SyncItem.Folder }.map {
|
||||
rows = all.filter { it !is SyncItem.Folder && (it !is SyncItem.Contact || TeamSpeakImporter.isImportable(it)) }.map {
|
||||
val imported = vm.isImported(it)
|
||||
ItemRow(it, imported, !imported)
|
||||
}
|
||||
message = if (rows.isEmpty()) "The account holds no bookmarks or identities." else null
|
||||
message = if (rows.isEmpty()) "The account holds no bookmarks, identities or contacts." else null
|
||||
error = false
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
if (!signedIn) {
|
||||
item {
|
||||
Column(Modifier.padding(horizontal = 16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("Sign in to bring over the bookmarks and identities your account synchronises. " +
|
||||
Text("Sign in to bring over the bookmarks, identities and contacts your account synchronises. " +
|
||||
"The app stays signed in; your password itself is not kept.")
|
||||
OutlinedTextField(email, { email = it }, Modifier.fillMaxWidth(), label = { Text("Email") },
|
||||
singleLine = true, enabled = !busy,
|
||||
@@ -189,6 +190,7 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
for ((title, section) in listOf(
|
||||
"Identities" to rows.filter { it.item is SyncItem.Identity },
|
||||
"Bookmarks" to rows.filter { it.item is SyncItem.Bookmark },
|
||||
"Contacts" to rows.filter { it.item is SyncItem.Contact },
|
||||
)) {
|
||||
if (section.isEmpty()) continue
|
||||
item {
|
||||
@@ -219,8 +221,9 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
work {
|
||||
val r = vm.importMyTeamSpeak(all, rows.filter { it.selected }.map { it.item })
|
||||
rows = rows.map { it.copy(imported = vm.isImported(it.item), selected = false) }
|
||||
message = "Imported ${count(r.identitiesAdded(), "identity", "identities")} and " +
|
||||
"${count(r.bookmarksAdded(), "bookmark", "bookmarks")}."
|
||||
message = "Imported ${count(r.identitiesAdded(), "identity", "identities")}, " +
|
||||
"${count(r.bookmarksAdded(), "bookmark", "bookmarks")} and " +
|
||||
"${count(r.contactsAdded(), "contact", "contacts")}."
|
||||
}
|
||||
},
|
||||
enabled = !busy && rows.any { it.selected },
|
||||
@@ -253,12 +256,14 @@ private fun Detail(label: String, value: String) {
|
||||
private fun name(item: SyncItem) = when (item) {
|
||||
is SyncItem.Bookmark -> item.name().ifBlank { item.address() }
|
||||
is SyncItem.Identity -> item.name()
|
||||
is SyncItem.Contact -> item.customName().ifBlank { item.myTeamSpeakId() }
|
||||
else -> ""
|
||||
}
|
||||
|
||||
private fun details(item: SyncItem) = when (item) {
|
||||
is SyncItem.Bookmark -> Bookmark.hostPort(item.address(), item.port())
|
||||
is SyncItem.Identity -> item.nickname()
|
||||
is SyncItem.Contact -> item.myTeamSpeakId()
|
||||
else -> ""
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
||||
"IDENTITY_MANAGER") { page = SettingsPage.IDENTITIES }
|
||||
LinkRow("myTeamSpeak",
|
||||
if (vm.myTeamSpeak.isSignedIn) "Signed in as ${vm.myTeamSpeak.username()}"
|
||||
else "Sign in to bring over your synchronised bookmarks and identities",
|
||||
else "Sign in to bring over your synchronised bookmarks, identities and contacts",
|
||||
"MYTS_ACCOUNT") { page = SettingsPage.MY_TEAMSPEAK }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user