mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
commit
c4e66d8b83
@ -1331,11 +1331,35 @@ const (
|
|||||||
BouncerAllowedByUser
|
BouncerAllowedByUser
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// controls whether/when clients without event-playback support see fake
|
||||||
|
// PRIVMSGs for JOINs
|
||||||
|
type ReplayJoinsSetting uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
ReplayJoinsCommandsOnly = iota // replay in HISTORY or CHATHISTORY output
|
||||||
|
ReplayJoinsAlways // replay in HISTORY, CHATHISTORY, or autoreplay
|
||||||
|
ReplayJoinsNever // never replay
|
||||||
|
)
|
||||||
|
|
||||||
|
func replayJoinsSettingFromString(str string) (result ReplayJoinsSetting, err error) {
|
||||||
|
switch strings.ToLower(str) {
|
||||||
|
case "commands-only":
|
||||||
|
result = ReplayJoinsCommandsOnly
|
||||||
|
case "always":
|
||||||
|
result = ReplayJoinsAlways
|
||||||
|
case "never":
|
||||||
|
result = ReplayJoinsNever
|
||||||
|
default:
|
||||||
|
err = errInvalidParams
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type AccountSettings struct {
|
type AccountSettings struct {
|
||||||
AutoreplayLines *int
|
AutoreplayLines *int
|
||||||
NickEnforcement NickEnforcementMethod
|
NickEnforcement NickEnforcementMethod
|
||||||
AllowBouncer BouncerAllowedSetting
|
AllowBouncer BouncerAllowedSetting
|
||||||
AutoreplayJoins bool
|
ReplayJoins ReplayJoinsSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientAccount represents a user account.
|
// ClientAccount represents a user account.
|
||||||
|
@ -786,15 +786,26 @@ func stripMaskFromNick(nickMask string) (nick string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
|
func (channel *Channel) replayHistoryItems(rb *ResponseBuffer, items []history.Item, autoreplay bool) {
|
||||||
|
if len(items) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
chname := channel.Name()
|
chname := channel.Name()
|
||||||
client := rb.target
|
client := rb.target
|
||||||
eventPlayback := rb.session.capabilities.Has(caps.EventPlayback)
|
eventPlayback := rb.session.capabilities.Has(caps.EventPlayback)
|
||||||
extendedJoin := rb.session.capabilities.Has(caps.ExtendedJoin)
|
extendedJoin := rb.session.capabilities.Has(caps.ExtendedJoin)
|
||||||
playJoinsAsPrivmsg := (!autoreplay || client.AccountSettings().AutoreplayJoins)
|
var playJoinsAsPrivmsg bool
|
||||||
|
if !eventPlayback {
|
||||||
if len(items) == 0 {
|
switch client.AccountSettings().ReplayJoins {
|
||||||
return
|
case ReplayJoinsCommandsOnly:
|
||||||
|
playJoinsAsPrivmsg = !autoreplay
|
||||||
|
case ReplayJoinsAlways:
|
||||||
|
playJoinsAsPrivmsg = true
|
||||||
|
case ReplayJoinsNever:
|
||||||
|
playJoinsAsPrivmsg = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batchID := rb.StartNestedHistoryBatch(chname)
|
batchID := rb.StartNestedHistoryBatch(chname)
|
||||||
defer rb.EndNestedBatch(batchID)
|
defer rb.EndNestedBatch(batchID)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ const (
|
|||||||
// 'version' of the database schema
|
// 'version' of the database schema
|
||||||
keySchemaVersion = "db.version"
|
keySchemaVersion = "db.version"
|
||||||
// latest schema of the db
|
// latest schema of the db
|
||||||
latestDbSchema = "7"
|
latestDbSchema = "8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SchemaChanger func(*Config, *buntdb.Tx) error
|
type SchemaChanger func(*Config, *buntdb.Tx) error
|
||||||
@ -500,6 +500,59 @@ func schemaChangeV6ToV7(config *Config, tx *buntdb.Tx) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type accountSettingsLegacyV7 struct {
|
||||||
|
AutoreplayLines *int
|
||||||
|
NickEnforcement NickEnforcementMethod
|
||||||
|
AllowBouncer BouncerAllowedSetting
|
||||||
|
AutoreplayJoins bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type accountSettingsLegacyV8 struct {
|
||||||
|
AutoreplayLines *int
|
||||||
|
NickEnforcement NickEnforcementMethod
|
||||||
|
AllowBouncer BouncerAllowedSetting
|
||||||
|
ReplayJoins ReplayJoinsSetting
|
||||||
|
}
|
||||||
|
|
||||||
|
// #616: change autoreplay-joins to replay-joins
|
||||||
|
func schemaChangeV7ToV8(config *Config, tx *buntdb.Tx) error {
|
||||||
|
prefix := "account.settings "
|
||||||
|
var accounts, blobs []string
|
||||||
|
tx.AscendGreaterOrEqual("", prefix, func(key, value string) bool {
|
||||||
|
var legacy accountSettingsLegacyV7
|
||||||
|
var current accountSettingsLegacyV8
|
||||||
|
if !strings.HasPrefix(key, prefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
account := strings.TrimPrefix(key, prefix)
|
||||||
|
err := json.Unmarshal([]byte(value), &legacy)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("corrupt record for %s: %v\n", account, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
current.AutoreplayLines = legacy.AutoreplayLines
|
||||||
|
current.NickEnforcement = legacy.NickEnforcement
|
||||||
|
current.AllowBouncer = legacy.AllowBouncer
|
||||||
|
if legacy.AutoreplayJoins {
|
||||||
|
current.ReplayJoins = ReplayJoinsAlways
|
||||||
|
} else {
|
||||||
|
current.ReplayJoins = ReplayJoinsCommandsOnly
|
||||||
|
}
|
||||||
|
blob, err := json.Marshal(current)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("could not marshal record for %s: %v\n", account, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
accounts = append(accounts, account)
|
||||||
|
blobs = append(blobs, string(blob))
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
for i, account := range accounts {
|
||||||
|
tx.Set(prefix+account, blobs[i], nil)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
allChanges := []SchemaChange{
|
allChanges := []SchemaChange{
|
||||||
{
|
{
|
||||||
@ -532,6 +585,11 @@ func init() {
|
|||||||
TargetVersion: "7",
|
TargetVersion: "7",
|
||||||
Changer: schemaChangeV6ToV7,
|
Changer: schemaChangeV6ToV7,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
InitialVersion: "7",
|
||||||
|
TargetVersion: "8",
|
||||||
|
Changer: schemaChangeV7ToV8,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the index
|
// build the index
|
||||||
|
@ -237,10 +237,12 @@ be replayed to you automatically when joining a channel. Your options are any
|
|||||||
positive number, 0 to disable the feature, and 'default' to use the server
|
positive number, 0 to disable the feature, and 'default' to use the server
|
||||||
default.`,
|
default.`,
|
||||||
|
|
||||||
`$bAUTOREPLAY-JOINS$b
|
`$bREPLAY-JOINS$b
|
||||||
'autoreplay-joins' controls whether autoreplayed channel history will include
|
'replay-joins' controls whether replayed channel history will include
|
||||||
lines for join and part. This provides more information about the context of
|
lines for join and part. This provides more information about the context of
|
||||||
messages, but may be spammy. Your options are 'on' and 'off'.`,
|
messages, but may be spammy. Your options are 'always', 'never', and the default
|
||||||
|
of 'commands-only' (the messages will be replayed in /HISTORY output, but not
|
||||||
|
during autoreplay).`,
|
||||||
},
|
},
|
||||||
authRequired: true,
|
authRequired: true,
|
||||||
enabled: servCmdRequiresAccreg,
|
enabled: servCmdRequiresAccreg,
|
||||||
@ -303,11 +305,14 @@ func displaySetting(settingName string, settings AccountSettings, client *Client
|
|||||||
} else {
|
} else {
|
||||||
nsNotice(rb, fmt.Sprintf(client.t("You will receive %d lines of autoreplayed history"), *settings.AutoreplayLines))
|
nsNotice(rb, fmt.Sprintf(client.t("You will receive %d lines of autoreplayed history"), *settings.AutoreplayLines))
|
||||||
}
|
}
|
||||||
case "autoreplay-joins":
|
case "replay-joins":
|
||||||
if settings.AutoreplayJoins {
|
switch settings.ReplayJoins {
|
||||||
nsNotice(rb, client.t("You will see JOINs and PARTs in autoreplayed history lines"))
|
case ReplayJoinsCommandsOnly:
|
||||||
} else {
|
nsNotice(rb, client.t("You will see JOINs and PARTs in /HISTORY output, but not in autoreplay"))
|
||||||
nsNotice(rb, client.t("You will not see JOINs and PARTs in autoreplayed history lines"))
|
case ReplayJoinsAlways:
|
||||||
|
nsNotice(rb, client.t("You will see JOINs and PARTs in /HISTORY output and in autoreplay"))
|
||||||
|
case ReplayJoinsNever:
|
||||||
|
nsNotice(rb, client.t("You will not see JOINs and PARTs in /HISTORY output or in autoreplay"))
|
||||||
}
|
}
|
||||||
case "bouncer":
|
case "bouncer":
|
||||||
if !config.Accounts.Bouncer.Enabled {
|
if !config.Accounts.Bouncer.Enabled {
|
||||||
@ -396,13 +401,13 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "autoreplay-joins":
|
case "replay-joins":
|
||||||
var newValue bool
|
var newValue ReplayJoinsSetting
|
||||||
newValue, err = utils.StringToBool(params[1])
|
newValue, err = replayJoinsSettingFromString(params[1])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
munger = func(in AccountSettings) (out AccountSettings, err error) {
|
munger = func(in AccountSettings) (out AccountSettings, err error) {
|
||||||
out = in
|
out = in
|
||||||
out.AutoreplayJoins = newValue
|
out.ReplayJoins = newValue
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user