Add `hideids` configuration option

calls
Bohdan Horbeshko 1 year ago
parent 22b46c71ce
commit 0a2c4e09d9

@ -41,6 +41,7 @@ type Session struct {
AsciiArrows bool `yaml:":asciiarrows"` AsciiArrows bool `yaml:":asciiarrows"`
OOBMode bool `yaml:":oobmode"` OOBMode bool `yaml:":oobmode"`
Carbons bool `yaml:":carbons"` Carbons bool `yaml:":carbons"`
HideIds bool `yaml:":hideids"`
} }
var configKeys = []string{ var configKeys = []string{
@ -50,6 +51,7 @@ var configKeys = []string{
"asciiarrows", "asciiarrows",
"oobmode", "oobmode",
"carbons", "carbons",
"hideids",
} }
var sessionDB *SessionsYamlDB var sessionDB *SessionsYamlDB
@ -126,6 +128,8 @@ func (s *Session) Get(key string) (string, error) {
return fromBool(s.OOBMode), nil return fromBool(s.OOBMode), nil
case "carbons": case "carbons":
return fromBool(s.Carbons), nil return fromBool(s.Carbons), nil
case "hideids":
return fromBool(s.HideIds), nil
} }
return "", errors.New("Unknown session property") return "", errors.New("Unknown session property")
@ -183,6 +187,13 @@ func (s *Session) Set(key string, value string) (string, error) {
} }
s.Carbons = b s.Carbons = b
return value, nil return value, nil
case "hideids":
b, err := toBool(value)
if err != nil {
return "", err
}
s.HideIds = b
return value, nil
} }
return "", errors.New("Unknown session property") return "", errors.New("Unknown session property")

@ -57,6 +57,7 @@ func TestSessionToMap(t *testing.T) {
"asciiarrows": "false", "asciiarrows": "false",
"oobmode": "true", "oobmode": "true",
"carbons": "false", "carbons": "false",
"hideids": "false",
} }
if !reflect.DeepEqual(m, sample) { if !reflect.DeepEqual(m, sample) {
t.Errorf("Map does not match the sample: %v", m) t.Errorf("Map does not match the sample: %v", m)

@ -746,34 +746,51 @@ func (c *Client) countCharsInLines(lines *[]string) (count int) {
} }
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, replyMsg *client.Message) (string, int, int) { func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, replyMsg *client.Message) (string, int, int) {
isPM, err := c.IsPM(message.ChatId)
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
}
var replyStart, replyEnd int var replyStart, replyEnd int
prefix := []string{} prefix := []string{}
// message direction // message direction
var directionChar string var directionChar string
if c.Session.AsciiArrows { if !isPM || !gateway.MessageOutgoingPermission || !c.Session.Carbons {
if message.IsOutgoing { if c.Session.AsciiArrows {
directionChar = "> " if message.IsOutgoing {
} else { directionChar = "> "
directionChar = "< " } else {
} directionChar = "< "
} else { }
if message.IsOutgoing {
directionChar = "➡ "
} else { } else {
directionChar = "⬅ " if message.IsOutgoing {
directionChar = "➡ "
} else {
directionChar = "⬅ "
}
} }
} }
prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10)) if !isPM || !c.Session.HideIds {
prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10))
}
// show sender in group chats // show sender in group chats
if message.ChatId < 0 { if !isPM {
prefix = append(prefix, c.formatSender(message)) sender := c.formatSender(message)
if sender != "" {
prefix = append(prefix, sender)
}
} }
// reply to // reply to
if message.ReplyToMessageId != 0 { if message.ReplyToMessageId != 0 {
replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator) if len(prefix) > 0 {
replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator)
}
replyLine := "reply: " + c.formatMessage(message.ChatId, message.ReplyToMessageId, true, replyMsg) replyLine := "reply: " + c.formatMessage(message.ChatId, message.ReplyToMessageId, true, replyMsg)
prefix = append(prefix, replyLine) prefix = append(prefix, replyLine)
replyEnd = replyStart + len(replyLine) + len(messageHeaderSeparator) replyEnd = replyStart + len(replyLine)
if len(prefix) > 0 {
replyEnd += len(messageHeaderSeparator)
}
} }
if message.ForwardInfo != nil { if message.ForwardInfo != nil {
prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo)) prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo))
@ -856,10 +873,12 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
if text != "" { if text != "" {
// \n if it is groupchat and message is not empty // \n if it is groupchat and message is not empty
if chatId < 0 { if prefix != "" {
newText.WriteString("\n") if chatId < 0 {
} else if chatId > 0 { newText.WriteString("\n")
newText.WriteString(" | ") } else if chatId > 0 {
newText.WriteString(" | ")
}
} }
newText.WriteString(text) newText.WriteString(text)

Loading…
Cancel
Save