Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
33b940cc
W
wechaty
项目概览
.Veneno.
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
33b940cc
编写于
6月 10, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactoring 62data refresh logic
上级
d5b41fc3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
75 addition
and
28 deletion
+75
-28
src/puppet-padchat/bridge.ts
src/puppet-padchat/bridge.ts
+75
-28
未找到文件。
src/puppet-padchat/bridge.ts
浏览文件 @
33b940cc
...
...
@@ -39,9 +39,9 @@ const MEMORY_SLOT_WECHATY_PUPPET_PADCHAT = 'WECHATY_PUPPET_PADCHAT'
export
interface
PadchatMemorySlot
{
device
:
{
[
userId
:
string
]:
undefined
|
{
token
?
:
string
,
name
?
:
string
,
data
:
string
,
token
:
string
,
name
?
:
string
,
data
:
string
,
},
},
currentUserId
?:
string
,
...
...
@@ -198,10 +198,7 @@ export class Bridge extends PadchatRpc {
this
.
state
.
off
(
'
pending
'
)
if
(
this
.
loginTimer
)
{
clearTimeout
(
this
.
loginTimer
)
this
.
loginTimer
=
undefined
}
this
.
stopCheckScan
()
// await this.padchatRpc.stop()
await
super
.
stop
()
...
...
@@ -230,7 +227,7 @@ export class Bridge extends PadchatRpc {
/**
* Update Memory Slot
*/
this
.
memorySlot
=
await
this
.
refresh62Data
(
this
.
memorySlot
=
await
this
.
refresh62Data
ForMemory
(
this
.
memorySlot
,
userId
,
userName
,
...
...
@@ -516,40 +513,90 @@ export class Bridge extends PadchatRpc {
)
}
protected
async
refresh62Data
(
protected
async
refresh62Data
ForMemory
(
memorySlot
:
PadchatMemorySlot
,
userId
:
string
,
userName
?:
string
,
):
Promise
<
PadchatMemorySlot
>
{
log
.
verbose
(
'
PuppetPadchatBridge
'
,
`
save
62Data(%s, %s)`
,
userId
,
userName
)
log
.
verbose
(
'
PuppetPadchatBridge
'
,
`
refresh
62Data(%s, %s)`
,
userId
,
userName
)
// await this.padchatRpc.WXHeartBeat()
/**
* must do a HeatBeat before WXGenerateWxData()
*/
await
this
.
WXHeartBeat
()
const
deviceCurrentUserId
=
memorySlot
.
currentUserId
const
deviceInfoDict
=
memorySlot
.
device
// const deviceCurrentUserId = memorySlot.currentUserId
// const deviceInfoDict = memorySlot.device
/**
* 1. Empty memorySlot, init & return it
*/
if
(
!
memorySlot
.
currentUserId
)
{
log
.
silly
(
'
PuppetPadchatBridge
'
,
'
refresh62Data() memorySlot is empty, init & return it
'
)
const
name
=
userName
const
data
=
await
this
.
WXGenerateWxDat
()
const
token
=
await
this
.
WXGetLoginToken
()
memorySlot
.
currentUserId
=
userId
memorySlot
.
device
[
userId
]
=
{
data
,
name
,
token
,
}
return
memorySlot
}
// if (!this.autoData.wxData || this.autoData.user_name !== userId) {
if
(
deviceCurrentUserId
!==
userId
)
{
log
.
verbose
(
'
PuppetPadchatBridge
'
,
`save62Data() user switch detected: from "%s(%s)" to "%s(%s)"`
,
deviceCurrentUserId
&&
deviceInfoDict
[
deviceCurrentUserId
]
!
.
name
,
deviceCurrentUserId
,
/**
* 2. User account not changed between this and the last login session
*/
if
(
memorySlot
.
currentUserId
===
userId
)
{
log
.
silly
(
'
PuppetPadchatBridge
'
,
'
refresh62Data() userId did not change since last login, keep the data as the same
'
)
return
memorySlot
}
/**
* 3. Current user is a user that had used this memorySlot, use the old data for it.
*/
if
(
userId
in
memorySlot
.
device
)
{
log
.
silly
(
'
PuppetPadchatBridge
'
,
'
refresh62Data() current userId has existing device info, set %s(%s) as currentUserId and use old data for it
'
,
userId
,
userName
,
)
memorySlot
.
currentUserId
=
userId
memorySlot
.
device
[
userId
]
=
{
...
memorySlot
.
device
[
userId
]
!
,
name
:
userName
,
token
:
await
this
.
WXGetLoginToken
(),
}
return
memorySlot
}
else
{
/**
* 4. New user login, generate 62data for it
*/
log
.
verbose
(
'
PuppetPadchatBridge
'
,
`refresh62Data() user switch detected: from "%s(%s)" to "%s(%s)"`
,
memorySlot
.
currentUserId
&&
memorySlot
.
device
[
memorySlot
.
currentUserId
]
!
.
name
,
memorySlot
.
currentUserId
,
userName
,
userId
,
)
const
name
=
userName
const
data
=
await
this
.
WXGenerateWxDat
()
const
token
=
await
this
.
WXGetLoginToken
()
memorySlot
.
currentUserId
=
userId
memorySlot
.
device
=
{
...
memorySlot
.
device
,
[
userId
]:
{
data
:
await
this
.
WXGenerateWxDat
(),
name
:
userName
,
},
memorySlot
.
device
[
userId
]
=
{
data
,
name
,
token
,
}
}
memorySlot
.
device
[
userId
]
!
.
token
=
await
this
.
WXGetLoginToken
()
return
memorySlot
return
memorySlot
}
}
protected
async
tryLoad62Data
():
Promise
<
void
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录