3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

fix Client.historyStatus

This commit is contained in:
Shivaram Lingamneni 2020-02-20 02:06:13 -05:00
parent 8f4c14c783
commit 17a89838b8
3 changed files with 17 additions and 11 deletions

View File

@ -353,7 +353,7 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string)
} }
func (client *Client) resizeHistory(config *Config) { func (client *Client) resizeHistory(config *Config) {
_, ephemeral := client.historyStatus(config) _, ephemeral, _ := client.historyStatus(config)
if ephemeral { if ephemeral {
client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow) client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow)
} else { } else {
@ -756,7 +756,7 @@ func (session *Session) playResume() {
} }
} }
} }
_, cEphemeral := client.historyStatus(config) _, cEphemeral, _ := client.historyStatus(config)
if cEphemeral { if cEphemeral {
lastDiscarded := client.history.LastDiscarded() lastDiscarded := client.history.LastDiscarded()
if oldestLostMessage.Before(lastDiscarded) { if oldestLostMessage.Before(lastDiscarded) {
@ -1543,20 +1543,23 @@ func (client *Client) attemptAutoOper(session *Session) {
} }
} }
func (client *Client) historyStatus(config *Config) (persistent, ephemeral bool) { func (client *Client) historyStatus(config *Config) (persistent, ephemeral bool, target string) {
if !config.History.Enabled { if !config.History.Enabled {
return false, false return
} else if !config.History.Persistent.Enabled { } else if !config.History.Persistent.Enabled {
return false, true ephemeral = true
return
} }
client.stateMutex.RLock() client.stateMutex.RLock()
alwaysOn := client.alwaysOn alwaysOn := client.alwaysOn
historyStatus := client.accountSettings.DMHistory historyStatus := client.accountSettings.DMHistory
target = client.nickCasefolded
client.stateMutex.RUnlock() client.stateMutex.RUnlock()
if !alwaysOn { if !alwaysOn {
return false, true ephemeral = true
return
} }
historyStatus = historyEnabled(config.History.Persistent.DirectMessages, historyStatus) historyStatus = historyEnabled(config.History.Persistent.DirectMessages, historyStatus)

View File

@ -1975,8 +1975,8 @@ func dispatchMessageToTarget(client *Client, tags map[string]string, histType hi
} }
targetedItem := item targetedItem := item
targetedItem.Params[0] = tnick targetedItem.Params[0] = tnick
cPersistent, cEphemeral := client.historyStatus(config) cPersistent, cEphemeral, _ := client.historyStatus(config)
tPersistent, tEphemeral := user.historyStatus(config) tPersistent, tEphemeral, _ := user.historyStatus(config)
// add to ephemeral history // add to ephemeral history
if cEphemeral { if cEphemeral {
targetedItem.CfCorrespondent = tDetails.nickCasefolded targetedItem.CfCorrespondent = tDetails.nickCasefolded

View File

@ -867,10 +867,13 @@ func (server *Server) GetHistorySequence(providedChannel *Channel, client *Clien
var sender, recipient string var sender, recipient string
var hist *history.Buffer var hist *history.Buffer
if target == "*" { if target == "*" {
if client.AlwaysOn() { persistent, ephemeral, target := client.historyStatus(config)
recipient = client.NickCasefolded() if persistent {
} else { recipient = target
} else if ephemeral {
hist = &client.history hist = &client.history
} else {
return
} }
} else { } else {
channel = providedChannel channel = providedChannel