From 6ad43fc25e03eccbcab946c219cbd7347225ee80 Mon Sep 17 00:00:00 2001
From: aforge <aforge@>
Date: Fri, 24 Mar 2023 18:02:19 -0700
Subject: [PATCH] Fix crash in calls.

Call termination:
Current code attempted to re-use headers from the original message (Pub)
in order to form a replacement message
while calls normally terminate on Note messages which don't have headers.
---
 server/calls.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/server/calls.go b/server/calls.go
index a082ee30..29e3b80d 100644
--- a/server/calls.go
+++ b/server/calls.go
@@ -406,7 +406,11 @@ func (t *Topic) maybeEndCallInProgress(from string, msg *ClientComMessage, callD
 	// Send a message indicating the call has ended.
 	msgCopy := *msg
 	msgCopy.AsUser = originatorUid.UserId()
-	head := t.currentCall.messageHead(msgCopy.Pub.Head, replaceWith, int(callDuration))
+	var origHead map[string]any
+	if msgCopy.Pub != nil {
+		origHead = msgCopy.Pub.Head
+	} // else fetch the original message from store and use its head.
+	head := t.currentCall.messageHead(origHead, replaceWith, int(callDuration))
 	if err := t.saveAndBroadcastMessage(&msgCopy, originatorUid, false, nil, head, t.currentCall.content); err != nil {
 		logs.Err.Printf("topic[%s]: failed to write finalizing message for call seq id %d - '%s'", t.name, t.currentCall.seq, err)
 	}
-- 
GitLab