mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-02 11:09:30 +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));
|
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor));
|
||||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(daysToGetEventsFor));
|
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(daysToGetEventsFor));
|
||||||
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(daysToGetEventsFor)); // from relay group 2
|
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)
|
// 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:
|
case 3:
|
||||||
await createPublicChannel(node);
|
await createPublicChannel(node);
|
||||||
|
justShowedChannels = false;
|
||||||
|
|
||||||
|
// TODO put user in the newly created channel
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
@ -785,7 +788,7 @@ Future<void> addUsersToEncryptedChannel(Store node, String fullChannelId, String
|
|||||||
|
|
||||||
Future<void> encryptedChannelMenuUI(Store node) async {
|
Future<void> encryptedChannelMenuUI(Store node) async {
|
||||||
|
|
||||||
|
gSpecificDebug = 1;
|
||||||
bool continueChatMenu = true;
|
bool continueChatMenu = true;
|
||||||
|
|
||||||
bool justShowedChannels = false;
|
bool justShowedChannels = false;
|
||||||
@ -877,6 +880,7 @@ Future<void> encryptedChannelMenuUI(Store node) async {
|
|||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
await createEncryptedChannel(node);
|
await createEncryptedChannel(node);
|
||||||
|
justShowedChannels = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
@ -895,7 +899,7 @@ Future<void> PrivateMenuUI(Store node) async {
|
|||||||
bool continueChatMenu = true;
|
bool continueChatMenu = true;
|
||||||
while(continueChatMenu) {
|
while(continueChatMenu) {
|
||||||
|
|
||||||
await processAnyIncomingEvents(node); // this takes 300 ms
|
await processAnyIncomingEvents(node, true); // this takes 300 ms
|
||||||
|
|
||||||
node.printDirectRoomInfo(showAllRooms);
|
node.printDirectRoomInfo(showAllRooms);
|
||||||
|
|
||||||
@ -924,6 +928,8 @@ Future<void> PrivateMenuUI(Store node) async {
|
|||||||
}
|
}
|
||||||
int pageNum = 1;
|
int pageNum = 1;
|
||||||
while(showChannelOption) {
|
while(showChannelOption) {
|
||||||
|
|
||||||
|
|
||||||
String fullChannelId = node.showDirectRoom(directRoomId, pageNum);
|
String fullChannelId = node.showDirectRoom(directRoomId, pageNum);
|
||||||
if( fullChannelId == "") {
|
if( fullChannelId == "") {
|
||||||
printWarning("Could not find the given direct room.");
|
printWarning("Could not find the given direct room.");
|
||||||
@ -956,7 +962,9 @@ Future<void> PrivateMenuUI(Store node) async {
|
|||||||
} else {
|
} else {
|
||||||
print("Refreshing...");
|
print("Refreshing...");
|
||||||
}
|
}
|
||||||
await processAnyIncomingEvents(node);
|
|
||||||
|
await processAnyIncomingEvents(node, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import 'dart:convert' as convert;
|
|||||||
import "package:pointycastle/export.dart";
|
import "package:pointycastle/export.dart";
|
||||||
import 'package:kepler/kepler.dart';
|
import 'package:kepler/kepler.dart';
|
||||||
|
|
||||||
int gDebug = 0;
|
|
||||||
|
|
||||||
String getStrInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?"$commentColor$s$gColorEndMarker":s;
|
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);
|
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
|
int gDebug = 0;
|
||||||
|
int gSpecificDebug = 0;
|
||||||
|
|
||||||
final log = Logger('ExampleLogger');
|
final log = Logger('ExampleLogger');
|
||||||
|
|
||||||
@ -38,8 +39,8 @@ const String relayNostrInfo = 'wss://relay.nostr.info';
|
|||||||
String defaultServerUrl = "wss://relay.damus.io";
|
String defaultServerUrl = "wss://relay.damus.io";
|
||||||
|
|
||||||
List<String> gListRelayUrls1 = [ defaultServerUrl,
|
List<String> gListRelayUrls1 = [ defaultServerUrl,
|
||||||
relayNostrInfo
|
relayNostrInfo,
|
||||||
// "wss://nostr-verified.wellorder.net"
|
"wss://nostr-verified.wellorder.net"
|
||||||
];
|
];
|
||||||
|
|
||||||
List<String> gListRelayUrls2 = [
|
List<String> gListRelayUrls2 = [
|
||||||
|
@ -21,11 +21,18 @@ bool selectorShowAllRooms(ScrollableMessages room) {
|
|||||||
|
|
||||||
bool showAllRooms (ScrollableMessages room) => selectorShowAllRooms(room);
|
bool showAllRooms (ScrollableMessages room) => selectorShowAllRooms(room);
|
||||||
|
|
||||||
int getLatestMessageTime(List<String> _messageIds) {
|
int getLatestMessageTime(ScrollableMessages channel) {
|
||||||
if( _messageIds.length <= 0 || gStore == null) {
|
|
||||||
|
List<String> _messageIds = channel.messageIds;
|
||||||
|
if(gStore == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(_messageIds.length == 0) {
|
||||||
|
int createdAt = channel.createdAt;
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
int latest = 0;
|
int latest = 0;
|
||||||
for(int i = 0; i < _messageIds.length; i++) {
|
for(int i = 0; i < _messageIds.length; i++) {
|
||||||
if( gStore != null) {
|
if( gStore != null) {
|
||||||
@ -65,8 +72,8 @@ int scrollableCompareTo(ScrollableMessages a, ScrollableMessages b) {
|
|||||||
if( gStore == null)
|
if( gStore == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int otherLatest = getLatestMessageTime(b.messageIds);
|
int otherLatest = getLatestMessageTime(b);
|
||||||
int thisLatest = getLatestMessageTime(a.messageIds);
|
int thisLatest = getLatestMessageTime(a);
|
||||||
|
|
||||||
if( thisLatest < otherLatest) {
|
if( thisLatest < otherLatest) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -82,8 +89,9 @@ int scrollableCompareTo(ScrollableMessages a, ScrollableMessages b) {
|
|||||||
class ScrollableMessages {
|
class ScrollableMessages {
|
||||||
String topHeader;
|
String topHeader;
|
||||||
List<String> messageIds;
|
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) {
|
void addMessageToRoom(String messageId, Map<String, Tree> tempChildEventsMap) {
|
||||||
int newEventTime = (tempChildEventsMap[messageId]?.event.eventData.createdAt??0);
|
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) :
|
Channel(this.channelId, this.internalChatRoomName, this.about, this.picture, List<String> messageIds, this.participants, this.lastUpdated) :
|
||||||
super ( internalChatRoomName.isEmpty? channelId: internalChatRoomName + "( " + channelId + " )" ,
|
super ( internalChatRoomName.isEmpty? channelId: internalChatRoomName + "( " + channelId + " )" ,
|
||||||
messageIds);
|
messageIds,
|
||||||
|
lastUpdated);
|
||||||
|
|
||||||
|
String getChannelId() {
|
||||||
|
return channelId;
|
||||||
|
}
|
||||||
|
|
||||||
String get chatRoomName {
|
String get chatRoomName {
|
||||||
return internalChatRoomName;
|
return internalChatRoomName;
|
||||||
@ -214,11 +226,16 @@ class Channel extends ScrollableMessages {
|
|||||||
|
|
||||||
class DirectMessageRoom extends ScrollableMessages{
|
class DirectMessageRoom extends ScrollableMessages{
|
||||||
String otherPubkey; // id of user this DM is happening
|
String otherPubkey; // id of user this DM is happening
|
||||||
|
int createdAt;
|
||||||
|
|
||||||
DirectMessageRoom(this.otherPubkey, List<String> messageIds):
|
DirectMessageRoom(this.otherPubkey, List<String> messageIds, this.createdAt):
|
||||||
super ( "${getAuthorName(otherPubkey)} ($otherPubkey)", messageIds) {
|
super ( "${getAuthorName(otherPubkey)} ($otherPubkey)", messageIds, createdAt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getChannelId() {
|
||||||
|
return otherPubkey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isPrivateMessageRoom() {
|
bool isPrivateMessageRoom() {
|
||||||
return false;
|
return false;
|
||||||
@ -757,7 +774,7 @@ class Store {
|
|||||||
} else {
|
} else {
|
||||||
List<String> temp = [];
|
List<String> temp = [];
|
||||||
temp.add(eId);
|
temp.add(eId);
|
||||||
DirectMessageRoom newDirectRoom= DirectMessageRoom(directRoomId, temp);
|
DirectMessageRoom newDirectRoom= DirectMessageRoom(directRoomId, temp, ce.eventData.createdAt);
|
||||||
directRooms.add( newDirectRoom);
|
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}.");
|
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 = [];
|
List<String> temp = [];
|
||||||
temp.add(newTree.event.eventData.id);
|
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;
|
break;
|
||||||
|
|
||||||
@ -1528,23 +1545,26 @@ class Store {
|
|||||||
|
|
||||||
if( lookedUpName.length == 1) {
|
if( lookedUpName.length == 1) {
|
||||||
DirectMessageRoom? room = getDirectRoom(directRooms, lookedUpName.first);
|
DirectMessageRoom? room = getDirectRoom(directRooms, lookedUpName.first);
|
||||||
if( room != null) {
|
if( room != null) {// room is already created, use it
|
||||||
room.printDirectMessageRoom(this, page);
|
room.printDirectMessageRoom(this, page);
|
||||||
return lookedUpName.first;
|
return lookedUpName.first;
|
||||||
} else {
|
} 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}");
|
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;
|
return directRoomId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if( lookedUpName.length > 0)
|
if( lookedUpName.length > 0) {
|
||||||
print("Got more than one public id for the name given, which are: ${lookedUpName.length}");
|
print("Got more than one public id for the name given, which are: ${lookedUpName.length}");
|
||||||
else {
|
}
|
||||||
|
else { // in case the given id is not present in our global list of usernames, create new room for them
|
||||||
if( isValidPubkey(directRoomId)) {
|
if( isValidPubkey(directRoomId)) {
|
||||||
print("Could not find a conversation or room with the given id. Creating one with $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;
|
return directRoomId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1553,8 +1573,11 @@ class Store {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void createDirectRoom(String directRoomId) {
|
DirectMessageRoom createDirectRoom(String directRoomId) {
|
||||||
directRooms.add(DirectMessageRoom(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
|
// 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
|
homepage: https://github.com/vishalxl/nostr_console
|
||||||
|
|
||||||
# Release 0.0.9 - encrypted channels; fixes
|
# Release 0.0.9 - encrypted channels; fixes
|
||||||
# spam
|
# improved fetching of events. and display for channels.
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.17.3 <3.0.0'
|
sdk: '>=2.17.3 <3.0.0'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user