feat: filter (#6)
This commit is contained in:
parent
99964ccf69
commit
b3a9a81aef
|
@ -173,4 +173,14 @@ class ReactNativeModule(reactContext: ReactApplicationContext) : ReactContextBas
|
|||
fun storeQuery(queryJSON: String, peerID: String = "", ms: Double, promise: Promise) {
|
||||
promise.resolve(Gowaku.storeQuery(queryJSON, peerID, ms.toLong()))
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun filterSubscribe(filterJSON: String, peerID: String = "", ms: Double, promise: Promise) {
|
||||
promise.resolve(Gowaku.filterSubscribe(filterJSON, peerID, ms.toLong()))
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun filterUnsubscribe(filterJSON: String, ms: Double, promise: Promise) {
|
||||
promise.resolve(Gowaku.filterUnsubscribe(filterJSON, ms.toLong()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,4 +135,16 @@ RCT_EXTERN_METHOD(storeQuery:(NSString *)query
|
|||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(filterSubscribe:(NSString *)filterJSON
|
||||
withPeerID:(NSString *)peerID
|
||||
withMs:(nonnull NSNumber *)ms
|
||||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(filterUnsubscribe:(NSString *)filterJSON
|
||||
withMs:(nonnull NSNumber *)ms
|
||||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -167,4 +167,14 @@ class ReactNative: RCTEventEmitter {
|
|||
resolve(GowakuStoreQuery(queryJSON, peerID, ms))
|
||||
}
|
||||
|
||||
@objc(filterSubscribe:withPeerID:withMs:withResolver:withRejecter:)
|
||||
func filterSubscribe(filterJSON: String, peerID: String, ms: Int, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
||||
resolve(GowakuFilterSubscribe(filterJSON, peerID, ms))
|
||||
}
|
||||
|
||||
@objc(filterUnsubscribe:withMs:withResolver:withRejecter:)
|
||||
func filterSubscribe(filterJSON: String, ms: Int, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
|
||||
resolve(GowakuFilterUnsubscribe(filterJSON, ms))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -378,9 +378,14 @@ export class PagingOptions {
|
|||
cursor: Index | null = null
|
||||
forward: Boolean = false
|
||||
}
|
||||
|
||||
export class ContentFilter {
|
||||
contentTopic: String = ""
|
||||
}
|
||||
|
||||
export class StoreQuery {
|
||||
pubsubTopic: String = ""
|
||||
contentFilters: Array<String> = Array()
|
||||
contentFilters: Array<ContentFilter> = Array()
|
||||
startTime: Number = 0
|
||||
endTime: Number = 0
|
||||
pagingOptions: PagingOptions | null = null
|
||||
|
@ -391,13 +396,41 @@ export function storeQuery(query: StoreQuery, peerID: String = "", ms: Number =
|
|||
let queryJSON = JSON.stringify(query)
|
||||
let response = JSON.parse(await ReactNative.storeQuery(queryJSON, peerID, ms));
|
||||
|
||||
console.log("STORE RESPONSE:")
|
||||
console.log(response)
|
||||
|
||||
if(response.error){
|
||||
reject(response.error);
|
||||
} else {
|
||||
resolve(response.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export class FilterSubscription {
|
||||
topic: String | null = null
|
||||
contentFilters: Array<ContentFilter> = Array()
|
||||
}
|
||||
|
||||
export function filterSubscribe(filter: FilterSubscription, peerID: String = "", ms: Number = 0): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
let filterJSON = JSON.stringify(filter)
|
||||
let response = JSON.parse(await ReactNative.filterSubscribe(filterJSON, peerID, ms));
|
||||
|
||||
if(response.error){
|
||||
reject(response.error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function filterUnsubscribe(filter: FilterSubscription, ms: Number = 0): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
let filterJSON = JSON.stringify(filter)
|
||||
let response = JSON.parse(await ReactNative.filterSubscribe(filterJSON, ms));
|
||||
|
||||
if(response.error){
|
||||
reject(response.error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue