Fix send message logic and tweak context queries for private messages
This commit is contained in:
@@ -104,7 +104,11 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
|
||||
|
||||
def get(self, request, net):
|
||||
relays = threshold.get_irc_relays(net)
|
||||
sinst = threshold.get_irc_sinst(net)
|
||||
context = {"net": net, "relays": relays["relays"]}
|
||||
if sinst:
|
||||
if sinst["success"]:
|
||||
context["sinst"] = sinst["sinst"]
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
||||
@@ -693,7 +697,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||
parser_classes = [FormParser]
|
||||
template_name = "partials/context-input.html"
|
||||
|
||||
def put(self, request, net, num, nick=None):
|
||||
def put(self, request, net, num):
|
||||
"""
|
||||
Send a message
|
||||
"""
|
||||
@@ -713,6 +717,9 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||
self.template_name,
|
||||
{"message": message, "class": message_class},
|
||||
)
|
||||
nick = None
|
||||
if "nick" in request.data:
|
||||
nick = request.data["nick"]
|
||||
if nick:
|
||||
messaged = threshold.send_irc_message(
|
||||
net, num, request.data["channel"], request.data["msg"], nick=nick
|
||||
|
||||
@@ -255,26 +255,18 @@ class DrilldownContextModal(APIView):
|
||||
# Create the query params from the POST arguments
|
||||
mandatory = ["net", "channel", "num", "src", "index", "nick", "type"]
|
||||
invalid = [None, False, "—", "None"]
|
||||
|
||||
query_params = {k: v for k, v in request.data.items() if v}
|
||||
|
||||
if query_params["index"] == "int":
|
||||
mandatory.append("mtype")
|
||||
|
||||
for key in query_params:
|
||||
if query_params[key] in invalid:
|
||||
query_params[key] = None
|
||||
for key in mandatory:
|
||||
if key not in query_params:
|
||||
query_params[key] = None
|
||||
if query_params["index"] == "int":
|
||||
if "mtype" not in query_params:
|
||||
query_params["mtype"] = None
|
||||
if request.user.is_superuser:
|
||||
if query_params["type"] in ["query", "notice"]:
|
||||
nicks = [query_params["channel"], query_params["nick"]]
|
||||
query_params["sorting"] = "desc"
|
||||
if (
|
||||
query_params["index"] == "int"
|
||||
and query_params["mtype"] == "msg"
|
||||
and not query_params["type"] == "query"
|
||||
):
|
||||
query_params["index"] = "main"
|
||||
|
||||
type = None
|
||||
if "type" in query_params:
|
||||
@@ -282,6 +274,17 @@ class DrilldownContextModal(APIView):
|
||||
if type == "znc":
|
||||
query_params["channel"] = "*status"
|
||||
|
||||
if request.user.is_superuser:
|
||||
if type in ["query", "notice"]:
|
||||
nicks = [query_params["channel"], query_params["nick"]]
|
||||
query_params["sorting"] = "desc"
|
||||
if (
|
||||
query_params["index"] == "int"
|
||||
and query_params["mtype"] == "msg"
|
||||
and not type == "query"
|
||||
):
|
||||
query_params["index"] = "main"
|
||||
|
||||
# Create the query with the context helper
|
||||
search_query = construct_query(
|
||||
query_params["index"],
|
||||
|
||||
Reference in New Issue
Block a user