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

@ -57,6 +57,7 @@ func TestSessionToMap(t *testing.T) {
"asciiarrows": "false",
"oobmode": "true",
"carbons": "false",
"hideids": "false",
}
if !reflect.DeepEqual(m, sample) {
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) {
isPM, err := c.IsPM(message.ChatId)
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
}
var replyStart, replyEnd int
prefix := []string{}
// message direction
var directionChar string
if c.Session.AsciiArrows {
if message.IsOutgoing {
directionChar = "> "
} else {
directionChar = "< "
}
} else {
if message.IsOutgoing {
directionChar = "➡ "
if !isPM || !gateway.MessageOutgoingPermission || !c.Session.Carbons {
if c.Session.AsciiArrows {
if message.IsOutgoing {
directionChar = "> "
} else {
directionChar = "< "
}
} 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
if message.ChatId < 0 {
prefix = append(prefix, c.formatSender(message))
if !isPM {
sender := c.formatSender(message)
if sender != "" {
prefix = append(prefix, sender)
}
}
// reply to
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)
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 {
prefix = append(prefix, "fwd: "+c.formatForward(message.ForwardInfo))
@ -856,10 +873,12 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
if text != "" {
// \n if it is groupchat and message is not empty
if chatId < 0 {
newText.WriteString("\n")
} else if chatId > 0 {
newText.WriteString(" | ")
if prefix != "" {
if chatId < 0 {
newText.WriteString("\n")
} else if chatId > 0 {
newText.WriteString(" | ")
}
}
newText.WriteString(text)

Loading…
Cancel
Save