mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 12:17:06 +00:00
Merge branch 'master' into muc
This commit is contained in:
commit
1811f7622a
2 changed files with 18 additions and 8 deletions
|
|
@ -129,6 +129,8 @@ func NewMessageLimitSince(since int64) *MessageLimit {
|
||||||
return &limit
|
return &limit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AVATAR_SIZE_LIMIT int64 = 128 * 1024
|
||||||
|
|
||||||
// GetContactByUsername resolves username to user id retrieves user and chat information
|
// GetContactByUsername resolves username to user id retrieves user and chat information
|
||||||
func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.User, error) {
|
func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.User, error) {
|
||||||
if !c.Online() {
|
if !c.Online() {
|
||||||
|
|
@ -353,6 +355,12 @@ func (c *Client) getFileData(tgFile *client.File, typ byte) string {
|
||||||
priority = 32
|
priority = 32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avoid not-well-formed stanza errors
|
||||||
|
if typ == typeFileDataBase64 && c.GetPhotoSize(tgFile) > AVATAR_SIZE_LIMIT {
|
||||||
|
log.Warnf("Photo %v skipped as it's too huge", tgFile.Id)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
file, path, err := c.ForceOpenFile(tgFile, priority)
|
file, path, err := c.ForceOpenFile(tgFile, priority)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
@ -395,16 +403,16 @@ func (c *Client) SetEmptyAvatarHash(chatId int64) {
|
||||||
c.AvatarHashesLock.Unlock()
|
c.AvatarHashesLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhotoSha1AndSize obtains data for PEP
|
// GetPhotoSize return at least a rough size
|
||||||
func (c *Client) GetPhotoSha1AndSize(photo *client.File, chatId int64) (string, int64) {
|
func (c *Client) GetPhotoSize(photo *client.File) int64 {
|
||||||
sha1 := c.GetPhotoSha1(photo, chatId)
|
if photo == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
size := photo.Size
|
size := photo.Size
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
size = photo.ExpectedSize
|
size = photo.ExpectedSize
|
||||||
}
|
}
|
||||||
|
return size
|
||||||
return sha1, size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhotoSha1 computes the photo hash
|
// GetPhotoSha1 computes the photo hash
|
||||||
|
|
@ -1684,7 +1692,8 @@ func (c *Client) SendMessageToGateway(chatId int64, message *client.Message, id
|
||||||
if chat.Photo == nil {
|
if chat.Photo == nil {
|
||||||
c.SetEmptyAvatarHash(chatId)
|
c.SetEmptyAvatarHash(chatId)
|
||||||
} else {
|
} else {
|
||||||
sha1, size := c.GetPhotoSha1AndSize(chat.Photo.Small, chatId)
|
sha1 := c.GetPhotoSha1(chat.Photo.Small, chatId)
|
||||||
|
size := c.GetPhotoSize(chat.Photo.Small)
|
||||||
|
|
||||||
for resource := range c.resourcesRange() {
|
for resource := range c.resourcesRange() {
|
||||||
features, ok := c.XmppClientFeatures[resource]
|
features, ok := c.XmppClientFeatures[resource]
|
||||||
|
|
|
||||||
|
|
@ -1803,7 +1803,8 @@ func sendPubSubAvatarNotifications(s xmpp.Sender, jid string, session *telegram.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sha1, size := session.GetPhotoSha1AndSize(chat.Photo.Small, chat.Id)
|
sha1 := session.GetPhotoSha1(chat.Photo.Small, chat.Id)
|
||||||
|
size := session.GetPhotoSize(chat.Photo.Small)
|
||||||
|
|
||||||
gateway.SendPubSubAvatarNotification(component, jid, chat.Id, sha1, size)
|
gateway.SendPubSubAvatarNotification(component, jid, chat.Id, sha1, size)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue