aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-19 03:13:00 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-19 03:13:00 +0300
commit0a2c4e09d9179108208461a58990f3397dad5a6c (patch)
treee437ddc32498c6ce424557e53353639c8ee4b1ef /telegram
parent22b46c71ce932cc97fa6d437a7473a653bb59a41 (diff)
Add `hideids` configuration option
Diffstat (limited to 'telegram')
-rw-r--r--telegram/utils.go57
1 files changed, 38 insertions, 19 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index 905a97b..9a247c4 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -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)