edits: bridge TG -> Matrix
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -13,18 +13,20 @@ import (
|
||||
// The format of the media ID is as follows (each character represents a single
|
||||
// byte, |'s added for clarity):
|
||||
//
|
||||
// v|p|cccccccc|mmmmmmmm|T
|
||||
// v|p|cccccccc|mmmmmmmm|T|MMMMMMMM
|
||||
//
|
||||
// v (int8) = binary encoding format version. Should be 0.
|
||||
// p (byte) = the peer type of the Telegram chat ID
|
||||
// cccccccc (int64) = the Telegram chat ID (big endian)
|
||||
// mmmmmmmm (int64) = the Telegram message ID (big endian)
|
||||
// T (byte) = 0 or 1 depending on whether it's a thumbnail
|
||||
// T (byte) = 0 or 1 depending on whether it's a thumbnail (optional)
|
||||
// MMMMMMMM (int64) = the Telegram media ID (big endian) (optional)
|
||||
type DirectMediaInfo struct {
|
||||
PeerType PeerType
|
||||
ChatID int64
|
||||
MessageID int64
|
||||
Thumbnail bool
|
||||
PeerType PeerType
|
||||
ChatID int64
|
||||
MessageID int64
|
||||
Thumbnail bool
|
||||
TelegramMediaID int64
|
||||
}
|
||||
|
||||
func (m DirectMediaInfo) AsMediaID() (networkid.MediaID, error) {
|
||||
@@ -39,6 +41,7 @@ func (m DirectMediaInfo) AsMediaID() (networkid.MediaID, error) {
|
||||
} else {
|
||||
mediaID = append(mediaID, 0x00)
|
||||
}
|
||||
mediaID = binary.BigEndian.AppendUint64(mediaID, uint64(m.TelegramMediaID)) // Telegram Message ID
|
||||
return mediaID, nil
|
||||
}
|
||||
|
||||
@@ -51,7 +54,10 @@ func ParseDirectMediaInfo(mediaID networkid.MediaID) (info DirectMediaInfo, err
|
||||
err = fmt.Errorf("invalid version %d", mediaID[0])
|
||||
return
|
||||
}
|
||||
if len(mediaID) != 18 && len(mediaID) != 19 {
|
||||
|
||||
// For compatibility with old media IDs that don't have the thumbnail flag
|
||||
// and the Telegram media ID, we allow media IDs with 18, 19, or 27 bytes.
|
||||
if len(mediaID) != 18 && len(mediaID) != 19 && len(mediaID) != 27 {
|
||||
err = fmt.Errorf("invalid media ID")
|
||||
return
|
||||
}
|
||||
@@ -61,8 +67,11 @@ func ParseDirectMediaInfo(mediaID networkid.MediaID) (info DirectMediaInfo, err
|
||||
}
|
||||
info.ChatID = int64(binary.BigEndian.Uint64(mediaID[2:]))
|
||||
info.MessageID = int64(binary.BigEndian.Uint64(mediaID[10:]))
|
||||
if len(mediaID) == 19 {
|
||||
if len(mediaID) >= 19 {
|
||||
info.Thumbnail = mediaID[18] == 1
|
||||
}
|
||||
if len(mediaID) >= 20 {
|
||||
info.TelegramMediaID = int64(binary.BigEndian.Uint64(mediaID[19:]))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user