Skip to content

Commit

Permalink
Means to mark all private dms as read
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Sep 28, 2024
1 parent 1672b43 commit e9ae7fc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gossip-bin/src/ui/dm_chat_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra

let mut channels = app.dm_channel_cache.clone();

widgets::page_header(ui, "Direct Messages", |_| {});
widgets::page_header(ui, "Direct Messages", |ui| {
ui.add_space(16.0);
if widgets::Button::bordered(&app.theme, "Mark all read")
.small(true)
.show(ui)
.clicked()
{
let _ = GLOBALS.db().mark_all_dms_read();
}
});

let is_signer_ready = GLOBALS.identity.is_unlocked();

Expand Down
29 changes: 29 additions & 0 deletions gossip-lib/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,35 @@ impl Storage {
Ok(false)
}

/// Mark all DMs as read
pub fn mark_all_dms_read(&self) -> Result<(), Error> {
let my_pubkey = match GLOBALS.identity.public_key() {
Some(pk) => pk,
None => return Ok(()),
};

let mut filter = Filter::new();
filter.kinds = vec![EventKind::EncryptedDirectMessage, EventKind::GiftWrap];

let events = self.find_events_by_filter(&filter, |event| {
if event.kind == EventKind::EncryptedDirectMessage {
event.pubkey == my_pubkey || event.is_tagged(&my_pubkey)
// Make sure if it has tags, only author and my_pubkey
// TBD
} else {
event.kind == EventKind::GiftWrap
}
})?;

let mut txn = self.get_write_txn()?;
for event in &events {
self.mark_event_viewed(event.id, Some(&mut txn))?;
}
txn.commit()?;

Ok(())
}

/// Get all the DM channels with associated data
pub fn dm_channels(&self) -> Result<Vec<DmChannelData>, Error> {
let my_pubkey = match GLOBALS.identity.public_key() {
Expand Down

0 comments on commit e9ae7fc

Please sign in to comment.