mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-05-28 13:09:57 +02:00
improved ordering of channel display
.. by correctly placing empty channels depending on their creation date. improved kind 0,3 fetching. improved display around channel menu and printNotifications.
This commit is contained in:
parent
212df566c6
commit
c37e2b038f
@ -262,7 +262,8 @@ Future<void> main(List<String> arguments) async {
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor));
|
||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(daysToGetEventsFor));
|
||||
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor)); // from relay group 2
|
||||
getKindEvents([0, 3, 40, 42, 140, 141, 142], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor* 100)); // get all type 3 etc
|
||||
getKindEvents([0, 3], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor* 100)); // get all type 3 etc
|
||||
getKindEvents([40, 42, 140, 141, 142], gListRelayUrls1, gLimitPerSubscription * 3, getSecondsDaysAgo(daysToGetEventsFor)); // get all type 3 etc
|
||||
|
||||
// TODO get all 40 events, and then get all #e for them ( responses to them)
|
||||
|
||||
|
@ -637,6 +637,9 @@ Future<void> channelMenuUI(Store node) async {
|
||||
|
||||
case 3:
|
||||
await createPublicChannel(node);
|
||||
justShowedChannels = false;
|
||||
|
||||
// TODO put user in the newly created channel
|
||||
break;
|
||||
|
||||
case 4:
|
||||
@ -785,7 +788,7 @@ Future<void> addUsersToEncryptedChannel(Store node, String fullChannelId, String
|
||||
|
||||
Future<void> encryptedChannelMenuUI(Store node) async {
|
||||
|
||||
|
||||
gSpecificDebug = 1;
|
||||
bool continueChatMenu = true;
|
||||
|
||||
bool justShowedChannels = false;
|
||||
@ -877,6 +880,7 @@ Future<void> encryptedChannelMenuUI(Store node) async {
|
||||
|
||||
case 3:
|
||||
await createEncryptedChannel(node);
|
||||
justShowedChannels = false;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
@ -895,7 +899,7 @@ Future<void> PrivateMenuUI(Store node) async {
|
||||
bool continueChatMenu = true;
|
||||
while(continueChatMenu) {
|
||||
|
||||
await processAnyIncomingEvents(node); // this takes 300 ms
|
||||
await processAnyIncomingEvents(node, true); // this takes 300 ms
|
||||
|
||||
node.printDirectRoomInfo(showAllRooms);
|
||||
|
||||
@ -924,6 +928,8 @@ Future<void> PrivateMenuUI(Store node) async {
|
||||
}
|
||||
int pageNum = 1;
|
||||
while(showChannelOption) {
|
||||
|
||||
|
||||
String fullChannelId = node.showDirectRoom(directRoomId, pageNum);
|
||||
if( fullChannelId == "") {
|
||||
printWarning("Could not find the given direct room.");
|
||||
@ -956,7 +962,9 @@ Future<void> PrivateMenuUI(Store node) async {
|
||||
} else {
|
||||
print("Refreshing...");
|
||||
}
|
||||
await processAnyIncomingEvents(node);
|
||||
|
||||
await processAnyIncomingEvents(node, false);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -12,7 +12,6 @@ import 'dart:convert' as convert;
|
||||
import "package:pointycastle/export.dart";
|
||||
import 'package:kepler/kepler.dart';
|
||||
|
||||
int gDebug = 0;
|
||||
|
||||
String getStrInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?"$commentColor$s$gColorEndMarker":s;
|
||||
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
||||
|
@ -1,7 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
|
||||
int gDebug = 0;
|
||||
int gSpecificDebug = 0;
|
||||
|
||||
final log = Logger('ExampleLogger');
|
||||
|
||||
@ -38,8 +39,8 @@ const String relayNostrInfo = 'wss://relay.nostr.info';
|
||||
String defaultServerUrl = "wss://relay.damus.io";
|
||||
|
||||
List<String> gListRelayUrls1 = [ defaultServerUrl,
|
||||
relayNostrInfo
|
||||
// "wss://nostr-verified.wellorder.net"
|
||||
relayNostrInfo,
|
||||
"wss://nostr-verified.wellorder.net"
|
||||
];
|
||||
|
||||
List<String> gListRelayUrls2 = [
|
||||
|
@ -21,11 +21,18 @@ bool selectorShowAllRooms(ScrollableMessages room) {
|
||||
|
||||
bool showAllRooms (ScrollableMessages room) => selectorShowAllRooms(room);
|
||||
|
||||
int getLatestMessageTime(List<String> _messageIds) {
|
||||
if( _messageIds.length <= 0 || gStore == null) {
|
||||
int getLatestMessageTime(ScrollableMessages channel) {
|
||||
|
||||
List<String> _messageIds = channel.messageIds;
|
||||
if(gStore == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(_messageIds.length == 0) {
|
||||
int createdAt = channel.createdAt;
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
int latest = 0;
|
||||
for(int i = 0; i < _messageIds.length; i++) {
|
||||
if( gStore != null) {
|
||||
@ -65,8 +72,8 @@ int scrollableCompareTo(ScrollableMessages a, ScrollableMessages b) {
|
||||
if( gStore == null)
|
||||
return 0;
|
||||
|
||||
int otherLatest = getLatestMessageTime(b.messageIds);
|
||||
int thisLatest = getLatestMessageTime(a.messageIds);
|
||||
int otherLatest = getLatestMessageTime(b);
|
||||
int thisLatest = getLatestMessageTime(a);
|
||||
|
||||
if( thisLatest < otherLatest) {
|
||||
return 1;
|
||||
@ -82,8 +89,9 @@ int scrollableCompareTo(ScrollableMessages a, ScrollableMessages b) {
|
||||
class ScrollableMessages {
|
||||
String topHeader;
|
||||
List<String> messageIds;
|
||||
int createdAt;
|
||||
|
||||
ScrollableMessages(this.topHeader, this.messageIds);
|
||||
ScrollableMessages(this.topHeader, this.messageIds, this.createdAt);
|
||||
|
||||
void addMessageToRoom(String messageId, Map<String, Tree> tempChildEventsMap) {
|
||||
int newEventTime = (tempChildEventsMap[messageId]?.event.eventData.createdAt??0);
|
||||
@ -175,8 +183,12 @@ class Channel extends ScrollableMessages {
|
||||
|
||||
Channel(this.channelId, this.internalChatRoomName, this.about, this.picture, List<String> messageIds, this.participants, this.lastUpdated) :
|
||||
super ( internalChatRoomName.isEmpty? channelId: internalChatRoomName + "( " + channelId + " )" ,
|
||||
messageIds);
|
||||
messageIds,
|
||||
lastUpdated);
|
||||
|
||||
String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
String get chatRoomName {
|
||||
return internalChatRoomName;
|
||||
@ -214,11 +226,16 @@ class Channel extends ScrollableMessages {
|
||||
|
||||
class DirectMessageRoom extends ScrollableMessages{
|
||||
String otherPubkey; // id of user this DM is happening
|
||||
int createdAt;
|
||||
|
||||
DirectMessageRoom(this.otherPubkey, List<String> messageIds):
|
||||
super ( "${getAuthorName(otherPubkey)} ($otherPubkey)", messageIds) {
|
||||
DirectMessageRoom(this.otherPubkey, List<String> messageIds, this.createdAt):
|
||||
super ( "${getAuthorName(otherPubkey)} ($otherPubkey)", messageIds, createdAt) {
|
||||
}
|
||||
|
||||
String getChannelId() {
|
||||
return otherPubkey;
|
||||
}
|
||||
|
||||
|
||||
bool isPrivateMessageRoom() {
|
||||
return false;
|
||||
@ -757,7 +774,7 @@ class Store {
|
||||
} else {
|
||||
List<String> temp = [];
|
||||
temp.add(eId);
|
||||
DirectMessageRoom newDirectRoom= DirectMessageRoom(directRoomId, temp);
|
||||
DirectMessageRoom newDirectRoom= DirectMessageRoom(directRoomId, temp, ce.eventData.createdAt);
|
||||
directRooms.add( newDirectRoom);
|
||||
if( ce.eventData.id == gCheckEventId && gDebug >= 0) print("Adding new message ${ce.eventData.id} to NEW direct room $directRoomId. sender pubkey = ${ce.eventData.pubkey}.");
|
||||
}
|
||||
@ -1042,7 +1059,7 @@ class Store {
|
||||
|
||||
List<String> temp = [];
|
||||
temp.add(newTree.event.eventData.id);
|
||||
directRooms.add(DirectMessageRoom(directRoomId, temp)); // TODO sort it
|
||||
directRooms.add(DirectMessageRoom(directRoomId, temp, newTree.event.eventData.createdAt)); // TODO sort it
|
||||
|
||||
break;
|
||||
|
||||
@ -1528,23 +1545,26 @@ class Store {
|
||||
|
||||
if( lookedUpName.length == 1) {
|
||||
DirectMessageRoom? room = getDirectRoom(directRooms, lookedUpName.first);
|
||||
if( room != null) {
|
||||
if( room != null) {// room is already created, use it
|
||||
room.printDirectMessageRoom(this, page);
|
||||
return lookedUpName.first;
|
||||
} else {
|
||||
if( isValidPubkey(lookedUpName.first)) {
|
||||
if( isValidPubkey(lookedUpName.first)) { // in case the pubkey is valid and we have seen the pubkey in global author list, create new room
|
||||
print("Could not find a conversation or room with the given id. Creating one with ${lookedUpName.first}");
|
||||
createDirectRoom( directRoomId);
|
||||
DirectMessageRoom room = createDirectRoom( directRoomId);
|
||||
room.printDirectMessageRoom(this, page);
|
||||
return directRoomId;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( lookedUpName.length > 0)
|
||||
print("Got more than one public id for the name given, which are: ${lookedUpName.length}");
|
||||
else {
|
||||
if( lookedUpName.length > 0) {
|
||||
print("Got more than one public id for the name given, which are: ${lookedUpName.length}");
|
||||
}
|
||||
else { // in case the given id is not present in our global list of usernames, create new room for them
|
||||
if( isValidPubkey(directRoomId)) {
|
||||
print("Could not find a conversation or room with the given id. Creating one with $directRoomId");
|
||||
createDirectRoom(directRoomId);
|
||||
DirectMessageRoom room = createDirectRoom(directRoomId);
|
||||
room.printDirectMessageRoom(this, page);
|
||||
return directRoomId;
|
||||
}
|
||||
}
|
||||
@ -1553,8 +1573,11 @@ class Store {
|
||||
return "";
|
||||
}
|
||||
|
||||
void createDirectRoom(String directRoomId) {
|
||||
directRooms.add(DirectMessageRoom(directRoomId, []));
|
||||
DirectMessageRoom createDirectRoom(String directRoomId) {
|
||||
int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000;
|
||||
DirectMessageRoom room = DirectMessageRoom(directRoomId, [], createdAt);
|
||||
directRooms.add(room);
|
||||
return room;
|
||||
}
|
||||
|
||||
// Write the tree's events to file as one event's json per line
|
||||
|
@ -4,7 +4,7 @@ version: 0.0.9-beta
|
||||
homepage: https://github.com/vishalxl/nostr_console
|
||||
|
||||
# Release 0.0.9 - encrypted channels; fixes
|
||||
# spam
|
||||
# improved fetching of events. and display for channels.
|
||||
|
||||
environment:
|
||||
sdk: '>=2.17.3 <3.0.0'
|
||||
|
Loading…
x
Reference in New Issue
Block a user