Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dnas/relay/zomes/coordinator/relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use relay_integrity::*;
#[serde(tag = "signal_type")]
pub enum RemoteSignalPayload {
Message(MessageRecord),
MessageUpdated(MessageRecord),
PeerPing { from_agent: AgentPubKey },
PeerPong { from_agent: AgentPubKey },
}
Expand Down Expand Up @@ -46,6 +47,21 @@ fn recv_remote_signal(payload: RemoteSignalPayload) -> ExternResult<()> {
)))
}
}
RemoteSignalPayload::MessageUpdated(message_record) => {
let info: CallInfo = call_info()?;
if let Some(message) = message_record.message {
emit_signal(Signal::MessageUpdated {
action: message_record.signed_action.clone(),
original_action: message_record.original_action.clone(),
message,
from: info.provenance,
})
} else {
Err(wasm_error!(WasmErrorInner::Guest(
"Invalid message record".to_string()
)))
}
}
RemoteSignalPayload::PeerPing { from_agent } => {
ping::handle_peer_ping(from_agent)
}
Expand Down Expand Up @@ -81,6 +97,12 @@ pub enum Signal {
original_action: ActionHash,
from: AgentPubKey,
},
MessageUpdated {
action: SignedActionHashed,
original_action: ActionHash,
message: Message,
from: AgentPubKey,
},
PeerPing {
from_agent: AgentPubKey,
},
Expand Down
20 changes: 20 additions & 0 deletions dnas/relay/zomes/coordinator/relay/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ pub struct UpdateMessageInput {
pub original_message_hash: ActionHash,
pub previous_message_hash: ActionHash,
pub updated_message: Message,
// Agents to notify of the edit so they update their copy in real time.
pub agents: Vec<AgentPubKey>,
}
#[hdk_extern]
pub fn update_message(input: UpdateMessageInput) -> ExternResult<Record> {
Expand All @@ -267,6 +269,24 @@ pub fn update_message(input: UpdateMessageInput) -> ExternResult<Record> {
let record = get(updated_message_hash.clone(), GetOptions::local())?.ok_or(wasm_error!(
WasmErrorInner::Guest("Could not find the newly updated Message".to_string())
))?;

// Broadcast the edit, keyed by the original message so peers can replace the
// message they already have rather than treat it as a new one.
let my_pub_key = agent_info()?.agent_initial_pubkey;
let agents: Vec<AgentPubKey> = input
.agents
.into_iter()
.filter(|a| a != &my_pub_key)
.collect();
let _ = send_remote_signal(
crate::RemoteSignalPayload::MessageUpdated(MessageRecord {
message: Some(input.updated_message),
original_action: input.original_message_hash,
signed_action: record.signed_action().clone(),
}),
agents,
);

Ok(record)
}

Expand Down
3 changes: 3 additions & 0 deletions dnas/relay/zomes/integrity/relay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use hdi::prelude::*;
pub struct Config {
pub title: String,
pub image: String,
// Optional so configs written before this field existed still deserialize.
#[serde(default)]
pub description: Option<String>,
}
pub fn validate_create_config(
_action: TypedAction<EntryCreationData>,
Expand Down
3 changes: 3 additions & 0 deletions dnas/relay/zomes/integrity/relay/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub struct Message {
pub bucket: u32,
pub images: Vec<File>,
pub message_type: MessageType,
// Set when the message was forwarded from another conversation.
#[serde(default)]
pub forwarded: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions tests/src/relay/relay/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function sampleConfig(cell: CallableCell, partialConfig = {}) {
...{
title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
image: "",
description: null,
},
...partialConfig
};
Expand All @@ -30,6 +31,7 @@ export async function sampleMessage(cell: CallableCell, partialMessage = {}) {
bucket: 0,
images: [],
message_type: "User",
forwarded: null,
},
...partialMessage
};
Expand Down
2 changes: 2 additions & 0 deletions tests/src/relay/relay/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ test('create and update Message', async () => {
original_message_hash: originalActionHash,
previous_message_hash: originalActionHash,
updated_message: contentUpdate,
agents: [],
};

let updatedRecord: Record = await alice.cells[0].callZome({
Expand All @@ -133,6 +134,7 @@ test('create and update Message', async () => {
original_message_hash: originalActionHash,
previous_message_hash: updatedRecord.signed_action.hashed.hash,
updated_message: contentUpdate,
agents: [],
};

updatedRecord = await alice.cells[0].callZome({
Expand Down
8 changes: 8 additions & 0 deletions ui/src/lib/svgIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export const svgIcons: { [key: string]: string } = {
'<svg width="100%" height="100%" fill="currentColor" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 17.5H17.5C17.8315 17.5 18.1495 17.3683 18.3839 17.1339C18.6183 16.8995 18.75 16.5815 18.75 16.25C18.75 15.9185 18.6183 15.6005 18.3839 15.3661C18.1495 15.1317 17.8315 15 17.5 15H12.5C12.1685 15 11.8505 15.1317 11.6161 15.3661C11.3817 15.6005 11.25 15.9185 11.25 16.25C11.25 16.5815 11.3817 16.8995 11.6161 17.1339C11.8505 17.3683 12.1685 17.5 12.5 17.5ZM23.75 3.75H6.25C5.25544 3.75 4.30161 4.14509 3.59835 4.84835C2.89509 5.55161 2.5 6.50544 2.5 7.5V11.25C2.5 11.5815 2.6317 11.8995 2.86612 12.1339C3.10054 12.3683 3.41848 12.5 3.75 12.5H5V22.5C5 23.4946 5.39509 24.4484 6.09835 25.1517C6.80161 25.8549 7.75544 26.25 8.75 26.25H21.25C22.2446 26.25 23.1984 25.8549 23.9017 25.1517C24.6049 24.4484 25 23.4946 25 22.5V12.5H26.25C26.5815 12.5 26.8995 12.3683 27.1339 12.1339C27.3683 11.8995 27.5 11.5815 27.5 11.25V7.5C27.5 6.50544 27.1049 5.55161 26.4017 4.84835C25.6984 4.14509 24.7446 3.75 23.75 3.75ZM22.5 22.5C22.5 22.8315 22.3683 23.1495 22.1339 23.3839C21.8995 23.6183 21.5815 23.75 21.25 23.75H8.75C8.41848 23.75 8.10054 23.6183 7.86612 23.3839C7.6317 23.1495 7.5 22.8315 7.5 22.5V12.5H22.5V22.5ZM25 10H5V7.5C5 7.16848 5.1317 6.85054 5.36612 6.61612C5.60054 6.3817 5.91848 6.25 6.25 6.25H23.75C24.0815 6.25 24.3995 6.3817 24.6339 6.61612C24.8683 6.85054 25 7.16848 25 7.5V10Z" /></svg>',
arrowRight:
'<svg width="100%" height="100%" fill="currentColor" viewBox="0 0 42 42" xmlns="http://www.w3.org/2000/svg"><path d="M31.36 20.335C31.2767 20.1202 31.1518 19.924 30.9925 19.7575L22.2425 11.0075C22.0793 10.8444 21.8856 10.7149 21.6724 10.6266C21.4592 10.5383 21.2308 10.4929 21 10.4929C20.534 10.4929 20.087 10.678 19.7575 11.0075C19.5943 11.1707 19.4649 11.3644 19.3766 11.5776C19.2883 11.7908 19.2428 12.0193 19.2428 12.25C19.2428 12.716 19.428 13.163 19.7575 13.4925L25.5325 19.25H12.25C11.7859 19.25 11.3408 19.4344 11.0126 19.7626C10.6844 20.0908 10.5 20.5359 10.5 21C10.5 21.4641 10.6844 21.9093 11.0126 22.2375C11.3408 22.5656 11.7859 22.75 12.25 22.75H25.5325L19.7575 28.5075C19.5935 28.6702 19.4633 28.8638 19.3744 29.077C19.2856 29.2903 19.2399 29.519 19.2399 29.75C19.2399 29.981 19.2856 30.2098 19.3744 30.423C19.4633 30.6363 19.5935 30.8298 19.7575 30.9925C19.9202 31.1565 20.1137 31.2867 20.327 31.3756C20.5402 31.4644 20.769 31.5102 21 31.5102C21.231 31.5102 21.4598 31.4644 21.673 31.3756C21.8863 31.2867 22.0798 31.1565 22.2425 30.9925L30.9925 22.2425C31.1518 22.0761 31.2767 21.8798 31.36 21.665C31.535 21.239 31.535 20.7611 31.36 20.335Z" /></svg>',
bell:
'<svg width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9" /><path d="M13.73 21a2 2 0 0 1-3.46 0" /></svg>',
bellOff:
'<svg width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M13.73 21a2 2 0 0 1-3.46 0" /><path d="M18.63 13A17.89 17.89 0 0 1 18 8" /><path d="M6.26 6.26A5.86 5.86 0 0 0 6 8c0 7-3 9-3 9h14" /><path d="M18 8a6 6 0 0 0-9.33-5" /><line x1="1" y1="1" x2="23" y2="23" /></svg>',
star:
'<svg width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" /></svg>',
starFilled:
'<svg width="100%" height="100%" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" /></svg>',
betaTag:
'<svg width="100%" height="100%" fill="currentColor" viewBox="0 0 28 14" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M26 1H2C1.44772 1 1 1.44772 1 2V12C1 12.5523 1.44772 13 2 13H26C26.5523 13 27 12.5523 27 12V2C27 1.44772 26.5523 1 26 1ZM2 0C0.895431 0 0 0.89543 0 2V12C0 13.1046 0.895431 14 2 14H26C27.1046 14 28 13.1046 28 12V2C28 0.895431 27.1046 0 26 0H2Z" /><path d="M20.8917 10.8142C20.5316 10.8142 20.2106 10.7518 19.9289 10.6268C19.6472 10.4994 19.4243 10.312 19.2601 10.0646C19.0984 9.81469 19.0176 9.50357 19.0176 9.13119C19.0176 8.81761 19.0751 8.55426 19.1903 8.34112C19.3054 8.12798 19.4622 7.9565 19.6607 7.82665C19.8591 7.69681 20.0845 7.59882 20.3368 7.53267C20.5916 7.46653 20.8586 7.41998 21.1379 7.39303C21.4662 7.35874 21.7308 7.32689 21.9317 7.29749C22.1325 7.26564 22.2783 7.2191 22.369 7.15785C22.4596 7.0966 22.5049 7.00596 22.5049 6.88592V6.86387C22.5049 6.63114 22.4314 6.45107 22.2844 6.32368C22.1399 6.19629 21.9341 6.13259 21.6671 6.13259C21.3853 6.13259 21.1612 6.19506 20.9946 6.32001C20.828 6.4425 20.7178 6.59684 20.6639 6.78302L19.216 6.66543C19.2895 6.32246 19.4341 6.02603 19.6496 5.77614C19.8652 5.52381 20.1433 5.33027 20.4838 5.19553C20.8268 5.05834 21.2237 4.98975 21.6744 4.98975C21.988 4.98975 22.2881 5.02649 22.5747 5.09999C22.8638 5.17348 23.1198 5.2874 23.3428 5.44174C23.5681 5.59608 23.7458 5.79452 23.8756 6.03705C24.0054 6.27713 24.0704 6.56499 24.0704 6.90062V10.7077H22.5858V9.92494H22.5417C22.451 10.1013 22.3298 10.2569 22.1779 10.3916C22.026 10.5239 21.8435 10.628 21.6303 10.704C21.4172 10.7775 21.171 10.8142 20.8917 10.8142ZM21.34 9.73385C21.5703 9.73385 21.7736 9.68853 21.95 9.59788C22.1264 9.50479 22.2648 9.37985 22.3653 9.22306C22.4657 9.06627 22.5159 8.88866 22.5159 8.69022V8.09124C22.4669 8.12308 22.3996 8.15248 22.3138 8.17943C22.2305 8.20393 22.1362 8.2272 22.0309 8.24925C21.9255 8.26885 21.8202 8.28722 21.7148 8.30437C21.6095 8.31907 21.514 8.33254 21.4282 8.34479C21.2445 8.37174 21.084 8.41461 20.9468 8.47341C20.8096 8.53221 20.7031 8.61183 20.6271 8.71227C20.5512 8.81026 20.5132 8.93275 20.5132 9.07974C20.5132 9.29288 20.5904 9.45579 20.7447 9.56849C20.9015 9.67873 21.0999 9.73385 21.34 9.73385Z" /><path d="M18.78 5.06325V6.23917H15.3809V5.06325H18.78ZM16.1526 3.71094H17.718V8.97318C17.718 9.11772 17.74 9.23041 17.7841 9.31126C17.8282 9.38965 17.8895 9.44478 17.9679 9.47662C18.0487 9.50847 18.1418 9.5244 18.2472 9.5244C18.3207 9.5244 18.3942 9.51827 18.4677 9.50602C18.5411 9.49132 18.5975 9.4803 18.6367 9.47295L18.8829 10.6378C18.8045 10.6623 18.6943 10.6905 18.5522 10.7224C18.4101 10.7567 18.2374 10.7775 18.034 10.7848C17.6568 10.7995 17.326 10.7493 17.0418 10.6342C16.7601 10.519 16.5409 10.3402 16.3841 10.0977C16.2273 9.85512 16.1501 9.54889 16.1526 9.17897V3.71094Z" /><path d="M12.683 10.8179C12.1024 10.8179 11.6026 10.7003 11.1837 10.4651C10.7672 10.2275 10.4463 9.89186 10.2209 9.45824C9.9955 9.02217 9.88281 8.50648 9.88281 7.91117C9.88281 7.33056 9.9955 6.821 10.2209 6.38248C10.4463 5.94396 10.7635 5.6022 11.1727 5.35722C11.5842 5.11224 12.0668 4.98975 12.6205 4.98975C12.9929 4.98975 13.3395 5.04977 13.6605 5.16981C13.9838 5.2874 14.2656 5.46501 14.5056 5.70265C14.7482 5.94028 14.9368 6.23916 15.0716 6.59929C15.2063 6.95696 15.2737 7.37589 15.2737 7.85605V8.286H10.5075V7.31586H13.8001C13.8001 7.09048 13.7511 6.89082 13.6531 6.71688C13.5551 6.54294 13.4191 6.40698 13.2452 6.30898C13.0737 6.20854 12.8741 6.15832 12.6462 6.15832C12.4086 6.15832 12.1979 6.21344 12.0142 6.32368C11.8329 6.43147 11.6908 6.57724 11.5879 6.76098C11.485 6.94226 11.4323 7.14438 11.4299 7.36731V8.28967C11.4299 8.56895 11.4813 8.81026 11.5842 9.0136C11.6896 9.21694 11.8378 9.37372 12.0289 9.48397C12.22 9.59421 12.4466 9.64933 12.7087 9.64933C12.8826 9.64933 13.0419 9.62483 13.1864 9.57584C13.331 9.52684 13.4547 9.45335 13.5576 9.35535C13.6605 9.25736 13.7389 9.13732 13.7927 8.99523L15.2406 9.09077C15.1671 9.43865 15.0164 9.74243 14.7886 10.0021C14.5632 10.2593 14.2717 10.4602 13.914 10.6048C13.5588 10.7469 13.1484 10.8179 12.683 10.8179Z" /><path d="M3.81445 10.7075V3.18164H6.82775C7.38141 3.18164 7.84321 3.26371 8.21313 3.42785C8.58306 3.59199 8.86111 3.81982 9.0473 4.11135C9.23349 4.40043 9.32658 4.73361 9.32658 5.11089C9.32658 5.40487 9.26778 5.66332 9.15019 5.88626C9.0326 6.10674 8.87091 6.28803 8.66513 6.43012C8.46179 6.56976 8.22905 6.66898 7.96692 6.72778V6.80127C8.25355 6.81352 8.52181 6.89436 8.77169 7.0438C9.02403 7.19324 9.22859 7.40271 9.38538 7.67219C9.54217 7.93922 9.62056 8.2577 9.62056 8.62762C9.62056 9.02695 9.52134 9.3834 9.32291 9.69698C9.12692 10.0081 8.83661 10.2543 8.45199 10.4356C8.06737 10.6169 7.59332 10.7075 7.02986 10.7075H3.81445ZM5.40562 9.40667H6.70281C7.14623 9.40667 7.46961 9.32215 7.67294 9.15311C7.87628 8.98162 7.97795 8.75379 7.97795 8.46961C7.97795 8.26137 7.92772 8.07764 7.82728 7.9184C7.72684 7.75916 7.58352 7.63421 7.39734 7.54357C7.2136 7.45293 6.99434 7.40761 6.73956 7.40761H5.40562V9.40667ZM5.40562 6.3309H6.58522C6.80325 6.3309 6.99679 6.29293 7.16583 6.21699C7.33732 6.13859 7.47206 6.02835 7.57005 5.88626C7.67049 5.74417 7.72071 5.5739 7.72071 5.37547C7.72071 5.10354 7.62395 4.88428 7.43041 4.71769C7.23932 4.5511 6.96739 4.4678 6.61461 4.4678H5.40562V6.3309Z" /></svg>',
caretDown:
Expand Down
24 changes: 24 additions & 0 deletions ui/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
ActionHash,
ActionHashB64,
AgentPubKeyB64,
CellId,
EntryHash,
Expand Down Expand Up @@ -29,6 +30,14 @@ export interface MessageDeleted {
from: AgentPubKey;
}

export interface MessageUpdatedSignal {
type: "MessageUpdated";
action: SignedActionHashed<Update>;
original_action: ActionHash;
message: Message;
from: AgentPubKey;
}

export interface PeerPingSignal {
type: "PeerPing";
from_agent: AgentPubKey;
Expand All @@ -42,6 +51,7 @@ export interface PeerPongSignal {
export type RelaySignal =
| MessageSignal
| MessageDeleted
| MessageUpdatedSignal
| PeerPingSignal
| PeerPongSignal
| {
Expand Down Expand Up @@ -98,13 +108,19 @@ export interface Message {
bucket: number;
images: MessageFile[];
message_type: MessageType;
forwarded?: boolean;
}

export interface MessageExtended {
message: Message;
authorAgentPubKeyB64: AgentPubKeyB64;
timestamp: number;
deliveredTo: AgentPubKeyB64[];

// Set once the author has edited the message. latestUpdateActionHashB64 is the
// head of the update chain, needed as the previous hash for any further edit.
edited?: boolean;
latestUpdateActionHashB64?: ActionHashB64;
}

export enum DeliveryStatus {
Expand Down Expand Up @@ -135,13 +151,21 @@ export interface DeleteMessageInput {
agents: AgentPubKey[];
}

export interface UpdateMessageInput {
original_message_hash: ActionHash;
previous_message_hash: ActionHash;
updated_message: Message;
agents: AgentPubKey[];
}

/**
* Conversation
*/

export interface Config {
title: string;
image: string;
description?: string;
}

export enum Privacy {
Expand Down
10 changes: 10 additions & 0 deletions ui/src/routes/conversations/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
{/if}

<ConversationList enabled={true}>
<li class="hover:bg-tertiary-500 dark:hover:bg-secondary-500 flex items-center rounded-lg py-2">
<button
on:click={() => goto("/conversations/starred")}
class="mx-4 flex w-full items-center justify-start space-x-6"
>
<SvgIcon icon="starFilled" />
<div>{$t("common.starred_messages")}</div>
</button>
</li>

{#if hasArchivedConversations}
<li class="hover:bg-tertiary-500 dark:hover:bg-secondary-500 flex items-center rounded-lg py-2">
<button
Expand Down
Loading
Loading