robbiehanson / XMPPFramework

An XMPP Framework in Objective-C for Mac and iOS
Other
5.91k stars 2.09k forks source link

When i terminate app MUC group chat members are getting removed #1212

Open hasyapanchasara opened 3 years ago

hasyapanchasara commented 3 years ago

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.

hasyapanchasara commented 2 years ago

Any opinion on this?

hasyapanchasara commented 2 years ago

@robbiehanson Can you please suggest us on this?

smindia1988 commented 2 years ago

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 group's 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.