feat: filter

This commit is contained in:
Richard Ramos 2022-08-09 14:29:20 -04:00
parent 99964ccf69
commit d5da246ddb
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
4 changed files with 69 additions and 4 deletions

View File

@ -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()))
}
}

View File

@ -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

View File

@ -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))
}
}

View File

@ -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();
}
});
}