Backendless Support
 
Answered

Any idea how to create a groups like whatsapp ??

Hi guys ,

i'm creating an app users can sign in and create a group with multiple users in it that they can sharing a pictures or anything (the creator of the group is the admin or he can pass the administration to any one in the group) ? any idea how to do that ???

Best Answer
photo

here's one way to do it:

8bfeed15907d15ceaae776e2999d5595

Leave a Comment

Comments (13)

photo
1

Hi Nasser,

How to do what?

  1. Create app?
  2. Create group with multiple users?
  3. Sharing pictures or anything?
  4. Pass administration to any one?

There are a lot of questions.. Please keep in mind that the support we can provide is specifically on Backendless API and features we support.

Regards,

Mark

photo
1

Hi Mark,

ok, How to Create group with multiple users?

photo
2

here's one way to do it:

8bfeed15907d15ceaae776e2999d5595

photo
1

thanks Mark very much for supporting

ok how to add a specific user to a specific group by Code Not the panal ?

Because in my app i'm trying to give any user the functionality to create a group and add some users in it for sharing photos or anything !

photo
1

so for each group i have to create a table ?

photo
1

No, the UserGroup is already a table, for each group you will save an object in that table

photo
1

Thanks Mark

i did it thanks to you2b450add0ba9f4debdfc619da59fe34e

photo
1

You got it, Nasser! Great job!

photo
1

Hi Mark,

I've managed adding users very well with this Code

  1. let User = userResults[indexPath.row]

    let member1 = backendless.userService.findById(User.memberId)

    let query = BackendlessDataQuery()

    let group = backendless.persistenceService.of(Groups.ofClass()).find(query)

    let currentPage = group.getCurrentPage()

    for theGroup in currentPage as! [Groups] {

    if theGroup.objectId == addNewUserGroup?.grouPId {

    if theGroup.ownerId != member1.objectId {

    theGroup.members.append(member1)

    var error: Fault?

    let result = backendless.data.update(theGroup, error: &error) as? Groups

    if error == nil {

    print("Member havs been added: \(result)")

    } else {

    print("Server reported an error: \(error)")

    }

    } else {

    displayAlert("You are the owner of this group !", message: "")

    print("He Is The Owner!")

    }

    }

    }

BUT i'm struggling with delete users from the group ... I'm trying with this code

  1. let User = memberResult[indexPath.row]

    let member = backendless.userService.findById(User.memberId)

    let TheGroup = backendless.persistenceService.of(Groups.ofClass()).findID(groupUsersInfo?.grouPId) as! Groups

    let index = TheGroup.members.indexOf(member)

    TheGroup.members.removeAtIndex(index!)

    var error: Fault?

    let result = backendless.data.update(TheGroup, error: &error) as? Groups

    if error == nil {

    print("Member havs been updated: \(result)")

    }

    else {

    print("Server reported an error: \(error)")

    }

it give me this error ....

83fa00ef5af555bf434163dac82badbe

what is the problem ?

photo
1

I do not know, it looks like a problem in your code and not with Backendless API. Use debugger to see where it does not work as expected.

Mark

photo
1

so my delete users code is correct ?

photo
1

it is, however, you need to make sure that the "members" collection is also returned. See the "Single Step Retrieval" section here:

https://backendless.com/documentation/data/ios/data_relations_retrieve.htm

Regards,

Mark

photo