handlematrix: fix delete chat error messages
This commit is contained in:
@@ -1104,47 +1104,45 @@ func (t *TelegramClient) HandleMatrixDeleteChat(ctx context.Context, chat *bridg
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ids.PeerTypeChat:
|
case ids.PeerTypeChat:
|
||||||
if chat.Content.DeleteForEveryone {
|
if !chat.Content.DeleteForEveryone {
|
||||||
result, err := t.client.API().MessagesDeleteChat(ctx, id)
|
return fmt.Errorf("chats can only be deleted for everyone or left")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !result {
|
|
||||||
return fmt.Errorf("failed to delete chat %d", id)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("deleting chat only supported for group creators")
|
|
||||||
}
|
}
|
||||||
|
result, err := t.client.API().MessagesDeleteChat(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !result {
|
||||||
|
return fmt.Errorf("failed to delete chat %d", id)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
case ids.PeerTypeChannel:
|
case ids.PeerTypeChannel:
|
||||||
|
if !chat.Content.DeleteForEveryone {
|
||||||
|
return fmt.Errorf("channels can only be deleted for everyone or left")
|
||||||
|
}
|
||||||
accessHash, err := t.ScopedStore.GetAccessHash(ctx, peerType, id)
|
accessHash, err := t.ScopedStore.GetAccessHash(ctx, peerType, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if chat.Content.DeleteForEveryone {
|
if topicID > 0 {
|
||||||
if topicID > 0 {
|
_, err = t.client.API().MessagesDeleteTopicHistory(ctx, &tg.MessagesDeleteTopicHistoryRequest{
|
||||||
_, err = t.client.API().MessagesDeleteTopicHistory(ctx, &tg.MessagesDeleteTopicHistoryRequest{
|
Peer: &tg.InputPeerChannel{
|
||||||
Peer: &tg.InputPeerChannel{
|
|
||||||
ChannelID: id,
|
|
||||||
AccessHash: accessHash,
|
|
||||||
},
|
|
||||||
TopMsgID: topicID,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
_, err = t.client.API().ChannelsDeleteChannel(ctx, &tg.InputChannel{
|
|
||||||
ChannelID: id,
|
ChannelID: id,
|
||||||
AccessHash: accessHash,
|
AccessHash: accessHash,
|
||||||
})
|
},
|
||||||
}
|
TopMsgID: topicID,
|
||||||
if err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("deleting chat only supported for channel creators")
|
_, err = t.client.API().ChannelsDeleteChannel(ctx, &tg.InputChannel{
|
||||||
|
ChannelID: id,
|
||||||
|
AccessHash: accessHash,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("deleting chat not supported for peer type %s", peerType)
|
return fmt.Errorf("unknown peer type %s", peerType)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user