mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-12-11 21:21:44 +01:00
improved getFollowers()
This commit is contained in:
@@ -9,16 +9,6 @@ bool selectAll(Tree t) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Message {
|
|
||||||
String text;
|
|
||||||
Message(this.text);
|
|
||||||
}
|
|
||||||
class ImgMessage extends Message {
|
|
||||||
String imageUrl;
|
|
||||||
ImgMessage(String text, this.imageUrl, tx) :
|
|
||||||
super( tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ScrollableMessages {
|
class ScrollableMessages {
|
||||||
String topHeader;
|
String topHeader;
|
||||||
List<String> messageIds;
|
List<String> messageIds;
|
||||||
@@ -31,13 +21,9 @@ class ScrollableMessages {
|
|||||||
page = 1;
|
page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//print(topHeader);
|
|
||||||
|
|
||||||
String displayName = topHeader;
|
String displayName = topHeader;
|
||||||
|
int lenDashes = 10;
|
||||||
int lenDashes = 10;
|
|
||||||
String str = getNumSpaces(gNumLeftMarginSpaces + 10) + getNumDashes(lenDashes) + displayName + getNumDashes(lenDashes);
|
String str = getNumSpaces(gNumLeftMarginSpaces + 10) + getNumDashes(lenDashes) + displayName + getNumDashes(lenDashes);
|
||||||
//print(" ${getNumSpaces(gNumLeftMarginSpaces + displayName.length~/2 + 4)}In Channel");
|
|
||||||
print("\n$str\n");
|
print("\n$str\n");
|
||||||
|
|
||||||
int i = 0, startFrom = 0, endAt = messageIds.length;
|
int i = 0, startFrom = 0, endAt = messageIds.length;
|
||||||
@@ -104,7 +90,6 @@ class Tree {
|
|||||||
Store? store;
|
Store? store;
|
||||||
|
|
||||||
Tree(this.event, this.children,this.store );
|
Tree(this.event, this.children,this.store );
|
||||||
|
|
||||||
factory Tree.withoutStore(Event e, List<Tree> c) {
|
factory Tree.withoutStore(Event e, List<Tree> c) {
|
||||||
return Tree(e, c, null);
|
return Tree(e, c, null);
|
||||||
}
|
}
|
||||||
@@ -113,7 +98,6 @@ class Tree {
|
|||||||
store = s;
|
store = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************/
|
/***********************************************************************************************************************************/
|
||||||
/* The main print tree function. Calls the reeSelector() for every node and prints it( and its children), only if it returns true.
|
/* The main print tree function. Calls the reeSelector() for every node and prints it( and its children), only if it returns true.
|
||||||
*/
|
*/
|
||||||
@@ -1063,30 +1047,21 @@ class Store {
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO inefficient; fix
|
// get followers of given pubkey
|
||||||
List<String> getFollowers(String pubkey) {
|
List<String> getFollowers(String pubkey) {
|
||||||
if( gDebug > 0) print("Finding followrs for $pubkey");
|
if( gDebug > 0) print("Finding followrs for $pubkey");
|
||||||
List<String> followers = [];
|
List<String> followers = [];
|
||||||
|
|
||||||
Set<String> usersWithContactList = {};
|
gKindONames.forEach((otherPubkey, userInfo) {
|
||||||
allChildEventsMap.forEach((eventId, tree) {
|
List<Contact>? contactList = userInfo.latestContactEvent?.eventData.contactList;
|
||||||
if( tree.event.eventData.kind == 3) {
|
if( contactList != null ) {
|
||||||
usersWithContactList.add(tree.event.eventData.pubkey);
|
for(int i = 0; i < contactList.length; i ++) {
|
||||||
}
|
if( contactList[i].id == pubkey) {
|
||||||
});
|
followers.add(otherPubkey);
|
||||||
|
return;
|
||||||
usersWithContactList.forEach((x) {
|
}
|
||||||
Event? contactEvent = getContactEvent(x);
|
|
||||||
|
|
||||||
if( contactEvent != null) {
|
|
||||||
List<Contact> contacts = contactEvent.eventData.contactList;
|
|
||||||
for(int i = 0; i < contacts.length; i ++) {
|
|
||||||
if( contacts[i].id == pubkey) {
|
|
||||||
followers.add(x);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return followers;
|
return followers;
|
||||||
@@ -1411,5 +1386,4 @@ String getDirectRoomId(EventData eventData) {
|
|||||||
} else {
|
} else {
|
||||||
return eventData.pubkey;
|
return eventData.pubkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user