Synchronize muted channel state
This commit is contained in:
committed by
Brandon McGinty
parent
118799d112
commit
20c6997ab0
+26
-11
@@ -53,8 +53,9 @@ type Barnard struct {
|
||||
exitMessage string
|
||||
|
||||
// Added for channel muting
|
||||
MutedChannels map[uint32]bool
|
||||
userChannels map[uint32]*gumble.Channel
|
||||
MutedChannels map[uint32]bool
|
||||
MutedChannelsMutex sync.RWMutex
|
||||
userChannels map[uint32]*gumble.Channel
|
||||
|
||||
// Added for noise suppression
|
||||
NoiseSuppressor *noise.Suppressor
|
||||
@@ -116,6 +117,25 @@ func (b *Barnard) updateUserGain(user *gumble.User) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Barnard) isChannelMuted(channelID uint32) bool {
|
||||
b.MutedChannelsMutex.RLock()
|
||||
defer b.MutedChannelsMutex.RUnlock()
|
||||
return b.MutedChannels[channelID]
|
||||
}
|
||||
|
||||
func (b *Barnard) setChannelMuted(channelID uint32, muted bool) {
|
||||
b.MutedChannelsMutex.Lock()
|
||||
defer b.MutedChannelsMutex.Unlock()
|
||||
if b.MutedChannels == nil {
|
||||
b.MutedChannels = make(map[uint32]bool)
|
||||
}
|
||||
if muted {
|
||||
b.MutedChannels[channelID] = true
|
||||
} else {
|
||||
delete(b.MutedChannels, channelID)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Barnard) StopTransmission() {
|
||||
if b.Tx {
|
||||
b.Notify("micdown", "me", "")
|
||||
@@ -159,7 +179,7 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
|
||||
if treeItem.Channel != nil {
|
||||
if key == *b.Hotkeys.MuteToggle {
|
||||
// Determine new channel mute state
|
||||
channelWillBeMuted := !b.MutedChannels[treeItem.Channel.ID]
|
||||
channelWillBeMuted := !b.isChannelMuted(treeItem.Channel.ID)
|
||||
|
||||
// Set all users in channel to the same mute state
|
||||
users := makeUsersArray(treeItem.Channel.Users)
|
||||
@@ -175,14 +195,9 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
|
||||
}
|
||||
|
||||
// Update channel mute state
|
||||
if channelWillBeMuted {
|
||||
b.MutedChannels[treeItem.Channel.ID] = true
|
||||
// If this is the current channel, stop transmission
|
||||
if b.Client.Self.Channel.ID == treeItem.Channel.ID && b.Tx {
|
||||
b.StopTransmission()
|
||||
}
|
||||
} else {
|
||||
delete(b.MutedChannels, treeItem.Channel.ID)
|
||||
b.setChannelMuted(treeItem.Channel.ID, channelWillBeMuted)
|
||||
if channelWillBeMuted && b.Client.Self.Channel.ID == treeItem.Channel.ID && b.Tx {
|
||||
b.StopTransmission()
|
||||
}
|
||||
|
||||
b.RebuildUserChannelTreePreservingSelection()
|
||||
|
||||
Reference in New Issue
Block a user