mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 22:25:26 +00:00
implement channel password management at local and /pass command handling.
This commit is contained in:
@@ -285,8 +285,20 @@ class ChannelManager(
|
|||||||
state.setPasswordPromptChannel(null)
|
state.setPasswordPromptChannel(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setChannelPassword(channel: String, password: String): Boolean {
|
fun setChannelPassword(channel: String, password: String) {
|
||||||
return verifyChannelPassword(channel, password)
|
|
||||||
|
channelPasswords[channel] = password
|
||||||
|
|
||||||
|
channelKeys[channel] = deriveChannelKey(password, channel)
|
||||||
|
|
||||||
|
state.setPasswordProtectedChannels(
|
||||||
|
state.getPasswordProtectedChannelsValue().toMutableSet().apply { add(channel) }
|
||||||
|
)
|
||||||
|
|
||||||
|
dataManager.saveChannelData(
|
||||||
|
state.getJoinedChannelsValue(),
|
||||||
|
state.getPasswordProtectedChannelsValue()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Emergency Clear
|
// MARK: - Emergency Clear
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class CommandProcessor(
|
|||||||
"/m", "/msg" -> handleMessageCommand(parts, meshService)
|
"/m", "/msg" -> handleMessageCommand(parts, meshService)
|
||||||
"/w" -> handleWhoCommand()
|
"/w" -> handleWhoCommand()
|
||||||
"/clear" -> handleClearCommand()
|
"/clear" -> handleClearCommand()
|
||||||
|
"/pass" -> handlePassCommand(parts, myPeerID)
|
||||||
"/block" -> handleBlockCommand(parts, meshService)
|
"/block" -> handleBlockCommand(parts, meshService)
|
||||||
"/unblock" -> handleUnblockCommand(parts, meshService)
|
"/unblock" -> handleUnblockCommand(parts, meshService)
|
||||||
"/hug" -> handleActionCommand(parts, "gives", "a warm hug 🫂", meshService, myPeerID, onSendMessage)
|
"/hug" -> handleActionCommand(parts, "gives", "a warm hug 🫂", meshService, myPeerID, onSendMessage)
|
||||||
@@ -54,7 +55,8 @@ class CommandProcessor(
|
|||||||
if (parts.size > 1) {
|
if (parts.size > 1) {
|
||||||
val channelName = parts[1]
|
val channelName = parts[1]
|
||||||
val channel = if (channelName.startsWith("#")) channelName else "#$channelName"
|
val channel = if (channelName.startsWith("#")) channelName else "#$channelName"
|
||||||
val success = channelManager.joinChannel(channel, null, myPeerID)
|
val password = if (parts.size > 2) parts[2] else null
|
||||||
|
val success = channelManager.joinChannel(channel, password, myPeerID)
|
||||||
if (success) {
|
if (success) {
|
||||||
val systemMessage = BitchatMessage(
|
val systemMessage = BitchatMessage(
|
||||||
sender = "system",
|
sender = "system",
|
||||||
@@ -166,6 +168,52 @@ class CommandProcessor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handlePassCommand(parts: List<String>, peerID: String) {
|
||||||
|
val currentChannel = state.getCurrentChannelValue()
|
||||||
|
|
||||||
|
if (currentChannel == null) {
|
||||||
|
val systemMessage = BitchatMessage(
|
||||||
|
sender = "system",
|
||||||
|
content = "you must be in a channel to set a password.",
|
||||||
|
timestamp = Date(),
|
||||||
|
isRelay = false
|
||||||
|
)
|
||||||
|
messageManager.addMessage(systemMessage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.size == 2){
|
||||||
|
if(!channelManager.isChannelCreator(channel = currentChannel, peerID = peerID)){
|
||||||
|
val systemMessage = BitchatMessage(
|
||||||
|
sender = "system",
|
||||||
|
content = "you must be the channel creator to set a password.",
|
||||||
|
timestamp = Date(),
|
||||||
|
isRelay = false
|
||||||
|
)
|
||||||
|
channelManager.addChannelMessage(currentChannel,systemMessage,null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val newPassword = parts[1]
|
||||||
|
channelManager.setChannelPassword(currentChannel, newPassword)
|
||||||
|
val systemMessage = BitchatMessage(
|
||||||
|
sender = "system",
|
||||||
|
content = "password changed for channel $currentChannel",
|
||||||
|
timestamp = Date(),
|
||||||
|
isRelay = false
|
||||||
|
)
|
||||||
|
channelManager.addChannelMessage(currentChannel,systemMessage,null)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
val systemMessage = BitchatMessage(
|
||||||
|
sender = "system",
|
||||||
|
content = "usage: /pass <password>",
|
||||||
|
timestamp = Date(),
|
||||||
|
isRelay = false
|
||||||
|
)
|
||||||
|
channelManager.addChannelMessage(currentChannel,systemMessage,null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleBlockCommand(parts: List<String>, meshService: Any) {
|
private fun handleBlockCommand(parts: List<String>, meshService: Any) {
|
||||||
if (parts.size > 1) {
|
if (parts.size > 1) {
|
||||||
val targetName = parts[1].removePrefix("@")
|
val targetName = parts[1].removePrefix("@")
|
||||||
|
|||||||
Reference in New Issue
Block a user