How to get group info of a user - xmpp

I get a user's JID,i want to get the group info that the user has joined by user JID.
Can someone help me ?Please.

Depending on which storage type you are using in there (CoreData/Memory) - the 'groups' field on the user (XMPPUserCoreDataStorageObject) is a 1:m relation to the groups (XMPPGroupCoreDataStorageObject) of that user, and each group also has a 1:m relation to users (group.users).
So you should be able to get the user object via the jid of that user ([xmppRosterStorage userForJID:jid ...]), and from there, get the groups (user.groups).

Related

How does MongoDB keep data in sync

Lets say I have a social media app. There is a Group model that has a field called invitedUsers which is simply an array of user ids that are a part of that group.
On my backend I have a route that a user hits to join that Group. In that route I do something like the following:
group.invitedUsers = lodash.concat(group.invitedUsers || [], userId)
group.save()
where group is the group that the user wants to join and userId is the id of the user that wants to join the group. Upon save everything is updated properly and the user is now a part of the group.
But what happens if two users hit the route at exactly the same time? How does MongoDB ensure that the group will always have both users ids added via the above method. Is there not a chance that group.invitedUsers could be referencing a stale value if both these group.save() are being triggered around the same time?

Get each user role in PostgreSQL

Suppose I have a DB and in this DB I have a users table and a groups table where each user is related to a specific group.
In the groups table we have a “data entry” group, a “reviewer” group, an “approver” group etc.
Now assume a user X. This user is added to the “data entry” group and also added to the “reviewer” group, that means the user X has both access rights: data entry and reviewer.
Y is another user who has the “data entry” access right, so when I want to generate a report to get the count for each user and group, the “data entry” user and the “data entry + reviewer” user must be counted separately.
The point here is that those users which belong to both groups must not be counted in the individual groups; for example the “data entry + reviewer” user must not be counted to the “data entry” group.
I'd aggregate twice - first, for each user get all the groups he or she belongs too, and then aggregate that result and count how many each combination appears:
-- Count how many times each combination occurs
SELECT group_combinataions, COUNT(*)
FROM (-- Get the groups for each user
SELECT STRING_AGG(group_name ORDER BY group_name) AS group_combinations
FROM groups
GROUP BY userid) t
GROUP BY group_combinations

How to access (closed user group) programmatically?

I have created Closed User Groupe My_CUG in crx and added some users user1 and user2. I would like to get the user registered in My_CUG and their email. How can I Access My_CUG programmatically?
You can do that in the following way -
If you group name is "My_CUG" then you can resolve the corresponding group object by using the correct admin privileges -
Session adminSession = resourceResolver.adaptTo(Session.class);
UserManager um = AccessControlUtil.getUserManager(adminSession);
Group naGrp = (Group) um.getAuthorizable("My_CUG");
Now you can add any user (user1) to this group by -
naGrp.addMember(user1_Object);
Hope this solves your problem.

How to restrict other user group members to view the Documents

I have created an Organization which has four user groups. I want to restrict the user group to view the file uploaded by the other user group.
i.e
Organization 1
User Group 1
A
B
User Group 2
C
D
User Group 3
E
F
User Group 4
G
H
I am using CustomLanding hook to land on the organization page.
From above, If A uploads a document, it can be viewed only by B in user group 1.
Like the same I want to restrict the viewable condition to other groups also.
Please guide me to achieve this.
Regards,
Dinesh.
you can create different roles for the user and apply permission for role.
Instead of taking as user group with in organization we have teams. you can try with teams.

how to get members' info by using group id in facebook?

Here is a group A. I want to extract the members' group information as the training data set.
For example, group A has a list of 400 members and each member joins a number of different groups.
How can I get the members' information from the group? Can I get members' information by simply using the group id?
You can query the group endpoint using the graph api...
https://graph.faecbook.com/GROUP_ID/members
This will return (quoting facebook docuemntation) :
All of the users who are members of this group (can only currently return the first 500 members).
You will have to use a valid access token and you will only be able to retrieve one if you are administering the group.