mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
Ping XEP-0363 link back for files uploaded in MUCs
This commit is contained in:
parent
cf2183e9ca
commit
ade944a9d6
3 changed files with 46 additions and 0 deletions
|
|
@ -148,6 +148,8 @@ type Client struct {
|
||||||
|
|
||||||
mucCache map[int64]*MUCState
|
mucCache map[int64]*MUCState
|
||||||
|
|
||||||
|
uploadingFiles map[int32]string
|
||||||
|
|
||||||
LastBotCmdString string
|
LastBotCmdString string
|
||||||
|
|
||||||
XmppClientFeatures map[string]*[]string
|
XmppClientFeatures map[string]*[]string
|
||||||
|
|
@ -174,6 +176,7 @@ type clientLocks struct {
|
||||||
lastMsgHashesLock sync.Mutex
|
lastMsgHashesLock sync.Mutex
|
||||||
lastMsgIdsLock sync.RWMutex
|
lastMsgIdsLock sync.RWMutex
|
||||||
loginFinish barrier
|
loginFinish barrier
|
||||||
|
uploadingFilesLock sync.Mutex
|
||||||
|
|
||||||
authorizerReadLock sync.Mutex
|
authorizerReadLock sync.Mutex
|
||||||
authorizerWriteLock sync.Mutex
|
authorizerWriteLock sync.Mutex
|
||||||
|
|
@ -243,6 +246,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
|
||||||
editOutbox: make(map[string]string),
|
editOutbox: make(map[string]string),
|
||||||
pinOutbox: make(map[IntPair]chan int64),
|
pinOutbox: make(map[IntPair]chan int64),
|
||||||
mucCache: make(map[int64]*MUCState),
|
mucCache: make(map[int64]*MUCState),
|
||||||
|
uploadingFiles: make(map[int32]string),
|
||||||
options: options,
|
options: options,
|
||||||
DelayedStatuses: make(map[int64]*DelayedStatus),
|
DelayedStatuses: make(map[int64]*DelayedStatus),
|
||||||
lastMsgHashes: make(map[int64]uint64),
|
lastMsgHashes: make(map[int64]uint64),
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,9 @@ func (c *Client) updateHandler() {
|
||||||
case client.TypeUpdateChatPermissions:
|
case client.TypeUpdateChatPermissions:
|
||||||
typedUpdate, _ := update.(*client.UpdateChatPermissions)
|
typedUpdate, _ := update.(*client.UpdateChatPermissions)
|
||||||
c.updateChatPermissions(typedUpdate)
|
c.updateChatPermissions(typedUpdate)
|
||||||
|
case client.TypeUpdateFile:
|
||||||
|
typedUpdate, _ := update.(*client.UpdateFile)
|
||||||
|
c.updateFile(typedUpdate)
|
||||||
default:
|
default:
|
||||||
// log only handled types
|
// log only handled types
|
||||||
continue
|
continue
|
||||||
|
|
@ -613,6 +616,21 @@ func (c *Client) updateChatPermissions(update *client.UpdateChatPermissions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) updateFile(update *client.UpdateFile) {
|
||||||
|
if update.File != nil && update.File.Local != nil {
|
||||||
|
// not really needed, why did I even write this then lol (TODO: maybe clean by some heur anyway)
|
||||||
|
/* c.locks.uploadingFilesLock.Lock()
|
||||||
|
if _, ok := c.uploadingFiles[update.File.Id]; ok && update.File.Local.CanBeDeleted && update.File.Local.Path != "" {
|
||||||
|
err := os.Remove(update.File.Local.Path)
|
||||||
|
if err != nil {
|
||||||
|
log.Warningf("Couldn't delete uploaded file: %v", err.Error())
|
||||||
|
}
|
||||||
|
delete(c.uploadingFiles, update.File.Id)
|
||||||
|
}
|
||||||
|
c.locks.uploadingFilesLock.Unlock() */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) tryUnlockMessageId(chatId, messageId int64) {
|
func (c *Client) tryUnlockMessageId(chatId, messageId int64) {
|
||||||
c.MessageIdChangesLock.Lock()
|
c.MessageIdChangesLock.Lock()
|
||||||
idsMap, ok := c.MessageIdChanges[chatId]
|
idsMap, ok := c.MessageIdChanges[chatId]
|
||||||
|
|
|
||||||
|
|
@ -1280,6 +1280,7 @@ func (c *Client) formatFile(file *client.File, compact bool) (string, string) {
|
||||||
if file == nil {
|
if file == nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
log.Debugf("formatFile: %v %#v %#v", c.jid, file.Local, file.Remote)
|
||||||
src, link := c.PermastoreFile(file, false)
|
src, link := c.PermastoreFile(file, false)
|
||||||
|
|
||||||
if compact {
|
if compact {
|
||||||
|
|
@ -1313,6 +1314,16 @@ func (c *Client) PermastoreFile(file *client.File, clone bool) (string, string)
|
||||||
size64 := uint64(file.Size)
|
size64 := uint64(file.Size)
|
||||||
c.prepareDiskSpace(size64)
|
c.prepareDiskSpace(size64)
|
||||||
|
|
||||||
|
// detect uploading files, there's no remote id for them yet
|
||||||
|
c.locks.uploadingFilesLock.Lock()
|
||||||
|
var ok bool
|
||||||
|
link, ok = c.uploadingFiles[file.Id]
|
||||||
|
if ok && !file.Local.CanBeDeleted {
|
||||||
|
defer c.locks.uploadingFilesLock.Unlock()
|
||||||
|
return src, link
|
||||||
|
}
|
||||||
|
c.locks.uploadingFilesLock.Unlock()
|
||||||
|
|
||||||
basename := file.Remote.UniqueId + filepath.Ext(src)
|
basename := file.Remote.UniqueId + filepath.Ext(src)
|
||||||
dest := c.content.Path + "/" + basename // destination path
|
dest := c.content.Path + "/" + basename // destination path
|
||||||
link = c.content.Link + "/" + basename // download link
|
link = c.content.Link + "/" + basename // download link
|
||||||
|
|
@ -1792,6 +1803,8 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
|
||||||
newFile, err := c.DownloadFile(file.Id, 1, true)
|
newFile, err := c.DownloadFile(file.Id, 1, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return newFile
|
return newFile
|
||||||
|
} else {
|
||||||
|
log.Errorf("Couldn't force-download file: %v", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2113,6 +2126,7 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
|
||||||
|
|
||||||
// attach a file
|
// attach a file
|
||||||
var file *client.InputFileLocal
|
var file *client.InputFileLocal
|
||||||
|
link := text
|
||||||
if c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) {
|
if c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) {
|
||||||
response, err := http.Get(text)
|
response, err := http.Get(text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -2183,6 +2197,16 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, returnJid str
|
||||||
c.returnError(returnJid, chatID, "Not sent", err, 400, isGroupchat)
|
c.returnError(returnJid, chatID, "Not sent", err, 400, isGroupchat)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if file != nil {
|
||||||
|
document, ok := tgMessage.Content.(*client.MessageDocument)
|
||||||
|
if ok && document.Document != nil && document.Document.Document != nil {
|
||||||
|
c.locks.uploadingFilesLock.Lock()
|
||||||
|
c.uploadingFiles[document.Document.Document.Id] = link
|
||||||
|
c.locks.uploadingFilesLock.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tgMessage, false
|
return tgMessage, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue