Carbons in group chats

This commit is contained in:
Bohdan Horbeshko 2023-08-02 13:53:34 -04:00
parent 8fc9edd7e7
commit 3c917c1698
2 changed files with 9 additions and 11 deletions

View file

@ -15,7 +15,7 @@ import (
goxmpp "gosrc.io/xmpp" goxmpp "gosrc.io/xmpp"
) )
var version string = "1.7.2" var version string = "1.8.0-dev"
var commit string var commit string
var sm *goxmpp.StreamManager var sm *goxmpp.StreamManager

View file

@ -837,12 +837,15 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
if err != nil { if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err) 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 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 !hideSender {
if c.Session.AsciiArrows { if c.Session.AsciiArrows {
if message.IsOutgoing { if message.IsOutgoing {
directionChar = "> " directionChar = "> "
@ -861,7 +864,7 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
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 !isPM { if !hideSender {
sender := c.formatSender(message) sender := c.formatSender(message)
if sender != "" { if sender != "" {
prefix = append(prefix, 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 // 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) { func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message, ignoredResource string) {
var isPM bool var isCarbon bool
var err error isOutgoing := message.IsOutgoing
if gateway.MessageOutgoingPermission && c.Session.Carbons { if gateway.MessageOutgoingPermission && c.Session.Carbons {
isPM, err = c.IsPM(chatId) isCarbon = isOutgoing
if err != nil {
log.Errorf("Could not determine if chat is PM: %v", err)
}
} }
isOutgoing := message.IsOutgoing
isCarbon := isPM && isOutgoing
jids := c.getCarbonFullJids(isOutgoing, ignoredResource) jids := c.getCarbonFullJids(isOutgoing, ignoredResource)
if len(jids) == 0 { if len(jids) == 0 {
log.Info("The only resource is ignored, aborting") log.Info("The only resource is ignored, aborting")