Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
rename fn call to list_messages_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
zo-el committed Nov 8, 2021
1 parent c43eccf commit a741dbf
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 205 deletions.
12 changes: 6 additions & 6 deletions tests/src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ module.exports = async (orchestrator) => {

// Alice lists the messages
const getTimestamp = () => (Date.now() * 1000)
let alices_view = await alice_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })
let alices_view = await alice_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })

let bobbos_view = await bobbo_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })
let bobbos_view = await bobbo_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })

if (alices_view.messages.length !== 2) {
await delay(10000)
console.log("Trying again...");

alices_view = await alice_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })
alices_view = await alice_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })

bobbos_view = await bobbo_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })
bobbos_view = await bobbo_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 2 })
}
t.deepEqual(alices_view.messages.length, 2)
t.deepEqual(bobbos_view.messages.length, 2)
Expand Down Expand Up @@ -116,9 +116,9 @@ module.exports = async (orchestrator) => {
t.deepEqual(sends[3].entry, recvs[3].entry);
await delay(4000)
// Alice lists the messages
alices_view = await alice_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 20 })
alices_view = await alice_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 20 })
// Bobbo lists the messages
bobbos_view = await bobbo_chat.call('chat', 'list_page_messages', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 10 })
bobbos_view = await bobbo_chat.call('chat', 'list_messages_batch', { channel: channel.entry, active_chatter: false, earlier_than: getTimestamp(), target_message_count: 10 })
bobbos_view.messages.forEach(msg => {
console.log(">>>>>>>", msg.entry);
});
Expand Down
2 changes: 1 addition & 1 deletion zomes/chat/src/entries/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct ListMessagesInput {
}
/// Input to the list messages call
#[derive(Debug, Clone, Serialize, Deserialize, SerializedBytes)]
pub struct ListMessagesPageInput {
pub struct ListMessagesBatchInput {
channel: Channel,
earlier_than: Timestamp,
// Keep expanding search interval until this count is reached
Expand Down
8 changes: 4 additions & 4 deletions zomes/chat/src/entries/message/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use link::Link;
use metadata::EntryDetails;

use super::{
ActiveChatters, LastSeen, LastSeenKey, ListMessages, ListMessagesInput, ListMessagesPageInput,
ActiveChatters, LastSeen, LastSeenKey, ListMessages, ListMessagesBatchInput, ListMessagesInput,
MessageData, SigResults, SignalMessageData, SignalSpecificInput,
};

Expand Down Expand Up @@ -58,10 +58,10 @@ pub(crate) fn create_message(message_input: MessageInput) -> ChatResult<MessageD
}

/// Using batching to List all the messages on this channel
pub(crate) fn list_page_messages(
list_message_input: ListMessagesPageInput,
pub(crate) fn list_messages_batch(
list_message_input: ListMessagesBatchInput,
) -> ChatResult<ListMessages> {
let ListMessagesPageInput {
let ListMessagesBatchInput {
channel,
earlier_than,
target_message_count,
Expand Down
6 changes: 3 additions & 3 deletions zomes/chat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use hc_joining_code;
pub use hdk::prelude::Path;
pub use hdk::prelude::*;
pub use message::{
ActiveChatters, ListMessages, ListMessagesInput, ListMessagesPageInput, Message, MessageData,
ActiveChatters, ListMessages, ListMessagesBatchInput, ListMessagesInput, Message, MessageData,
MessageInput, SigResults, SignalMessageData, SignalSpecificInput,
};
pub mod entries;
Expand Down Expand Up @@ -148,8 +148,8 @@ fn list_messages(list_messages_input: ListMessagesInput) -> ExternResult<ListMes
}

#[hdk_extern]
fn list_page_messages(list_messages_input: ListMessagesPageInput) -> ExternResult<ListMessages> {
Ok(message::handlers::list_page_messages(list_messages_input)?)
fn list_messages_batch(list_messages_input: ListMessagesBatchInput) -> ExternResult<ListMessages> {
Ok(message::handlers::list_messages_batch(list_messages_input)?)
}

#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion zomes/chat/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn set_read_only_cap_tokens() -> ExternResult<()> {
functions.insert((zome_info()?.zome_name, "get_active_chatters".into()));
functions.insert((zome_info()?.zome_name, "list_channels".into()));
functions.insert((zome_info()?.zome_name, "list_messages".into()));
functions.insert((zome_info()?.zome_name, "list_page_messages".into()));
functions.insert((zome_info()?.zome_name, "list_messages_batch".into()));
functions.insert((zome_info()?.zome_name, "list_all_messages".into()));
functions.insert((zome_info()?.zome_name, "stats".into()));
functions.insert((zome_info()?.zome_name, "agent_stats".into()));
Expand Down
Loading

0 comments on commit a741dbf

Please sign in to comment.