fix: sync DrKLO report selection support

This commit is contained in:
iamxvbaba 2026-07-24 11:57:01 +08:00
parent 70e57b4d07
commit 840ef6237c
4 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,22 @@
package android
const clientType = "android"
// OfferInitialMessageReportOptions preserves DrKLO's official channel-report
// flow. DrKLO starts that flow with an empty message-id vector and only opens
// its message selector after a chosen option receives MESSAGE_ID_REQUIRED.
//
// This exception is deliberately limited to the non-mutating first request:
// a selected option, a comment, or any non-Android caller must still pass the
// normal messages.report message-id validation.
func OfferInitialMessageReportOptions(
client string,
messageIDCount int,
option []byte,
comment string,
) bool {
return client == clientType &&
messageIDCount == 0 &&
len(option) == 0 &&
comment == ""
}

View file

@ -0,0 +1,32 @@
package android
import "testing"
func TestOfferInitialMessageReportOptions(t *testing.T) {
tests := []struct {
name string
client string
messageIDCount int
option []byte
comment string
want bool
}{
{name: "android initial discovery", client: "android", want: true},
{name: "desktop keeps protocol error", client: "tdesktop"},
{name: "selected option requires messages", client: "android", option: []byte("spam")},
{name: "comment requires messages", client: "android", comment: "details"},
{name: "message ids use normal flow", client: "android", messageIDCount: 1},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := OfferInitialMessageReportOptions(
test.client,
test.messageIDCount,
test.option,
test.comment,
); got != test.want {
t.Fatalf("OfferInitialMessageReportOptions() = %v, want %v", got, test.want)
}
})
}
}