From 3c917c16983c1afdd4a21d8021461585a1e785c9 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Wed, 2 Aug 2023 13:53:34 -0400 Subject: [PATCH] Carbons in group chats --- telegabber.go | 2 +- telegram/utils.go | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/telegabber.go b/telegabber.go index 9ce070f..671e13b 100644 --- a/telegabber.go +++ b/telegabber.go @@ -15,7 +15,7 @@ import ( goxmpp "gosrc.io/xmpp" ) -var version string = "1.7.2" +var version string = "1.8.0-dev" var commit string var sm *goxmpp.StreamManager diff --git a/telegram/utils.go b/telegram/utils.go index cd25c22..a91c6da 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -837,12 +837,15 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string, if err != nil { log.Errorf("Could not determine if chat is PM: %v", err) } + isCarbonsEnabled := gateway.MessageOutgoingPermission && c.Session.Carbons + // with carbons, hide for all messages in PM and only for outgoing in group chats + hideSender := isCarbonsEnabled && (message.IsOutgoing || isPM) var replyStart, replyEnd int prefix := []string{} // message direction var directionChar string - if !isPM || !gateway.MessageOutgoingPermission || !c.Session.Carbons { + if !hideSender { if c.Session.AsciiArrows { if message.IsOutgoing { directionChar = "> " @@ -861,7 +864,7 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string, prefix = append(prefix, directionChar+strconv.FormatInt(message.Id, 10)) } // show sender in group chats - if !isPM { + if !hideSender { sender := c.formatSender(message) if sender != "" { prefix = append(prefix, sender) @@ -912,17 +915,12 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File { // ProcessIncomingMessage transfers a message to XMPP side and marks it as read on Telegram side func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message, ignoredResource string) { - var isPM bool - var err error + var isCarbon bool + isOutgoing := message.IsOutgoing if gateway.MessageOutgoingPermission && c.Session.Carbons { - isPM, err = c.IsPM(chatId) - if err != nil { - log.Errorf("Could not determine if chat is PM: %v", err) - } + isCarbon = isOutgoing } - isOutgoing := message.IsOutgoing - isCarbon := isPM && isOutgoing jids := c.getCarbonFullJids(isOutgoing, ignoredResource) if len(jids) == 0 { log.Info("The only resource is ignored, aborting")