Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

删除 SyncReloadDataLoginOption #248

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (b *Bot) HotLogin(storage HotReloadStorage, opts ...BotLoginOption) error {
hotLogin := &HotLogin{storage: storage}
// 进行相关设置。
// 如果相对默认的行为进行修改,在opts里面进行追加即可。
b.loginOptionGroup = append(hotLoginDefaultOptions[:], opts...)
b.loginOptionGroup = opts
return b.login(hotLogin)
}

Expand All @@ -106,7 +106,7 @@ func (b *Bot) PushLogin(storage HotReloadStorage, opts ...BotLoginOption) error
pushLogin := &PushLogin{storage: storage}
// 进行相关设置。
// 如果相对默认的行为进行修改,在opts里面进行追加即可。
b.loginOptionGroup = append(pushLoginDefaultOptions[:], opts...)
b.loginOptionGroup = opts
return b.login(pushLogin)
}

Expand Down
45 changes: 0 additions & 45 deletions bot_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package openwechat

import (
"context"
"time"
)

// LoginCode 定义登录状态码
Expand Down Expand Up @@ -112,27 +111,6 @@ func NewRetryLoginOption() BotLoginOption {
return &RetryLoginOption{MaxRetryCount: 1}
}

// SyncReloadDataLoginOption 在登录成功后进行数据定时同步到指定的storage中
type SyncReloadDataLoginOption struct {
BaseBotLoginOption
SyncLoopDuration time.Duration
}

// OnSuccess 实现了 BotLoginOption 接口
// 当登录成功后,会调用此方法进行数据定时同步到指定的storage中
func (s SyncReloadDataLoginOption) OnSuccess(bot *Bot) error {
if s.SyncLoopDuration <= 0 {
return nil
}
syncer := NewHotReloadStorageSyncer(bot, s.SyncLoopDuration)
go func() { _ = syncer.Sync() }()
return nil
}

func NewSyncReloadDataLoginOption(duration time.Duration) BotLoginOption {
return &SyncReloadDataLoginOption{SyncLoopDuration: duration}
}

// withModeOption 指定使用哪种客户端模式
type withModeOption struct {
mode Mode
Expand Down Expand Up @@ -167,10 +145,6 @@ func (w WithContextOption) Prepare(b *Bot) {
b.context, b.cancel = context.WithCancel(w.Ctx)
}

const (
defaultHotStorageSyncDuration = time.Minute * 5
)

// BotLogin 定义了一个Login的接口
type BotLogin interface {
Login(bot *Bot) error
Expand Down Expand Up @@ -209,13 +183,6 @@ func (s *SacnLogin) checkLogin(bot *Bot, uuid string) error {
return loginChecker.CheckLogin()
}

var (
hotLoginDefaultOptions = [...]BotLoginOption{
NewSyncReloadDataLoginOption(defaultHotStorageSyncDuration),
}
pushLoginDefaultOptions = hotLoginDefaultOptions
)

// HotLogin 热登录模式
type HotLogin struct {
storage HotReloadStorage
Expand Down Expand Up @@ -341,12 +308,6 @@ func HotLoginWithRetry(flag bool) BotLoginOption {
return DoNothingBotLoginOption
}

// Deprecated: 请使用 NewRetryLoginOption 代替
// HotLoginWithSyncReloadData 定时同步热登录数据
func HotLoginWithSyncReloadData(duration time.Duration) BotLoginOption {
return NewSyncReloadDataLoginOption(duration)
}

// Deprecated: 请使用 NewRetryLoginOption 代替
// PushLoginWithRetry 免扫码登录模式,如果登录失败会重试
func PushLoginWithRetry(flag bool) BotLoginOption {
Expand All @@ -355,9 +316,3 @@ func PushLoginWithRetry(flag bool) BotLoginOption {
}
return NewRetryLoginOption()
}

// Deprecated: 请使用 NewSyncReloadDataLoginOption 代替
// PushLoginWithSyncReloadData 定时同步热登录数据
func PushLoginWithSyncReloadData(duration time.Duration) BotLoginOption {
return NewSyncReloadDataLoginOption(duration)
}
8 changes: 4 additions & 4 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

func TestLogin(t *testing.T) {
bot := DefaultBot(Desktop)
bot.LoginCallBack = func(body []byte) {
t.Log("login success")
bot.LoginCallBack = func(body CheckLoginResponse) {
t.Log("login")
}
if err := bot.Login(); err != nil {
t.Error(err)
Expand All @@ -18,8 +18,8 @@ func TestLogin(t *testing.T) {

func TestLogout(t *testing.T) {
bot := DefaultBot(Desktop)
bot.LoginCallBack = func(body []byte) {
t.Log("login success")
bot.LoginCallBack = func(body CheckLoginResponse) {
t.Log("login")
}
bot.LogoutCallBack = func(bot *Bot) {
t.Log("logout")
Expand Down