|
|
@ -350,10 +350,10 @@ func (c *Client) formatForward(fwd *client.MessageForwardInfo) string { |
|
|
|
return "Unknown forward type" |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) formatFile(file *client.File, compact bool) string { |
|
|
|
func (c *Client) formatFile(file *client.File, compact bool) (string, string) { |
|
|
|
log.Debugf("file: %#v", file) |
|
|
|
if file == nil || file.Local == nil || file.Remote == nil { |
|
|
|
return "" |
|
|
|
return "", "" |
|
|
|
} |
|
|
|
|
|
|
|
gateway.StorageLock.Lock() |
|
|
@ -367,7 +367,7 @@ func (c *Client) formatFile(file *client.File, compact bool) string { |
|
|
|
_, err := os.Stat(src) |
|
|
|
if err != nil { |
|
|
|
log.Errorf("Cannot access source file: %v", err) |
|
|
|
return "" |
|
|
|
return "", "" |
|
|
|
} |
|
|
|
|
|
|
|
size64 := uint64(file.Size) |
|
|
@ -385,7 +385,7 @@ func (c *Client) formatFile(file *client.File, compact bool) string { |
|
|
|
log.Warn(err.Error()) |
|
|
|
} else { |
|
|
|
log.Errorf("File moving error: %v", err) |
|
|
|
return "<ERROR>" |
|
|
|
return "<ERROR>", "" |
|
|
|
} |
|
|
|
} |
|
|
|
gateway.CachedStorageSize += size64 |
|
|
@ -410,9 +410,9 @@ func (c *Client) formatFile(file *client.File, compact bool) string { |
|
|
|
} |
|
|
|
|
|
|
|
if compact { |
|
|
|
return link |
|
|
|
return link, link |
|
|
|
} else { |
|
|
|
return fmt.Sprintf("%s (%v kbytes) | %s", filepath.Base(src), file.Size/1024, link) |
|
|
|
return fmt.Sprintf("%s (%v kbytes) | %s", filepath.Base(src), file.Size/1024, link), link |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -749,7 +749,7 @@ 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) { |
|
|
|
var text string |
|
|
|
var text, oob string |
|
|
|
content := message.Content |
|
|
|
if content != nil && content.MessageContentType() == client.TypeMessageChatChangePhoto { |
|
|
|
chat, err := c.client.GetChat(&client.GetChatRequest{ |
|
|
@ -772,7 +772,10 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) { |
|
|
|
preview = c.ensureDownloadFile(preview) |
|
|
|
|
|
|
|
var prefix strings.Builder |
|
|
|
prefix.WriteString(c.messageToPrefix(message, c.formatFile(preview, true), c.formatFile(file, false))) |
|
|
|
previewName, _ := c.formatFile(preview, true) |
|
|
|
fileName, link := c.formatFile(file, false) |
|
|
|
prefix.WriteString(c.messageToPrefix(message, previewName, fileName)) |
|
|
|
oob = link |
|
|
|
if text != "" { |
|
|
|
// \n if it is groupchat and message is not empty
|
|
|
|
if chatId < 0 { |
|
|
@ -786,6 +789,10 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) { |
|
|
|
|
|
|
|
text = prefix.String() |
|
|
|
} |
|
|
|
|
|
|
|
if c.Session.OOBMode && oob != "" { |
|
|
|
text = oob |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// mark message as read
|
|
|
@ -795,7 +802,7 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) { |
|
|
|
ForceRead: true, |
|
|
|
}) |
|
|
|
// forward message to XMPP
|
|
|
|
gateway.SendMessage(c.jid, strconv.FormatInt(chatId, 10), text, c.xmpp) |
|
|
|
gateway.SendMessageWithOOB(c.jid, strconv.FormatInt(chatId, 10), text, c.xmpp, oob) |
|
|
|
} |
|
|
|
|
|
|
|
// ProcessOutgoingMessage executes commands or sends messages to mapped chats
|
|
|
|