Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android) update to Facebook SDK 13.1.0, remove deprecated game request #282

Merged
merged 4 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ buildscript {
}

dependencies {
implementation 'com.facebook.android:facebook-android-sdk:9.0.0'
implementation 'com.facebook.android:facebook-android-sdk:13.1.0'
}
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 11.0.2
version: 11.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: facebook
Expand Down
115 changes: 1 addition & 114 deletions android/src/facebook/TiFacebookModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.share.Sharer;
import com.facebook.share.model.GameRequestContent;
import com.facebook.share.model.GameRequestContent.ActionType;
import com.facebook.share.model.GameRequestContent.Filters;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.model.SharePhoto;
import com.facebook.share.model.SharePhotoContent;
import com.facebook.share.widget.GameRequestDialog;
import com.facebook.share.widget.ShareDialog;
import com.facebook.share.widget.ShareDialog.Mode;
import java.math.BigDecimal;
Expand Down Expand Up @@ -165,7 +161,7 @@ public class TiFacebookModule extends KrollModule implements OnActivityResultEve

private static TiFacebookModule module;
private static String[] permissions = new String[] {};
private LoginBehavior loginBehavior;
private LoginBehavior loginBehavior = LoginBehavior.NATIVE_WITH_FALLBACK;

private KrollFunction permissionCallback = null;

Expand Down Expand Up @@ -827,115 +823,6 @@ public void onSuccess(Sharer.Result results)
}
}

@Kroll.method
public void presentSendRequestDialog(@Kroll.argument(optional = true) final KrollDict args)
{
GameRequestDialog requestDialog = new GameRequestDialog(TiApplication.getInstance().getCurrentActivity());
requestDialog.registerCallback(callbackManager, new FacebookCallback<GameRequestDialog.Result>() {
KrollDict data = new KrollDict();
public void onSuccess(GameRequestDialog.Result result)
{
final String postId = result.getRequestId();
if (postId != null) {
data.put(PROPERTY_RESULT, postId);
}
data.put(PROPERTY_SUCCESS, true);
data.put(PROPERTY_CANCELLED, false);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}

public void onCancel()
{
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, true);
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}

public void onError(FacebookException error)
{
data.put(PROPERTY_SUCCESS, false);
data.put(PROPERTY_CANCELLED, false);
data.put(PROPERTY_ERROR, "Error sending Game Request");
fireEvent(EVENT_REQUEST_DIALOG_COMPLETE, data);
}
});

String title = (String) args.get("title");
String message = (String) args.get("message");
@SuppressWarnings("unchecked")
Map<String, String> data = (Map<String, String>) args.get("data");
String recipients = (String) args.get("recipients");
String suggestions = (String) args.get("recipientSuggestions");
String objectID = (String) args.get("objectID");

String to = (String) args.get("to");
if (to != null) {
Log.w(TAG, "Property `to` is deprecated. Please use `recipients`.");
}

int actionTypeChoice = args.optInt("actionType", TiFacebookModule.ACTION_TYPE_NONE);
ActionType actionType;
switch (actionTypeChoice) {
case TiFacebookModule.ACTION_TYPE_SEND:
actionType = ActionType.SEND;
break;
case TiFacebookModule.ACTION_TYPE_TURN:
actionType = ActionType.TURN;
break;
case TiFacebookModule.ACTION_TYPE_ASK_FOR:
actionType = ActionType.ASKFOR;
break;
default:
case TiFacebookModule.ACTION_TYPE_NONE:
actionType = null;
break;
}

int filtersChoice = args.optInt("filters", TiFacebookModule.FILTER_NONE);
Filters filters;
switch (filtersChoice) {
case TiFacebookModule.FILTER_APP_NON_USERS:
filters = Filters.APP_NON_USERS;
break;
case TiFacebookModule.FILTER_APP_USERS:
filters = Filters.APP_USERS;
break;
default:
case TiFacebookModule.FILTER_NONE:
filters = null;
break;
}

String dataString = null;
if (data != null) {
dataString = data.toString();
}

List<String> recipientsList = null;
if (recipients != null) {
String[] recipientsArray = recipients.split(",");
recipientsList = Arrays.asList(recipientsArray);
}

List<String> suggestionsList = null;
if (suggestions != null) {
String[] suggestionsArray = suggestions.split(",");
suggestionsList = Arrays.asList(suggestionsArray);
}

GameRequestContent content = new GameRequestContent.Builder()
.setTitle(title)
.setMessage(message)
.setData(dataString)
.setRecipients(recipientsList)
.setActionType(actionType)
.setObjectId(objectID)
.setFilters(filters)
.setSuggestions(suggestionsList)
.build();
requestDialog.show(content);
}

@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data)
{
Expand Down
47 changes: 0 additions & 47 deletions apidoc/Facebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,40 +282,6 @@ description: |
For details on the Share dialog, see the
[official Facebook Share Dialogs documentation](https://developers.facebook.com/docs/sharing/reference/share-dialog).

### Game Requests Dialog

To send a game request to a user, call the
[presentSendRequestDialog()](Modules.Facebook.presentSendRequestDialog) method and pass the
method a dictionary with the `message` property set the message you want to send the invited user.
Optional: You can set the `title` property with a title string. You can also set the `data` property
with a dictionary of custom parameters. If you want to preselect users to send invite to, you can set
the `to` property with string of values that are facebook ids seperated by comma.

To monitor if the request succeeded or not, listen to the <Modules.Facebook.requestDialogCompleted> event.

``` javascript
fb.addEventListener('requestDialogCompleted', function (e) {
if (e.success) {
Ti.API.info('request succeeded.');
} else {
Ti.API.warn('Failed to share.');
}
});

fb.presentSendRequestDialog({
message: 'Go to https://appcelerator.com/',
title: 'Invitation to Appcelerator',
recipients: ['123456789', '987654321'],
data: {
badge_of_awesomeness: '1',
social_karma: '5'
}
});
```

For details on game request dialogs see the
[official Facebook Request Dialogs documentation](https://developers.facebook.com/docs/games/services/gamerequests).

### Messenger Button

The Messenger button provides a quick mechanism for users to share content to the Facebook Messenger.
Expand Down Expand Up @@ -491,19 +457,6 @@ methods:
type: SharePhotoContentParams
since: "7.4.0"

- name: presentSendRequestDialog
summary: |
Opens an App Request dialog.
description: |
A `requestDialogCompleted` event is generated to indicate if the request attempt was successful or unsuccessful,
and the resultURL.
parameters:
- name: params
summary: |
A dictionary object containing parameters.
type: RequestDialogParams
since: "4.0.0"

- name: refreshPermissionsFromServer
summary: Makes a request to Facebook to get the latest permissions granted.
description: |
Expand Down
6 changes: 0 additions & 6 deletions test/unit/specs/module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,6 @@ describe('ti.facebook', () => {
});
});

describe('#presentSendRequestDialog(params)', () => {
it('is a function', () => {
expect(Facebook.presentSendRequestDialog).toEqual(jasmine.any(Function));
});
});

describe('#presentShareDialog(params)', () => {
it('is a function', () => {
expect(Facebook.presentShareDialog).toEqual(jasmine.any(Function));
Expand Down