update job msg del

This commit is contained in:
shoopea 2020-01-13 16:30:41 +08:00
parent 48155d8cd4
commit a5e9039637
2 changed files with 37 additions and 9 deletions

View File

@ -112,7 +112,7 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
} }
} }
func clientDelCWMsg(userID64 int64, fromMsgID64 int64, fromChatID64 int64) { func clientDelTGMsg(userID64 int64, fromMsgID64 int64, fromChatID64 int64) {
c := TGCommand{ c := TGCommand{
Type: commandDeleteMsg, Type: commandDeleteMsg,
FromUserID64: userID64, FromUserID64: userID64,

42
job.go
View File

@ -596,8 +596,30 @@ func jobMsgDelete(j Job) {
err = json.Unmarshal(j.Payload, &p) err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobMsgDel : Unmarshal payload") logOnError(err, "jobMsgDel : Unmarshal payload")
_, err = getObjMsg(j.Trigger) if j.Trigger != 0 && p.MsgTypeID64 != 0 {
logOnError(err, "jobMsgDel : getObjMsg msg") logOnError(err, "jobMsgDel : getObjMsg msg")
id, err := getObjSubTypeId(j.Trigger)
if id == p.MsgTypeID64 {
if p.Delay == 0 {
obj, err = getObjMsg(j.Trigger)
clientDelTGMsg(j.UserID64, obj.ID64, obj.ChatID64)
} else {
p.ObjMsgID64 = j.Trigger
b, _ := json.Marshal(p)
_, err = createJob(cacheObjSubType[`job_msg_del`], objJobPriority, j.UserID64, time.Now().Add(p.Delay).UTC(), b)
}
} else {
log.Printf("jobMsgDelete : cannot identify msg to delete")
}
} else if p.ObjMsgID64 != 0 {
if p.Delay == 0 {
obj, err = getObjMsg(j.Trigger)
clientDelTGMsg(j.UserID64, obj.ID64, obj.ChatID64)
} else {
b, _ := json.Marshal(p)
_, err = createJob(cacheObjSubType[`job_msg_del`], objJobPriority, j.UserID64, time.Now().Add(p.Delay).UTC(), b)
}
}
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "jobMsgDel : setJobDone") logOnError(err, "jobMsgDel : setJobDone")
@ -1410,11 +1432,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_res_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_res_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_res`) clientSendCWMsg(j.UserID64, `/g_stock_res`)
} else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] {
log.Printf("jobGWithdraw : Requesting alch.\n") log.Printf("jobGWithdraw : Requesting alch.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]]
@ -1424,11 +1447,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_alch_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_alch_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_alch`) clientSendCWMsg(j.UserID64, `/g_stock_alch`)
} else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] {
log.Printf("jobGWithdraw : Requesting misc.\n") log.Printf("jobGWithdraw : Requesting misc.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]]
@ -1438,11 +1462,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_misc_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_misc_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_misc`) clientSendCWMsg(j.UserID64, `/g_stock_misc`)
} else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] {
log.Printf("jobGWithdraw : Requesting recipe.\n") log.Printf("jobGWithdraw : Requesting recipe.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]]
@ -1452,11 +1477,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_rec_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_rec_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_rec`) clientSendCWMsg(j.UserID64, `/g_stock_rec`)
} else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] {
log.Printf("jobGWithdraw : Requesting part.\n") log.Printf("jobGWithdraw : Requesting part.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]]
@ -1466,11 +1492,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_part_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_part_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_part`) clientSendCWMsg(j.UserID64, `/g_stock_part`)
} else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] {
log.Printf("jobGWithdraw : Requesting other.\n") log.Printf("jobGWithdraw : Requesting other.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]]
@ -1480,11 +1507,12 @@ func jobGWithdraw(j Job) {
p2 := JobPayloadMsgDel{ p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_oth_req`], MsgTypeID64: cacheObjSubType[`msg_gstock_oth_req`],
Delay: (10 * time.Second), Delay: (10 * time.Second),
ObjMsgID64: 0,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(`/g_stock_other`) clientSendCWMsg(j.UserID64, `/g_stock_other`)
} else { } else {
log.Printf("jobGWithdraw : got all the info\n") log.Printf("jobGWithdraw : got all the info\n")
} }