From 67eda0d0698657dff6d314b087cdb482f1ab1a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Krzy=C5=BCanowski?= Date: Mon, 29 Apr 2024 14:00:07 +0200 Subject: [PATCH] Changing initiation status to D when got ChatStartDRequest --- client/client.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/client.go b/client/client.go index a022c5b..e6e1e6f 100644 --- a/client/client.go +++ b/client/client.go @@ -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) { + cliCtx.initiationsLock.Lock() + defer cliCtx.initiationsLock.Unlock() + startChatDReq, err := cm.RequestFromFrame[cm.StartChatDRequest](reqFrame) if err != nil { return nil, err @@ -123,6 +126,17 @@ func (cliCtx *Context) handleStartChatD(reqFrame cm.RFrame) (res cm.Response, er startChatDReq.Nickname, startChatDReq.PunchCode) 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 } @@ -271,6 +285,9 @@ func sendStartChatA(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 { return i.AbANick == nick }) @@ -287,6 +304,8 @@ func sendStartChatC(ctx *Context, nick string) { return } + ctx.initiations[idx].Stage = cm.InitiationStageC + logger.Debug("request sent, no wait for response") }