mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Add cli option to include text of last received message
This commit is contained in:
parent
8ee7245881
commit
c5d6579397
26
meshms_cli.c
26
meshms_cli.c
@ -13,7 +13,7 @@
|
||||
// output the list of existing conversations for a given local identity
|
||||
DEFINE_CMD(app_meshms_conversations, 0,
|
||||
"List MeshMS threads that include <sid>",
|
||||
"meshms","list","conversations" KEYRING_PIN_OPTIONS, "<sid>","[<offset>]","[<count>]");
|
||||
"meshms","list","conversations" KEYRING_PIN_OPTIONS, "[--include-message]", "<sid>","[<offset>]","[<count>]");
|
||||
static int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
const char *sidhex, *offset_str, *count_str;
|
||||
@ -22,6 +22,7 @@ static int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_
|
||||
|| cli_arg(parsed, "count", &count_str, NULL, "-1")==-1)
|
||||
return -1;
|
||||
|
||||
int include_message = cli_arg(parsed, "--include-message", NULL, NULL, NULL) == 0;
|
||||
sid_t sid;
|
||||
struct meshms_conversations *conv = NULL;
|
||||
enum meshms_status status = MESHMS_STATUS_ERROR;
|
||||
@ -42,10 +43,10 @@ static int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_
|
||||
goto end;
|
||||
|
||||
const char *names[]={
|
||||
"_id","recipient","read", "last_message", "read_offset"
|
||||
"_id","recipient","read", "last_message", "read_offset", "message"
|
||||
};
|
||||
|
||||
cli_columns(context, 5, names);
|
||||
cli_columns(context, include_message? 6: 5, names);
|
||||
int rows = 0;
|
||||
if (conv) {
|
||||
struct meshms_conversation_iterator it;
|
||||
@ -58,7 +59,24 @@ static int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_
|
||||
cli_put_hexvalue(context, it.current->them.binary, sizeof(it.current->them), ":");
|
||||
cli_put_string(context, it.current->read_offset < it.current->their_last_message ? "unread":"", ":");
|
||||
cli_put_long(context, it.current->their_last_message, ":");
|
||||
cli_put_long(context, it.current->read_offset, "\n");
|
||||
cli_put_long(context, it.current->read_offset, include_message?":":"\n");
|
||||
if (include_message){
|
||||
int output = 0;
|
||||
if (it.current->their_last_message && it.current->their_ply.found){
|
||||
struct message_ply_read reader;
|
||||
bzero(&reader, sizeof reader);
|
||||
if (message_ply_read_open(&reader, &it.current->their_ply.bundle_id) == 0){
|
||||
reader.read.offset = it.current->their_last_message;
|
||||
if (message_ply_read_prev(&reader)==0){
|
||||
cli_put_string(context, (const char *)reader.record, "\n");
|
||||
output = 1;
|
||||
}
|
||||
message_ply_read_close(&reader);
|
||||
}
|
||||
}
|
||||
if (!output)
|
||||
cli_put_string(context, "", "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1186,8 +1186,10 @@ ssize_t rhizome_read_buffered(struct rhizome_read *read, struct rhizome_read_buf
|
||||
while (len>0){
|
||||
//DEBUGF(rhizome_store, "len=%zu read->length=%"PRIu64" read->offset=%"PRIu64" buffer->offset=%"PRIu64"", len, read->length, read->offset, buffer->offset);
|
||||
// make sure we only attempt to read data that actually exists
|
||||
if (read->length != RHIZOME_SIZE_UNSET && read->offset + len > read->length)
|
||||
if (read->length != RHIZOME_SIZE_UNSET && read->offset + len > read->length){
|
||||
assert(read->offset <= read->length);
|
||||
len = read->length - read->offset;
|
||||
}
|
||||
|
||||
// if we can supply either the beginning or end of the data from cache, do that first.
|
||||
if (read->offset >= buffer->offset) {
|
||||
|
12
tests/meshms
12
tests/meshms
@ -206,13 +206,13 @@ setup_listConversations() {
|
||||
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message4"
|
||||
}
|
||||
test_listConversations() {
|
||||
executeOk_servald meshms list conversations $SIDA1
|
||||
executeOk_servald meshms list conversations --include-message $SIDA1
|
||||
tfw_cat --stdout
|
||||
assertStdoutIs --stderr --line=1 -e '5\n'
|
||||
assertStdoutIs --stderr --line=2 -e '_id:recipient:read:last_message:read_offset\n'
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0\$"
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA3:unread:11:0\$"
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA4:unread:20:0\$"
|
||||
assertStdoutIs --stderr --line=1 -e '6\n'
|
||||
assertStdoutIs --stderr --line=2 -e '_id:recipient:read:last_message:read_offset:message\n'
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0:\$"
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA3:unread:11:0:Message2\$"
|
||||
assertStdoutGrep --stderr --matches=1 ":$SIDA4:unread:20:0:Message4\$"
|
||||
assertStdoutLineCount '==' 5
|
||||
executeOk_servald meshms list conversations $SIDA1 1
|
||||
tfw_cat --stderr
|
||||
|
Loading…
x
Reference in New Issue
Block a user