Add hideids
configuration option
This commit is contained in:
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,10 +746,16 @@ 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 !isPM || !gateway.MessageOutgoingPermission || !c.Session.Carbons {
|
||||||
if c.Session.AsciiArrows {
|
if c.Session.AsciiArrows {
|
||||||
if message.IsOutgoing {
|
if message.IsOutgoing {
|
||||||
directionChar = "> "
|
directionChar = "> "
|
||||||
|
@ -763,17 +769,28 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
|
||||||
directionChar = "⬅ "
|
directionChar = "⬅ "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if !isPM || !c.Session.HideIds {
|
||||||
prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10))
|
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 {
|
||||||
|
if len(prefix) > 0 {
|
||||||
replyStart = c.countCharsInLines(&prefix) + (len(prefix)-1)*len(messageHeaderSeparator)
|
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,11 +873,13 @@ 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 prefix != "" {
|
||||||
if chatId < 0 {
|
if chatId < 0 {
|
||||||
newText.WriteString("\n")
|
newText.WriteString("\n")
|
||||||
} else if chatId > 0 {
|
} else if chatId > 0 {
|
||||||
newText.WriteString(" | ")
|
newText.WriteString(" | ")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newText.WriteString(text)
|
newText.WriteString(text)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue