From: Jeff Halter Date: Thu, 2 Jun 2022 22:20:21 +0000 (-0700) Subject: Implement reply quoting X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/5ae5087660f0855087a2a65181d000d4383a45f4 Implement reply quoting --- diff --git a/hotline/field.go b/hotline/field.go index 26012af..ed009f4 100644 --- a/hotline/field.go +++ b/hotline/field.go @@ -38,7 +38,7 @@ const fieldFileComment = 210 const fieldFileNewName = 211 const fieldFileNewPath = 212 const fieldFileType = 213 -const fieldQuotingMsg = 214 // Defined but unused in the Hotline Protocol spec +const fieldQuotingMsg = 214 const fieldAutomaticResponse = 215 const fieldFolderItemCount = 220 const fieldUsernameWithInfo = 300 diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 745cb40..ea2409a 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -366,21 +366,25 @@ func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err erro func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) { msg := t.GetField(fieldData) ID := t.GetField(fieldUserID) - // TODO: Implement reply quoting - // options := transaction.GetField(hotline.fieldOptions) - res = append(res, - *NewTransaction( - tranServerMsg, - &ID.Data, - NewField(fieldData, msg.Data), - NewField(fieldUserName, cc.UserName), - NewField(fieldUserID, *cc.ID), - NewField(fieldOptions, []byte{0, 1}), - ), + reply := *NewTransaction( + tranServerMsg, + &ID.Data, + NewField(fieldData, msg.Data), + NewField(fieldUserName, cc.UserName), + NewField(fieldUserID, *cc.ID), + NewField(fieldOptions, []byte{0, 1}), ) - id, _ := byteToInt(ID.Data) + // Later versions of Hotline include the original message in the fieldQuotingMsg field so + // the receiving client can display both the received message and what it is in reply to + if t.GetField(fieldQuotingMsg).Data != nil { + reply.Fields = append(reply.Fields, NewField(fieldQuotingMsg, t.GetField(fieldQuotingMsg).Data)) + } + + res = append(res, reply) + + id, _ := byteToInt(ID.Data) otherClient := cc.Server.Clients[uint16(id)] if otherClient == nil { return res, errors.New("ohno")