handlematrix: Implement DeleteChatHandlingNetworkAPI (#122)
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/util/variationselector"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
"maunium.net/go/mautrix/bridgev2/database"
|
||||
"maunium.net/go/mautrix/event"
|
||||
)
|
||||
|
||||
@@ -57,7 +58,7 @@ func (tg *TelegramConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilit
|
||||
}
|
||||
|
||||
func (tg *TelegramConnector) GetBridgeInfoVersion() (info, capabilities int) {
|
||||
return 1, 5
|
||||
return 1, 6
|
||||
}
|
||||
|
||||
// TODO get these from getConfig instead of hardcoding?
|
||||
@@ -207,7 +208,7 @@ func makeTimerList() []jsontime.Milliseconds {
|
||||
var telegramTimers = makeTimerList()
|
||||
|
||||
func (t *TelegramClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures {
|
||||
baseID := "fi.mau.telegram.capabilities.2025_09_16"
|
||||
baseID := "fi.mau.telegram.capabilities.2025_09_27"
|
||||
feat := &event.RoomFeatures{
|
||||
Formatting: formattingCaps,
|
||||
File: fileCaps,
|
||||
@@ -250,6 +251,11 @@ func (t *TelegramClient) GetCapabilities(ctx context.Context, portal *bridgev2.P
|
||||
feat.File = premiumFileCaps
|
||||
feat.ReactionCount = 3
|
||||
}
|
||||
if portal.RoomType == database.RoomTypeDM {
|
||||
baseID += "+dm"
|
||||
feat.DeleteChat = true
|
||||
feat.DeleteChatForEveryone = true
|
||||
}
|
||||
feat.ID = baseID
|
||||
return feat
|
||||
}
|
||||
|
||||
@@ -741,3 +741,30 @@ func (t *TelegramClient) senderForUserID(userID int64) bridgev2.EventSender {
|
||||
Sender: ids.MakeUserID(userID),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TelegramClient) HandleMatrixDeleteChat(ctx context.Context, chat *bridgev2.MatrixDeleteChat) error {
|
||||
peerType, id, err := ids.ParsePortalID(chat.Portal.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch peerType {
|
||||
case ids.PeerTypeUser:
|
||||
if chat.Content.DeleteForEveryone {
|
||||
_, err := t.client.API().MessagesDeleteHistory(ctx, &tg.MessagesDeleteHistoryRequest{
|
||||
Peer: &tg.InputPeerUser{UserID: id},
|
||||
Revoke: true,
|
||||
MaxID: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = t.client.API().MessagesDeleteChat(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("deleting chat not supported for peer type %s", peerType)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ var (
|
||||
_ bridgev2.MuteHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||
_ bridgev2.TagHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||
_ bridgev2.ChatViewingNetworkAPI = (*TelegramClient)(nil)
|
||||
_ bridgev2.DeleteChatHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||
)
|
||||
|
||||
func getMediaFilename(content *event.MessageEventContent) (filename string) {
|
||||
|
||||
Reference in New Issue
Block a user