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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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