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

Add stanalone setup channel ID method for multiple channel ID use cases #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions android/src/main/java/com/xmartlabs/rnline/RNLine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
}


private val lineApiClient: LineApiClient
private val channelId: String
private var lineApiClient: LineApiClient
private var channelId: String
private var LOGIN_REQUEST_CODE: Int = 0
private val uiCoroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Main)
private val context: Context = reactContext.applicationContext

private var loginResult: Promise? = null

override fun getName() = MODULE_NAME

init {
val context: Context = reactContext.applicationContext
channelId = context.getString(R.string.line_channel_id)
lineApiClient = LineApiClientBuilder(context, channelId).build()
reactContext.addActivityEventListener(object : ActivityEventListener {
Expand All @@ -54,6 +54,12 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
})
}

@ReactMethod
fun configure(args: ReadableMap, promise: Promise) {
channelId = if (args.hasKey(ConfigureArguments.CHANNEL_ID.key)) args.getString(ConfigureArguments.CHANNEL_ID.key)!!.toString() else context.getString(R.string.line_channel_id)
lineApiClient = LineApiClientBuilder(context, channelId).build()
}

@ReactMethod
fun login(args: ReadableMap, promise: Promise) {
val scopes = if (args.hasKey(LoginArguments.SCOPES.key)) args.getArray(LoginArguments.SCOPES.key)!!.toArrayList() as List<String> else listOf("profile")
Expand Down
5 changes: 5 additions & 0 deletions ios/LineLogin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ @interface RCT_EXTERN_MODULE(LineLogin, NSObject)
verifyAccessToken: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
)
RCT_EXTERN_METHOD(
configure: (NSDictionary *)arguments
resolver: (RCTPromiseResolveBlock)resolve
rejecter: (RCTPromiseRejectBlock)reject
)
@end
15 changes: 15 additions & 0 deletions ios/LineLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ import LineSDK
}
}

@objc func configure(_ arguments: NSDictionary?, resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let args = arguments else {
LineLogin.nilArgument(reject)
return
}
guard let channelID = args["channelId"] as? String else { return }
Swift.print("[LineSDK] configure \(channelID)")
let universalLinkURL = args["universalLinkUrl"] as? URL

DispatchQueue.main.async {
LoginManager.shared.setup(channelID: channelID, universalLinkURL: universalLinkURL)
}
}

@objc func logout(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
LoginManager.shared.logout { result in
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
logout as LineSDKLogout,
refreshToken as LineSDKRefreshToken,
verifyAccessToken as LineSDKVerifyAccessToken,
configure as LineSDKConfigure,
} from './lineSDKWrapper'
import { LoginArguments } from './types'

export {
import {
LoginArguments,
ConfigureArguments,
BotFriendshipStatus,
AccessToken,
AccessTokenVerifyResult,
LoginArguments,
LoginPermission,
LoginResult,
BotPrompt,
Expand Down Expand Up @@ -42,4 +43,7 @@ export default {
verifyAccessToken() {
return LineSDKVerifyAccessToken()
},
configure(args: ConfigureArguments) {
return LineSDKConfigure(args)
},
}
5 changes: 5 additions & 0 deletions src/lineSDKWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
LoginArguments,
LoginResult,
UserProfile,
ConfigureArguments,
} from './types'

const { LineLogin } = NativeModules
Expand Down Expand Up @@ -59,3 +60,7 @@ export const verifyAccessToken = async (): Promise<AccessTokenVerifyResult> => {
const deserializedResult = deserializeVerifyAccessToken(result)
return deserializedResult
}

export const configure = (args: ConfigureArguments) => {
return LineLogin.configure(args)
}
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface AccessToken {
id_token?: String
}

export interface ConfigureArguments {
channelId: string
universalLinkUrl?: string
}

export interface BotFriendshipStatus {
friendFlag: boolean
}
Expand Down