aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-02 15:20:21 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-02 15:20:21 -0700
commit5ae5087660f0855087a2a65181d000d4383a45f4 (patch)
tree6b94924ab6b2827c0ede9dcab7a3e72a5d92f7f3
parent0197c3f5f7ac92d83711d28739670cba2e018701 (diff)
Implement reply quoting
-rw-r--r--hotline/field.go2
-rw-r--r--hotline/transaction_handlers.go28
2 files changed, 17 insertions, 13 deletions
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")