Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update-presage-2
Browse files Browse the repository at this point in the history
  • Loading branch information
boxdot committed Dec 22, 2024
2 parents d76be58 + fd4f0bc commit 5dd9986
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 29 deletions.
21 changes: 13 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,25 @@ impl App {
async fn resolve_name(&self, user_id: Uuid) -> Option<String> {
if let Some(name) = self.signal_manager.profile_name(user_id).await {
debug!(name, "resolved name as profile name");
Some(name)
} else if let Some(contact) = self.signal_manager.contact(user_id).await {
debug!(name = contact.name, "resolved name from contacts");
Some(contact.name)
} else if let Some(name) = self
return Some(name);
}
if let Some(contact) = self.signal_manager.contact(user_id).await {
if !contact.name.trim().is_empty() {
debug!(name = contact.name, "resolved name from contacts");
return Some(contact.name);
} else {
debug!(%user_id, "resolved empty name from contacts, skipping");
}
}
if let Some(name) = self
.storage
.name(user_id)
.filter(|name| !name.trim().is_empty())
{
debug!(%name, "resolved name from storage");
Some(name.into_owned())
} else {
None
return Some(name.into_owned());
}
None
}

// Resolves name of a user by their id
Expand Down
10 changes: 5 additions & 5 deletions src/storage/forgetful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{MessageId, Metadata, Storage};
pub struct ForgetfulStorage;

impl Storage for ForgetfulStorage {
fn channels<'s>(&'s self) -> Box<dyn Iterator<Item = Cow<Channel>> + 's> {
fn channels(&self) -> Box<dyn Iterator<Item = Cow<Channel>> + '_> {
Box::new(std::iter::empty())
}

Expand All @@ -22,10 +22,10 @@ impl Storage for ForgetfulStorage {
Cow::Owned(channel)
}

fn messages<'s>(
&'s self,
fn messages(
&self,
_channel_id: ChannelId,
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + 's> {
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + '_> {
Box::new(std::iter::empty())
}

Expand All @@ -44,7 +44,7 @@ impl Storage for ForgetfulStorage {
Cow::Owned(message)
}

fn names<'s>(&'s self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + 's> {
fn names(&self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + '_> {
Box::new(std::iter::empty())
}

Expand Down
10 changes: 5 additions & 5 deletions src/storage/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl JsonStorage {
}

impl Storage for JsonStorage {
fn channels<'s>(&'s self) -> Box<dyn Iterator<Item = Cow<Channel>> + 's> {
fn channels(&self) -> Box<dyn Iterator<Item = Cow<Channel>> + '_> {
Box::new(
self.data
.channels
Expand Down Expand Up @@ -194,10 +194,10 @@ impl Storage for JsonStorage {
Cow::Owned(Channel::from(&self.data.channels.items[channel_idx]))
}

fn messages<'s>(
&'s self,
fn messages(
&self,
channel_id: ChannelId,
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + 's> {
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + '_> {
if let Some(channel) = self
.data
.channels
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Storage for JsonStorage {
Cow::Borrowed(&self.data.channels.items[channel_idx].messages[idx])
}

fn names<'s>(&'s self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + 's> {
fn names(&self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + '_> {
Box::new(
self.data
.names
Expand Down
10 changes: 5 additions & 5 deletions src/storage/memcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<S: Storage> MemCache<S> {
}

impl<S: Storage> Storage for MemCache<S> {
fn channels<'s>(&'s self) -> Box<dyn Iterator<Item = Cow<Channel>> + 's> {
fn channels(&self) -> Box<dyn Iterator<Item = Cow<Channel>> + '_> {
Box::new(self.channels.iter().map(Cow::Borrowed))
}

Expand All @@ -86,10 +86,10 @@ impl<S: Storage> Storage for MemCache<S> {
self.storage.store_channel(channel)
}

fn messages<'s>(
&'s self,
fn messages(
&self,
channel_id: ChannelId,
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + 's> {
) -> Box<dyn DoubleEndedIterator<Item = Cow<Message>> + '_> {
if let Some(messages) = self.messages.get(&channel_id) {
Box::new(messages.iter().map(Cow::Borrowed))
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<S: Storage> Storage for MemCache<S> {
self.storage.store_message(channel_id, message)
}

fn names<'s>(&'s self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + 's> {
fn names(&self) -> Box<dyn Iterator<Item = (Uuid, Cow<str>)> + '_> {
Box::new(
self.names
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/storage/sql/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ struct SqlName {
}

impl Storage for SqliteStorage {
fn channels<'s>(&'s self) -> Box<dyn Iterator<Item = Cow<Channel>> + 's> {
fn channels(&self) -> Box<dyn Iterator<Item = Cow<Channel>> + '_> {
let channels = self.execute(|ctx|
Box::pin(sqlx::query_as!(
SqlChannel,
Expand Down
38 changes: 33 additions & 5 deletions src/ui/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ use std::fmt;

use chrono::Datelike;
use itertools::Itertools;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, Clear, List, ListDirection, ListItem, Paragraph};
use ratatui::Frame;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
widgets::Padding,
};
use ratatui::{
style::{Color, Modifier, Style},
widgets::Wrap,
};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
use uuid::Uuid;

Expand Down Expand Up @@ -94,7 +100,7 @@ fn draw_select_channel_popup(f: &mut Frame, select_channel: &mut SelectChannel)

fn draw_channels(f: &mut Frame, app: &mut App, area: Rect) {
let channel_list_width = area.width.saturating_sub(2) as usize;
let channels: Vec<ListItem> = app
let channels = app
.channels
.items
.iter()
Expand All @@ -118,12 +124,23 @@ fn draw_channels(f: &mut Frame, app: &mut App, area: Rect) {
format!("{}{}", &channel.name[0..end], unread_messages_label)
};
ListItem::new(vec![Line::from(Span::raw(label))])
})
.collect();
});

let channels = List::new(channels)
.block(Block::default().borders(Borders::ALL).title("Channels"))
.highlight_style(Style::default().fg(Color::Black).bg(Color::Gray));
let no_channels = channels.is_empty();
f.render_stateful_widget(channels, area, &mut app.channels.state);

if no_channels {
f.render_widget(
Paragraph::new("No channels\n(Channels will be added on incoming messages)")
.wrap(Wrap { trim: true })
.centered()
.block(Block::default().padding(Padding::top(area.height / 2))),
area,
);
};
}

fn wrap(text: &str, mut cursor: Cursor, width: usize) -> (String, Cursor, usize) {
Expand Down Expand Up @@ -267,8 +284,19 @@ fn draw_messages(f: &mut Frame, app: &mut App, area: Rect) {
prepare_receipts(app, height);

let Some(&channel_id) = app.channels.selected_item() else {
f.render_widget(
Paragraph::new("No Channel selected")
.block(
Block::bordered()
.title("Messages")
.padding(Padding::top(area.height / 2)),
)
.centered(),
area,
);
return;
};

let channel = app
.storage
.channel(channel_id)
Expand Down

0 comments on commit 5dd9986

Please sign in to comment.