summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2018-03-31 15:02:41 -0300
committerSoniEx2 <endermoneymod@gmail.com>2018-03-31 15:02:41 -0300
commit6d5d3e72974dcd1e70c2e4e339530bee1263114a (patch)
treec82edf30e10552f13446912182d6f990257f18d7 /src
parentb2be734b53e74caf087f0d112b432fcbeb1b72e9 (diff)
Implement find_context
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2b45724..45b3c66 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -95,7 +95,7 @@
  *     -[ ] hexchat_hook_server_attrs
  *     -[x] hexchat_hook_timer
  *     -[x] ~~hexchat_unhook~~ not available - use Drop impls
- *     -[ ] hexchat_find_context
+ *     -[x] hexchat_find_context
  *     -[x] hexchat_get_context
  *     -[x] hexchat_set_context
  *     -[ ] hexchat_pluginpref_set_str
@@ -631,9 +631,20 @@ impl<'a> EnsureValidContext<'a> {
  * context take an `&mut self`, things that do take an `self`.
  */
 
+    /// Finds an open context for the given servname and channel.
     pub fn find_context(&mut self, servname: Option<&str>, channel: Option<&str>) -> Option<Context> {
-        // TODO
-        unimplemented!()
+        // this was a mistake but oh well
+        let ph = self.ph.ph;
+        let servname = CString::new(servname).unwrap();
+        let channel = CString::new(channel).unwrap();
+        let ctx = unsafe {
+            ((*ph).hexchat_find_context)(ph, servname.as_ptr(), channel.as_ptr())
+        };
+        if ctx.is_null() {
+            None
+        } else {
+            Some(Context { ctx })
+        }
     }
 
     pub fn nickcmp(&mut self, nick1: &str, nick2: &str) -> ::std::cmp::Ordering {