• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

igniterealtime / Smack / #2862

pending completion
#2862

push

github-actions

web-flow
Merge pull request #535 from MF1-MS/mf1-ms/xep_0249_support

Add partial support for XEP-0249 Direct MUC Invitations

45 of 45 new or added lines in 3 files covered. (100.0%)

16371 of 41836 relevant lines covered (39.13%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.96
/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java
1
/**
2
 *
3
 * Copyright 2003-2007 Jive Software.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.jivesoftware.smackx.muc.packet;
18

19
import javax.xml.namespace.QName;
20

21
import org.jivesoftware.smack.packet.ExtensionElement;
22
import org.jivesoftware.smack.packet.Stanza;
23
import org.jivesoftware.smack.util.Objects;
24
import org.jivesoftware.smack.util.XmlStringBuilder;
25

26
import org.jxmpp.jid.EntityBareJid;
27

28
/**
29
 * A group chat invitation stanza extension, which is used to invite other
30
 * users to a group chat room. To invite a user to a group chat room, address
31
 * a new message to the user and set the room name appropriately, as in the
32
 * following code example:
33
 *
34
 * <pre>
35
 * Message message = new Message("user@chat.example.com");
36
 * message.setBody("Join me for a group chat!");
37
 * message.addExtension(new GroupChatInvitation("room@chat.example.com"););
38
 * con.sendStanza(message);
39
 * </pre>
40
 *
41
 * To listen for group chat invitations, use a StanzaExtensionFilter for the
42
 * <code>x</code> element name and <code>jabber:x:conference</code> namespace, as in the
43
 * following code example:
44
 *
45
 * <pre>
46
 * PacketFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference");
47
 * // Create a stanza collector or stanza listeners using the filter...
48
 * </pre>
49
 *
50
 * <b>Note</b>: this protocol is outdated now that the Multi-User Chat (MUC) XEP is available
51
 * (<a href="http://www.xmpp.org/extensions/jep-0045.html">XEP-45</a>). However, most
52
 * existing clients still use this older protocol. Once MUC support becomes more
53
 * widespread, this API may be deprecated.
54
 *
55
 * @author Matt Tucker
56
 */
57
public class GroupChatInvitation implements ExtensionElement {
58

59
    /**
60
     * Element name of the stanza extension.
61
     */
62
    public static final String ELEMENT = "x";
63

64
    /**
65
     * Namespace of the stanza extension.
66
     */
67
    public static final String NAMESPACE = "jabber:x:conference";
68

69
    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
1✔
70

71
    private final EntityBareJid roomAddress;
72
    private final String reason;
73
    private final String password;
74
    private final String thread;
75
    private final boolean continueAsOneToOneChat;
76

77
    /**
78
     * Creates a new group chat invitation to the specified room address.
79
     * GroupChat room addresses are in the form <code>room@service</code>,
80
     * where <code>service</code> is the name of group chat server, such as
81
     * <code>chat.example.com</code>.
82
     *
83
     * @param roomAddress the address of the group chat room.
84
     */
85
    public GroupChatInvitation(EntityBareJid roomAddress) {
86
        this(roomAddress, null, null, false, null);
1✔
87
    }
1✔
88

89
    /**
90
     * Creates a new group chat invitation to the specified room address.
91
     * GroupChat room addresses are in the form <code>room@service</code>,
92
     * where <code>service</code> is the name of group chat server, such as
93
     * <code>chat.example.com</code>.
94
     *
95
     * @param roomAddress the address of the group chat room.
96
     * @param reason the purpose for the invitation
97
     * @param password specifies a password needed for entry
98
     * @param continueAsOneToOneChat specifies if the groupchat room continues a one-to-one chat having the designated thread
99
     * @param thread the thread to continue
100
     */
101
    public GroupChatInvitation(EntityBareJid roomAddress,
102
                               String reason,
103
                               String password,
104
                               boolean continueAsOneToOneChat,
105
                               String thread) {
1✔
106
        this.roomAddress = Objects.requireNonNull(roomAddress);
1✔
107
        this.reason = reason;
1✔
108
        this.password = password;
1✔
109
        this.continueAsOneToOneChat = continueAsOneToOneChat;
1✔
110
        this.thread = thread;
1✔
111
    }
1✔
112

113
    /**
114
     * Returns the purpose for the invitation.
115
     *
116
     * @return the address of the group chat room.
117
     */
118
    public String getReason() {
119
        return reason;
1✔
120
    }
121

122
    /**
123
     * Returns the password needed for entry.
124
     *
125
     * @return the password needed for entry
126
     */
127
    public String getPassword() {
128
        return password;
1✔
129
    }
130

131
    /**
132
     * Returns the thread to continue.
133
     *
134
     * @return the thread to continue.
135
     */
136
    public String getThread() {
137
        return thread;
1✔
138
    }
139

140
    /**
141
     * Returns whether the groupchat room continues a one-to-one chat.
142
     *
143
     * @return whether the groupchat room continues a one-to-one chat.
144
     */
145
    public boolean continueAsOneToOneChat() {
146
        return continueAsOneToOneChat;
1✔
147
    }
148

149
    /**
150
     * Returns the address of the group chat room. GroupChat room addresses
151
     * are in the form <code>room@service</code>, where <code>service</code> is
152
     * the name of group chat server, such as <code>chat.example.com</code>.
153
     *
154
     * @return the address of the group chat room.
155
     */
156
    public EntityBareJid getRoomAddress() {
157
        return roomAddress;
1✔
158
    }
159

160
    @Override
161
    public String getElementName() {
162
        return ELEMENT;
1✔
163
    }
164

165
    @Override
166
    public String getNamespace() {
167
        return NAMESPACE;
1✔
168
    }
169

170
    @Override
171
    public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
172
        XmlStringBuilder xml = new XmlStringBuilder(this);
×
173
        xml.attribute("jid", getRoomAddress());
×
174
        xml.optAttribute("reason", getReason());
×
175
        xml.optAttribute("password", getPassword());
×
176
        xml.optAttribute("thread", getThread());
×
177

178
        if (continueAsOneToOneChat())
×
179
            xml.optBooleanAttribute("continue", true);
×
180

181
        xml.closeEmptyElement();
×
182
        return xml;
×
183
    }
184

185
    /**
186
     * Get the group chat invitation from the given stanza.
187
     * @param packet TODO javadoc me please
188
     * @return the GroupChatInvitation or null
189
     */
190
    public static GroupChatInvitation from(Stanza packet) {
191
        return packet.getExtension(GroupChatInvitation.class);
×
192
    }
193

194
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc