Changing initiation status to D when got ChatStartDRequest

This commit is contained in:
Maciej Krzyżanowski 2024-04-29 14:00:07 +02:00
parent 24ee719de3
commit 67eda0d069

View File

@ -114,6 +114,9 @@ func (cliCtx *Context) handleStartChatB(reqFrame cm.RFrame) (res cm.Response, er
} }
func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, err error) { func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, err error) {
cliCtx.initiationsLock.Lock()
defer cliCtx.initiationsLock.Unlock()
startChatDReq, err := cm.RequestFromFrame[cm.StartChatDRequest](reqFrame) startChatDReq, err := cm.RequestFromFrame[cm.StartChatDRequest](reqFrame)
if err != nil { if err != nil {
return nil, err return nil, err
@ -123,6 +126,17 @@ func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, er
startChatDReq.Nickname, startChatDReq.PunchCode) startChatDReq.Nickname, startChatDReq.PunchCode)
logger.Warn("handleStartChatD not implemented yet") logger.Warn("handleStartChatD not implemented yet")
idx := slices.IndexFunc(cliCtx.initiations, func(i *cm.Initiation) bool {
return i.AbBNick == startChatDReq.Nickname
})
if idx == -1 {
logger.Error("there is no initation related to chatstartd's nickname, ignoring")
return nil, nil
}
cliCtx.initiations[idx].Stage = cm.InitiationStageD
return nil, nil return nil, nil
} }
@ -271,6 +285,9 @@ func sendStartChatA(ctx *Context, nick string) {
} }
func sendStartChatC(ctx *Context, nick string) { func sendStartChatC(ctx *Context, nick string) {
ctx.initiationsLock.Lock()
defer ctx.initiationsLock.Unlock()
idx := slices.IndexFunc(ctx.initiations, func(i *cm.Initiation) bool { idx := slices.IndexFunc(ctx.initiations, func(i *cm.Initiation) bool {
return i.AbANick == nick return i.AbANick == nick
}) })
@ -287,6 +304,8 @@ func sendStartChatC(ctx *Context, nick string) {
return return
} }
ctx.initiations[idx].Stage = cm.InitiationStageC
logger.Debug("request sent, no wait for response") logger.Debug("request sent, no wait for response")
} }