Load real contacts
This commit is contained in:
parent
37bb7b09dc
commit
382caf83a8
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "xmpp-client"
|
name = "rino"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -13,3 +13,6 @@ nom = "7.1.3"
|
||||||
html-escape = "0.2.13"
|
html-escape = "0.2.13"
|
||||||
hsluv = "0.3.1"
|
hsluv = "0.3.1"
|
||||||
sha1 = "0.10.6"
|
sha1 = "0.10.6"
|
||||||
|
tokio = { version = "1", features = [ "rt" ] }
|
||||||
|
xmpp = { git = "https://gitlab.com/xmpp-rs/xmpp-rs" }
|
||||||
|
async-channel = "2.3.1"
|
||||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -21,6 +21,7 @@ mod message;
|
||||||
mod poezio_logs;
|
mod poezio_logs;
|
||||||
mod tab;
|
mod tab;
|
||||||
mod window;
|
mod window;
|
||||||
|
mod xmpp;
|
||||||
|
|
||||||
use message::Message;
|
use message::Message;
|
||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
|
@ -63,6 +64,11 @@ fn xep_0392(input: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let mut args = std::env::args();
|
||||||
|
let _ = args.next().unwrap();
|
||||||
|
let username = args.next().expect("Please give username argument 1");
|
||||||
|
let password = args.next().expect("Please give password argument 2");
|
||||||
|
|
||||||
let app = adw::Application::builder()
|
let app = adw::Application::builder()
|
||||||
.application_id("fr.linkmauve.XmppClient")
|
.application_id("fr.linkmauve.XmppClient")
|
||||||
.flags(gio::ApplicationFlags::HANDLES_COMMAND_LINE)
|
.flags(gio::ApplicationFlags::HANDLES_COMMAND_LINE)
|
||||||
|
@ -70,29 +76,13 @@ fn main() {
|
||||||
|
|
||||||
let tabs_store = gio::ListStore::new::<Tab>();
|
let tabs_store = gio::ListStore::new::<Tab>();
|
||||||
|
|
||||||
let tabs_store2 = tabs_store.clone();
|
let xmpp_receiver = xmpp::client(&username, &password);
|
||||||
app.connect_command_line(move |app, command_line| {
|
let tabs_store_copy = tabs_store.clone();
|
||||||
let args = command_line.arguments();
|
glib::spawn_future_local(async move {
|
||||||
let mut iter = args.iter();
|
while let Ok(xmpp::ContactReceived(jid)) = xmpp_receiver.recv().await {
|
||||||
iter.next().unwrap();
|
let tab = Tab::new(jid.as_str(), jid.as_str());
|
||||||
let mut first_tab = None;
|
tabs_store_copy.append(&tab);
|
||||||
for os_arg in iter {
|
|
||||||
let jid = os_arg.to_str().unwrap();
|
|
||||||
let tab = Tab::new(jid, "User");
|
|
||||||
tabs_store2.append(&tab);
|
|
||||||
if first_tab.is_none() {
|
|
||||||
first_tab = Some(tab);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(tab) = first_tab {
|
|
||||||
let win = app.active_window().unwrap();
|
|
||||||
let win: &window::MainWindow = win.downcast_ref().unwrap();
|
|
||||||
let store = load_logs(&tab.jid());
|
|
||||||
win.selection().set_model(Some(&store));
|
|
||||||
win.messages()
|
|
||||||
.scroll_to(win.selection().n_items() - 1, gtk::ListScrollFlags::FOCUS, None);
|
|
||||||
}
|
|
||||||
0
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.connect_startup(move |app| {
|
app.connect_startup(move |app| {
|
||||||
|
@ -196,8 +186,11 @@ fn main() {
|
||||||
.scroll_to(selection.n_items() - 1, gtk::ListScrollFlags::FOCUS, None);
|
.scroll_to(selection.n_items() - 1, gtk::ListScrollFlags::FOCUS, None);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.messages()
|
win.messages().scroll_to(
|
||||||
.scroll_to(win.selection().n_items() - 1, gtk::ListScrollFlags::FOCUS, None);
|
win.selection().n_items() - 1,
|
||||||
|
gtk::ListScrollFlags::FOCUS,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
win.present();
|
win.present();
|
||||||
});
|
});
|
||||||
|
|
45
src/xmpp.rs
Normal file
45
src/xmpp.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
use async_channel::Receiver;
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
|
use xmpp::{BareJid, ClientBuilder, ClientFeature, Event};
|
||||||
|
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ContactReceived(pub BareJid);
|
||||||
|
|
||||||
|
fn tokio_runtime() -> &'static Runtime {
|
||||||
|
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
|
||||||
|
RUNTIME.get_or_init(|| Runtime::new().expect("Setting up tokio runtime needs to succeed."))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn client(jid: &str, password: &str) -> Receiver<ContactReceived> {
|
||||||
|
let (event_sender, event_receiver) = async_channel::bounded::<ContactReceived>(1);
|
||||||
|
|
||||||
|
let jid = jid.to_string();
|
||||||
|
let password = password.to_string();
|
||||||
|
|
||||||
|
tokio_runtime().spawn(async move {
|
||||||
|
let mut client = ClientBuilder::new(BareJid::new(&jid).unwrap(), &password)
|
||||||
|
.set_default_nick("xmpp-client")
|
||||||
|
.enable_feature(ClientFeature::ContactList)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
while let Some(events) = client.wait_for_events().await {
|
||||||
|
for event in events {
|
||||||
|
match event {
|
||||||
|
Event::ContactAdded(contact) => {
|
||||||
|
event_sender
|
||||||
|
.send(ContactReceived(contact.jid))
|
||||||
|
.await
|
||||||
|
.expect("BOOOOOOHOOOO");
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
event_receiver
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user