smack - invite users to muc room as moderators - xmpp

I have this code, but muc.grantModerator(user.getJid()) is failing because the user is not inside the room yet.
Any suggestions to invite users to muc room as moderators?
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat muc = manager.getMultiUserChat(roomjid);
for (User user : invitedUsers) {
muc.invite(user.getJid(), "");
muc.grantModerator(user.getJid());
}

Related

Telegram chat and welcome message

Could you tell me how to create welcome message in telegram chat, which visible only for invited user(newbie).
Now bot is created and invited in group. When to login "newbie", chat-bot send welcome-message(for all users).
$chat = $message['chat'];
$user = $message['from'];
if (isset($message['new_chat_members'])) {
$mess_id = $this->send_message('Welcome '. $user['first_name'] , $chat);
}
How i can do this welcome message visible only for a newbie ?
PS: sorry for my english.(

How can I approve an XMPP subscription request 'later' in Smack ("Add later" functionality)?

Let us suppose that Alice sends a subscription request to Bob using the next code.
public bool AddBuddy(string jid) {
var roster = conn.Roster;
// 2` param is nickname
roster.CreateEntry(jid, null, null);
roster.SetSubscriptionMode(Roster.SubscriptionMode.Manual);
Presence subscribe = new Presence(Presence.Type.Subscribe);
subscribe.To = jid;
conn.SendPacket(subscribe);
}
When Bob has logged, it receives a popup where tell you if you want to added or not in the next method.
public void ProcessPacket (Packet p0)
{
Presence presence = p0.JavaCast<Presence> ();
var a = presence;
}
But I need to implement a "Add Later" functionality. I have no idea how to save the messages in the server and also how to receive all of them
You can delay the subscription as long as you want, there is no need to save the subscriptions packets on the server. And in order to query the deferred subscriptions requests, simply query the roster for subscriptions not in mode both.
One remark regarding your code: Roster.createEntry(String, String, String[] will automatically send the presence packat. No need to send it again.
No need to save anything on the server as it maintains pending subscribe requests automatically, ie. whenever you login to the server at a later time, the subscribe request will be pushed to you again (if it wasn't dealt with before). Therefore, just save the subscribe request locally in your application in a list or something whenever you receive it from the server, and show that local request list to the user as a "Friend request page" for the user to accept/reject. If your application's lifecycle restarts, it will be receiving all pending subsribe presences again from the server (or whenever it re-logins). Let me know if this works for you.

How to get ids of facebook invited friends by user in my asp.net4.0 web application

I am developing an ASP.NET application. I implemented Facebook JavaScript API in my application, for connect with Facebook and get FB friend list of user. I had done this successfully.
Now, I want to count how many friends are invited by user. Is it possible with facebook API. User can select multiple friends and i want to count how many friends selected and invited by user, Invited friends Id is bonus if We can get.
Please don't forget that facebook changed its Oauth settings for security reasons.
I'm also trying to get ids values after Send Invitation button clicked and page post back to
if (Request.Form["ids"] != null)
{
span1.InnerHtml = "ids";
//put success code here..
}
else
{
span1.InnerHtml = "oops no id";
}
if (Page.PreviousPage != null)
{
span1.InnerHtml = "ids";
//put success code here..
}
else
{
span1.InnerHtml = "oops no id";
}
but in this case program control always goes to else condition it means after page is post back form return null value.
Is there any way to get ids of invited friends.
Thanks.
If you using Facebook Requests to send invites (you really should, it's intended for this), the only way to get invited friends is via Facebook Requests Dialog callback:
FB.ui({method: 'apprequests', message: 'Whoa!'}, callback);
function callback(response){
// response.to now contain array of invited users ids
console.log('Invited friends ids', response.to);
if (response.request) {
console.log('Efficient Request id', response.request);
} else {
console.log('Requests Ids', response.request_ids);
}
}
There is no way to get request sent by user via Graph API or FQL, you only can get requests received by user. You may save all requests sent by your users and rely on this data if you need aggregated count of invitation sent...
Ok finally I resolve this issue and get invited friends ids..
As we know we use javascript sdk for FB connect so my solution is in concern of Java script:
Just make on change in your .js file where you put your facebook connect javascript code. Use Get or Request Method instead of Post Method in fb:request-form tag.
<script type="text/javascript>
var fbhtml = "<fb:serverFbml width=\"" + width_of_invitation_div + "\">
<script type=\"text/fbml\"><fb:fbml><fb:request-form action=" + window.location + " method="REQUEST" invite="true" type="" + type_of_fb_request_form + "" hold=" /><br mode="></fb:request-form></fb:fbml></script></fb:serverfbml>"
</script>
After invitation send to users selected friends you get ids[] in url.
you can get these ids through query string and split ids by comma(,) and store in array.
Hope this will help for other devs.

Facebook emails always return null through FQL and RestFB

I'm trying to convert friend pages into fan pages (most businesses have created friend pages by mistake) and am trying to email everyone on a friend list about the move.
I've tried
FQL "SELECT email FROM user WHERE uid=xxxx"
Creating groups (not good for 5000 friend pages)
Restfb: Connection myFriends = facebookClient.fetchConnection("me/friends", User.class) etc;
The FQL and RestFB methods are both returning nada, group email method is just plain messy.
Is this a security feature or can this data ever by returned for my purpose?
Cheers
to access user's private informations like email,posts etc you should have the permission to access those details .for more details visit https://developers.facebook.com/docs/reference/api/permissions/
If you are using restfb (Facebook graph API and old REST API client wriiten in Java), and you want to access all friend list after Oauth authentication, you can use following method to access the friends list and facebook id's,
public List<ArrayList> findFacebookFriendsUsingRest(String facebookAccessToken){
List<ArrayList> myFacebookFriendList= new ArrayList();
final FacebookClient facebookClient;
facebookClient = new DefaultFacebookClient(facebookAccessToken);
User user = facebookClient.fetchObject("me", User.class);
String userName = user.getFirstName();
if (userName == null){
userName = user.getLastName();
}
String userEmail = user.getEmail();
com.restfb.Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);
System.out.println("Count of my friends: " + myFriends.getData().size());
for(User friend: myFriends.getData()){
System.out.println("Friends id and name: "+friend.getId()+" , "+friend.getName());
myFacebookFriendList.add(friend.getName());
}
System.out.println("All Friends : "+myFacebookFriendList);
}
Facebook does not provide user, unless the user authorizes your application to access it. It's on account of security and user privacy, imagine how terrible it would be if everybody could have at her disposal all FB user's email addresses.
Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class ,Parameter.with("fields", "id, name, picture, email"));
You can specify any of the properties listed under
http://developers.facebook.com/docs/reference/api/user
The only thing is that FB does not seam to return the friends email..
I'm using restFb 1.5.3

Inviting friends in facebook application

I have a facebook application that is published at facebook platform and i used facebook API to invite friends and i have succeeded in creating invitation form but the problem is that when u invite friend and send invitation and the invitation request sent to the user and the user accept it this friend appears again in the friend list that can be invited again
For example :
i have friend in my friend list named X and when i send invitation to him the invitation is sent and and X accept the invitation and when i try to send invitation again the friend X appears again in the list that i can select from to send invitation this means that may i send an invitation to this user (X) and he is already playing the game i need to know how to fix this problem so friends appear in the friend list (for invitation )only friends that not use the application.
My application at the following link
My Game application
visit it and see the problem exactly after inviting friends they will appear again is this normal in any game application?
thanks in advance for any reply
In FBML if you are using the friend-selector you can pass it an array exclude_ids. If you use the api to find the users' friends who are already using your app, you can exclude them this way.
This also works in the multi-friend-selector which sits inside an fb:request-form tag.
EDIT: the array of users to exclude can be obtained through the api call Friends.getAppUsers.
Following example uses the .NET Facebook Developer Toolkit. (mainly because that's how I've done it before!)
CODE BEHIND:
public string CURRENT_USER_FRIENDS = "";
//Call this function on pageload or where you like
private void PopulateFriendsData()
{
//exclude friends who already have the app from the inviter
string UsersToExclude = string.Empty;
IList<long> AppUserFriends = this.Master.API.friends.getAppUsers();
foreach (long L in AppUserFriends)
{
UsersToExclude += L.ToString() + ",";
}
CURRENT_USER_FRIENDS = UsersToExclude.TrimEnd(',');
}
PAGE:
<fb:multi-friend-selector
actiontext="Select the friends you want to invite"
rows="3"
exclude_ids="<%=CURRENT_USER_FRIENDS%>"/>