diff --git a/core/lib/nicktrace.py b/core/lib/nicktrace.py index 96f99eb..173490e 100644 --- a/core/lib/nicktrace.py +++ b/core/lib/nicktrace.py @@ -1,13 +1,68 @@ from core.lib.opensearch import client, run_main_query -def get_nicks(request, net, nick): +def get_nicks(request, net, nick, iter=0): """ Get all related nicknames of the given nickname by tracking nickname changes. """ + print("GET NICKS INIT", net, nick, iter) # Get the initial query - query = {} - results = set() + query = { + "size": 10000, + "query": { + "bool": { + "must": [ + {"match": {"net": net}}, + {"match": {"type": "nick"}}, + { + "bool": { + "should": [ + {"match": {"nick": nick}}, + {"match": {"user": nick}}, + ] + } + }, + ] + } + }, + } + results = run_main_query(client, request.user, query, custom_query=True) + nicks = [] + if "hits" in results.keys(): + if "hits" in results["hits"]: + for item in results["hits"]["hits"]: + element = item["_source"] + element["id"] = item["_id"] + + # Split the timestamp into date and time + ts = element["ts"] + ts_spl = ts.split("T") + date = ts_spl[0] + time = ts_spl[1] + element["date"] = date + element["time"] = time + if element["nick"] not in nicks: + nicks.append(element["nick"]) + if element["user"] not in nicks: + nicks.append(element["user"]) + + # if iter < 2: + # iter += 1 + # collect_nicks = [] + # for x in nicks: + # nicks_2 = get_nicks(request, net, x, iter) + # print("NICKS_2", nicks_2) + # for y in nicks_2: + # if y not in collect_nicks: + # collect_nicks.append(y) + # print("RETURN NICKS", nick, collect_nicks) + # for x in collect_nicks: + # if x not in nicks: + # nicks.append(x) + # else: + # print("ABORTING SEARCH") + return nicks + # results = set() # nicks = query["nicks"] # for nick in nicks: # if nick not in results: diff --git a/core/templates/ui/insights/channels.html b/core/templates/ui/insights/channels.html index eee24a1..c17c3b4 100644 --- a/core/templates/ui/insights/channels.html +++ b/core/templates/ui/insights/channels.html @@ -1,16 +1,19 @@
- {% for chan in chans %} - - - - - {{ chan }} - - {% endfor %} +
+
    + {% for chan in chans %} +
  1. + + {{ chan }} + +
  2. + {% endfor %} +
+
\ No newline at end of file diff --git a/core/templates/ui/insights/nicks.html b/core/templates/ui/insights/nicks.html index f174669..49c02bf 100644 --- a/core/templates/ui/insights/nicks.html +++ b/core/templates/ui/insights/nicks.html @@ -1,14 +1,19 @@
- - - - - aaa - +
+
    + {% for nick in nicks %} +
  1. + + {{ nick }} + +
  2. + {% endfor %} +
+
\ No newline at end of file diff --git a/core/views/dynamic/insights.py b/core/views/dynamic/insights.py index d539d6d..f9d868c 100644 --- a/core/views/dynamic/insights.py +++ b/core/views/dynamic/insights.py @@ -26,10 +26,7 @@ class InsightsSearch(LoginRequiredMixin, View): results, context = query_single_result(request) if not context: return HttpResponseForbidden() - if context: - return render(request, self.template_name, context) - else: - return HttpResponse("No results") + return render(request, self.template_name, context) class InsightsChannels(LoginRequiredMixin, APIView): @@ -52,10 +49,7 @@ class InsightsChannels(LoginRequiredMixin, APIView): if not chans: return HttpResponseForbidden() context = {"net": net, "nick": nick, "chans": chans} - if chans: - return render(request, self.template_name, context) - else: - return HttpResponse("No results") + return render(request, self.template_name, context) class InsightsNicks(LoginRequiredMixin, APIView): @@ -72,8 +66,10 @@ class InsightsNicks(LoginRequiredMixin, APIView): return HttpResponse("No nick") net = request.data["net"] nick = request.data["nick"] - - context = {"net": net, "nick": nick} + nicks = get_nicks(request, net, nick) + if not nicks: + return HttpResponseForbidden() + context = {"net": net, "nick": nick, "nicks": nicks} return render(request, self.template_name, context)