This commit is contained in:
shoopea 2019-05-30 14:08:39 +08:00
parent bc02282bbe
commit c4ac28ed64
4 changed files with 15 additions and 31 deletions

View File

@ -17,30 +17,26 @@ func clientSendCWMsg(userID64 int64, s string) {
func clientMsgMeAck(m *ChatWarsMessageMeAck) { func clientMsgMeAck(m *ChatWarsMessageMeAck) {
log.Printf("clientMsgMeAck %d\n", m.UserID64) log.Printf("clientMsgMeAck %d\n", m.UserID64)
if _, ok := clientsQueue[m.UserID64]; ok { if _, ok := clientsQueue[m.Msg.UserID64]; ok {
log.Printf("Client in clientsQueue\n") log.Printf("Client in clientsQueue\n")
t, err := getObjMsgDate(m.ObjID64)
logOnError(err, "clientMsgMe : getObjMsgDate")
if c, ok := clientsCW[m.UserID64]; ok { if c, ok := clientsCW[m.UserID64]; ok {
if c.LastUpdate.Before(t) { if c.LastUpdate.Before(m.Msg.Date) {
c.GuildID64 = m.GuildID64 c.GuildID64 = m.GuildID64
c.State = m.State c.State = m.State
c.LastUpdate = t c.LastUpdate = m.Msg.Date
if cacheObjGuild[``].ObjID64 != m.GuildID64 && strings.Compare(c.Role, ``) == 0 { if cacheObjGuild[``].ObjID64 != m.GuildID64 && strings.Compare(c.Role, ``) == 0 {
clientSendCWMsg(m.UserID64, "/g_roles") clientSendCWMsg(m.Msg.UserID64, "/g_roles")
} }
} }
} else { } else {
c := ChatWarsClient{ c := ChatWarsClient{
GuildID64: m.GuildID64, GuildID64: m.GuildID64,
State: m.State, State: m.State,
LastUpdate: t, LastUpdate: m.Msg.Date,
} }
clientsCW[m.UserID64] = &c clientsCW[m.UserID64] = &c
if cacheObjGuild[``].ObjID64 != m.GuildID64 { if cacheObjGuild[``].ObjID64 != m.GuildID64 {
clientSendCWMsg(m.UserID64, "/g_roles") clientSendCWMsg(m.Msg.UserID64, "/g_roles")
} else {
clientSendCWMsg(m.UserID64, "/g_roles")
} }
} }
} else { } else {

2
def.go
View File

@ -72,7 +72,7 @@ type ChatWarsMessageReportAck struct {
} }
type ChatWarsMessageMeAck struct { type ChatWarsMessageMeAck struct {
ObjID64 int64 `json:"obj_id"` Msg *ChatWarsMessage `json:"msg"`
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"` GuildID64 int64 `json:"guild_id"`
State string `json:"state"` State string `json:"state"`

20
obj.go
View File

@ -377,22 +377,10 @@ func loadObjUser() error {
} }
func getObjMsgDate(objID64 int64) (time.Time, error) { func getObjMsgDate(objID64 int64) (time.Time, error) {
var t time.Time m, err := getMsg(objID64)
rows, err := db.Query(`SELECT om.date FROM obj_msg om WHERE om.obj_id = ?;`, objID64)
logOnError(err, "getObjMsgDate : select")
if err != nil { if err != nil {
return time.Now(), nil return time.Now(), err
} else {
return m.Date, nil
} }
defer rows.Close()
for rows.Next() {
err := rows.Scan(&t)
logOnError(err, "getObjMsgDate : row")
if err != nil {
return time.Now(), nil
}
}
return t, nil
} }

View File

@ -143,7 +143,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageMeAck: case objSubTypeMessageMeAck:
cwm, err := parseSubTypeMessageMeAck(m, r) cwm, err := parseSubTypeMessageMeAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
cwm.ObjID64 = objId cwm.Msg = m
clientMsgMeAck(cwm) clientMsgMeAck(cwm)
err = setObjSubTypeId(objId, objSubTypeMessageMeAck) err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")