From 0d5d8e45b0612a82f32fade487bb416a09b4f560 Mon Sep 17 00:00:00 2001 From: "Pavel R." Date: Tue, 2 Jun 2026 14:07:50 +0300 Subject: [PATCH] close #110 --- xmpp/gateway/gateway.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go index dbcf720..40aa648 100644 --- a/xmpp/gateway/gateway.go +++ b/xmpp/gateway/gateway.go @@ -762,10 +762,27 @@ func SPAppendFrom(oldArgs []args.V, id int64) []args.V { return newArgs } +// isSubscriptionType reports whether a presence type manages the subscription +// state. Per RFC 6121 ยง 3 such presences must be addressed from a bare JID; +// attaching the component resource makes clients treat the full JID as a +// separate entity and produces a duplicate subscription request. +func isSubscriptionType(typ string) bool { + switch typ { + case "subscribe", "subscribed", "unsubscribe", "unsubscribed": + return true + } + return false +} + // SimplePresence crafts simple presence varargs func SimplePresence(from int64, typ string) []args.V { args := []args.V{SPType(typ)} - args = SPAppendFrom(args, from) + if isSubscriptionType(typ) { + // subscription presences must come from the bare JID + args = append(args, SPFrom(CHATNODE(from))) + } else { + args = SPAppendFrom(args, from) + } return args }