How to get the website url

Plugin Development

Suggested Topics


  • 0 Votes
    3 Posts
    331 Views

    @julian Thanks for getting back to me quickly. Other priorities pulled me away from this, but after looking at your response, it seems like what I'm actually after are "unread" counts, not just notifications. The simple GET solution returned notifications, but not every "unread". Our app is using the session sharing plugin, and we are associating NodeBB accounts with our app accounts. Would I be able to leverage some of the session sharing functionality to get an unread count for users on our app based on their NodeBB account? Thanks

  • 0 Votes
    4 Posts
    2k Views

    Yeah forgot to mention you can put that piece of code in your custom header at /admin/appearance/customise#custom-header

  • 0 Votes
    2 Posts
    1k Views

    @Nisthar I was not able to get the content of a post by using the hook "filter:topic.get" But i used "filter:parse.post" to do it 😄

  • 0 Votes
    3 Posts
    2k Views

    You can use Plugins.isActive method.

  • 1 Votes
    8 Posts
    4k Views

    Okay! It works perfect now that I GET the Cookie first. It was pretty easy using the OkHttp3 library, which was already a dependent of SocketIO, so I didn't have to add any more dependencies.

    I'm not sure if this is useful to anyone else, but here is my test app.

    package com.radiofreederp.nodebbapp; import io.socket.client.Ack; import io.socket.client.IO; import io.socket.client.Manager; import io.socket.client.Socket; import io.socket.emitter.Emitter; import io.socket.engineio.client.Transport; import okhttp3.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; import java.util.Map; public class NodeBBApp { private String url; private OkHttpClient client = new OkHttpClient(); private String cookie; private Socket socket; NodeBBApp(String url) { this.url = url; } private void getCookie() throws IOException { Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); cookie = response.headers().get("Set-Cookie"); } private void connectSocket() throws URISyntaxException { socket = IO.socket(url); // Send the session cookie with requests. socket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() { @Override public void call(Object... args) { Transport transport = (Transport)args[0]; transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() { @Override public void call(Object... args) { @SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>)args[0]; headers.put("Cookie", Arrays.asList(cookie)); } }); } }); socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { @Override public void call(Object... objects) { JSONObject data = new JSONObject(); try { data.put("tid", 45); data.put("after", 1); data.put("direction", 1); } catch (JSONException e) { e.printStackTrace(); } socket.emit("topics.loadMore", data, new Ack() { @Override public void call(Object... objects) { System.out.println("Response:"); if (objects.length == 2 && objects[0] == null) { JSONObject data = (JSONObject)objects[1]; try { JSONArray posts = data.getJSONArray("posts"); for (int i = 0; i < posts.length(); i++) { System.out.println(((JSONObject)posts.get(i)).get("content")); } } catch (JSONException e) { e.printStackTrace(); } } socket.close(); } }); } }); socket.connect(); } public static void main(String [] args) { NodeBBApp app = new NodeBBApp("http://www.yaricraft.com/"); try { app.getCookie(); app.connectSocket(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } }