Update authorization state

This commit is contained in:
c0re100 2022-09-18 09:49:37 +08:00
parent 3b10777734
commit 65692be746
No known key found for this signature in database
GPG key ID: 7C3B3004FE745AAF
7 changed files with 18 additions and 30 deletions

View file

@ -46,7 +46,7 @@ func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandl
} }
type clientAuthorizer struct { type clientAuthorizer struct {
TdlibParameters chan *TdlibParameters TdlibParameters chan *SetTdlibParametersRequest
PhoneNumber chan string PhoneNumber chan string
Code chan string Code chan string
State chan AuthorizationState State chan AuthorizationState
@ -55,7 +55,7 @@ type clientAuthorizer struct {
func ClientAuthorizer() *clientAuthorizer { func ClientAuthorizer() *clientAuthorizer {
return &clientAuthorizer{ return &clientAuthorizer{
TdlibParameters: make(chan *TdlibParameters, 1), TdlibParameters: make(chan *SetTdlibParametersRequest, 1),
PhoneNumber: make(chan string, 1), PhoneNumber: make(chan string, 1),
Code: make(chan string, 1), Code: make(chan string, 1),
State: make(chan AuthorizationState, 10), State: make(chan AuthorizationState, 10),
@ -68,13 +68,7 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
switch state.AuthorizationStateType() { switch state.AuthorizationStateType() {
case TypeAuthorizationStateWaitTdlibParameters: case TypeAuthorizationStateWaitTdlibParameters:
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{ _, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters)
Parameters: <-stateHandler.TdlibParameters,
})
return err
case TypeAuthorizationStateWaitEncryptionKey:
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
return err return err
case TypeAuthorizationStateWaitPhoneNumber: case TypeAuthorizationStateWaitPhoneNumber:
@ -169,14 +163,14 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
} }
type botAuthorizer struct { type botAuthorizer struct {
TdlibParameters chan *TdlibParameters TdlibParameters chan *SetTdlibParametersRequest
Token chan string Token chan string
State chan AuthorizationState State chan AuthorizationState
} }
func BotAuthorizer(token string) *botAuthorizer { func BotAuthorizer(token string) *botAuthorizer {
botAuthorizer := &botAuthorizer{ botAuthorizer := &botAuthorizer{
TdlibParameters: make(chan *TdlibParameters, 1), TdlibParameters: make(chan *SetTdlibParametersRequest, 1),
Token: make(chan string, 1), Token: make(chan string, 1),
State: make(chan AuthorizationState, 10), State: make(chan AuthorizationState, 10),
} }
@ -191,13 +185,7 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
switch state.AuthorizationStateType() { switch state.AuthorizationStateType() {
case TypeAuthorizationStateWaitTdlibParameters: case TypeAuthorizationStateWaitTdlibParameters:
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{ _, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters)
Parameters: <-stateHandler.TdlibParameters,
})
return err
case TypeAuthorizationStateWaitEncryptionKey:
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
return err return err
case TypeAuthorizationStateWaitPhoneNumber: case TypeAuthorizationStateWaitPhoneNumber:

View file

@ -9,8 +9,8 @@ import (
tdlib "github.com/c0re100/gotdlib/client" tdlib "github.com/c0re100/gotdlib/client"
) )
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",

View file

@ -17,8 +17,8 @@ func GetSenderId(sender tdlib.MessageSender) int64 {
} }
} }
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",

View file

@ -17,8 +17,8 @@ func GetSenderId(sender tdlib.MessageSender) int64 {
} }
} }
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",

View file

@ -17,8 +17,8 @@ func GetSenderId(sender tdlib.MessageSender) int64 {
} }
} }
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",

View file

@ -9,8 +9,8 @@ import (
tdlib "github.com/c0re100/gotdlib/client" tdlib "github.com/c0re100/gotdlib/client"
) )
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",

View file

@ -17,8 +17,8 @@ func GetSenderId(sender tdlib.MessageSender) int64 {
} }
} }
func GetTdParameters() *tdlib.TdlibParameters { func GetTdParameters() *tdlib.SetTdlibParametersRequest {
return &tdlib.TdlibParameters{ return &tdlib.SetTdlibParametersRequest{
UseTestDc: false, UseTestDc: false,
DatabaseDirectory: "./tdlib-db", DatabaseDirectory: "./tdlib-db",
FilesDirectory: "./tdlib-files", FilesDirectory: "./tdlib-files",