getting only 200 maximum contacts for any user

reduced calls made. combined user fetch and mention fetch to one request.
This commit is contained in:
Vishal
2022-12-24 01:35:33 +05:30
parent 91fa45a8c6
commit 0b1bd5d9be
7 changed files with 83 additions and 38 deletions

View File

@@ -364,7 +364,7 @@ String getStringFromUser(String prompt, [String defaultValue=""] ) {
// returns list in form ( if 3 sized list)
// "pubkey1","pubkey2","pubkey3"
String getJsonList(Set<String> publicKeys) {
String getCommaSeparatedQuotedStrs(Set<String> publicKeys) {
String s = "";
int i = 0;
for(String pubkey in publicKeys) {
@@ -448,9 +448,23 @@ String getMentionRequest(String subscriptionId, Set<String> ids, int numUserEven
}
var strSubscription1 = '["REQ","$subscriptionId",{ "$tagToGet": [';
var strSubscription2 ='], "limit": $numUserEvents $strTime } ]';
return strSubscription1 + getJsonList(ids) + strSubscription2;
return strSubscription1 + getCommaSeparatedQuotedStrs(ids) + strSubscription2;
}
String getIdAndMentionRequest(String subscriptionId, Set<String> ids, int numUserEvents, int sinceWhen, String tagToGet) {
String strTime = "";
if( sinceWhen != 0) {
strTime = ', "since": ${sinceWhen.toString()}';
}
var strSubscription1 = '["REQ","$subscriptionId",{ "$tagToGet": [';
var strSubscription2 ='], "limit": $numUserEvents $strTime } ]';
String req = '["REQ","$subscriptionId",{ "$tagToGet": [' + getCommaSeparatedQuotedStrs(ids) + '], "limit": $numUserEvents $strTime},{"authors":[' + getCommaSeparatedQuotedStrs(ids) + ']} ]';
//print("Created id and mention request: $req");
return req;
}
String getMultiUserRequest(String subscriptionId, Set<String> publicKeys, int numUserEvents, int sinceWhen, [Set<int>? kind = null]) {
String strTime = "";
if( sinceWhen != 0) {
@@ -467,7 +481,7 @@ String getMultiUserRequest(String subscriptionId, Set<String> publicKeys, int nu
var strSubscription1 = '["REQ","$subscriptionId",{ "authors": [';
var strSubscription2 ='],$strKindSection"limit": $numUserEvents $strTime } ]';
String s = "";
s = getJsonList(publicKeys);
s = getCommaSeparatedQuotedStrs(publicKeys);
String request = strSubscription1 + s + strSubscription2;
//print("In getMultiUserRequest kind = $kind strKindSection = $strKindSection: request = $request");
return request;