Hasya
Hasya

Reputation: 9898

When i terminate app MUC group chat members are getting removed

When i terminate app MUC group chat members are getting removed, i have to join them again while coming back to app from bookmarks? We do not want to rejoin again and again. Can someone please suggest way how to avoid rejoining.

In Android smack there is provision for auto-rejoin.

Even from Openfire back end we have managed code to do not remove.

So Android is working fine, iOS is removing users.

Please do suggest.

Upvotes: 0

Views: 122

Answers (2)

Siarhei Yakushevich
Siarhei Yakushevich

Reputation: 626

In spite of the fact that there is the answer. I would like to elaborate a little bit :)

In case of MUC rooms: there is an affiliation, i.e. long-lasting role (admin, owner, etc) and "subscription" role (visitor, member etc).

What you are asking is per se described in XMPP MUC. 7.1 Order of Events

You send your presence to join the room, and receive presence from other other participants, you can also get some cached messages if your XMPP backend was configured properly.

For instance for ejabberd (process-one): mod_muc: history_size settings defines in-memory cache.

You might don't want to get set of room events, as described in 7.1 above.

There might be some server's extensions. In case of ejabberd there is MUCPubSub you send your subscription (not presence) and get the following messages, plus you can get list of members or track its changes, and etc:

 <subscribe xmlns='urn:xmpp:mucsub:0'
         nick='mynick'
         password='roompassword'>
<event node='urn:xmpp:mucsub:nodes:messages' />

Upvotes: 0

Sandip Patel - SM
Sandip Patel - SM

Reputation: 3394

Instead of rejoining the room every time, do set the presence of the group when the user relaunches the app.

Set presence with below code function iterate through all your groups name and set presence:

    for group in chatListModel ?? []{            
            if(group.opponent_type == "2"){
                print("Group Name: \(group.opponent_uuid ?? "")")                
XMPPGlobal.sharedIntanceXMPP.xmppController.updatePresence(roomJID: XMPPJID(string: "\(group.opponent_uuid ?? "")@\(groupServerName)"))
            }
        }

Define below function in your XMPPController class:

func updatePresence(roomJID : XMPPJID?) {
                        
        let presence = XMPPPresence(type: "presence")
        presence.addAttribute(withName: "from", stringValue: self.xmppStream.myJID?.user ?? "")
        presence.addAttribute(withName: "to", stringValue: "\(roomJID?.full ?? "")/\(self.xmppStream.myJID?.user ?? "")")
        
        let element = DDXMLElement.init(name: "x", xmlns: XMPPMUCNamespace)
        presence.addChild(element)
        self.xmppStream.send(presence)
        
    }

Hope it will works for you.

Upvotes: 2

Related Questions