push: enable push encryption key
[skip cd]
This commit is contained in:
@@ -188,6 +188,8 @@ type UserLoginMetadata struct {
|
||||
TakeoutDialogCrawlCursor networkid.PortalID `json:"takeout_portal_crawl_cursor,omitempty"`
|
||||
|
||||
PinnedDialogs []networkid.PortalID `json:"pinned_dialogs,omitempty"`
|
||||
|
||||
PushEncryptionKey []byte `json:"push_encryption_key,omitempty"`
|
||||
}
|
||||
|
||||
func (s *UserLoginSession) Load(_ context.Context) (*session.Data, error) {
|
||||
|
||||
+11
-2
@@ -5,12 +5,21 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gotd/td/tg"
|
||||
"go.mau.fi/util/random"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
)
|
||||
|
||||
var _ bridgev2.PushableNetworkAPI = (*TelegramClient)(nil)
|
||||
|
||||
func (t *TelegramClient) RegisterPushNotifications(ctx context.Context, pushType bridgev2.PushType, token string) error {
|
||||
meta := t.userLogin.Metadata.(*UserLoginMetadata)
|
||||
if meta.PushEncryptionKey == nil {
|
||||
meta.PushEncryptionKey = random.Bytes(256)
|
||||
err := t.userLogin.Save(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to save push encryption key: %w", err)
|
||||
}
|
||||
}
|
||||
var tokenType int
|
||||
switch pushType {
|
||||
case bridgev2.PushTypeWeb:
|
||||
@@ -27,12 +36,12 @@ func (t *TelegramClient) RegisterPushNotifications(ctx context.Context, pushType
|
||||
TokenType: tokenType,
|
||||
Token: token,
|
||||
AppSandbox: false,
|
||||
Secret: nil,
|
||||
Secret: meta.PushEncryptionKey,
|
||||
OtherUIDs: nil, // TODO set properly
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *TelegramClient) GetPushConfigs() *bridgev2.PushConfig {
|
||||
return &bridgev2.PushConfig{}
|
||||
return &bridgev2.PushConfig{Native: true}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user