From 8f92be676fd2895ecfbc0e2d69c558d1699b73c9 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 12 Dec 2012 20:38:19 +0000
Subject: [PATCH] Added a right click menu on chat users in the message log
 Added a "report user for bad behavior" option to the message log and chat
 log; use it with care

git-svn-id: http://svn.net-core.org/repos/t-engine4@6057 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/UserChat.lua     | 30 ++++++++++++++++++++
 game/modules/tome/class/uiset/Minimalist.lua | 10 ++++++-
 game/modules/tome/dialogs/MapMenu.lua        | 12 +++++++-
 game/modules/tome/dialogs/ShowChatLog.lua    | 24 ++++++++++++++++
 game/profile-thread/Client.lua               |  7 ++++-
 5 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/game/engines/default/engine/UserChat.lua b/game/engines/default/engine/UserChat.lua
index 0b7a83f70d..9f762f4886 100644
--- a/game/engines/default/engine/UserChat.lua
+++ b/game/engines/default/engine/UserChat.lua
@@ -248,6 +248,16 @@ function _M:whisper(to, msg)
 	if type(game) == "table" and game.logChat then game.logChat("#GOLD#<Whisper to %s> %s", to, msg) end
 end
 
+function _M:reportUser(to, msg)
+	if not profile.auth then return end
+	if not to or not msg or msg == "" then return end
+	msg = msg:removeColorCodes()
+	core.profile.pushOrder(string.format("o='ReportUser' target=%q msg=%q", to, msg))
+
+	self:addMessage("report", self.cur_channel, to, to, "#VIOLET#Report for "..to.." sent.#LAST#")
+	if type(game) == "table" and game.logChat then game.logChat("#VIOLET#Report for %s sent.#LAST#", to) end
+end
+
 function _M:achievement(name)
 	if not profile.auth then return end
 	core.profile.pushOrder(string.format("o='ChatAchievement' channel=%q msg=%q", self.cur_channel, name))
@@ -320,6 +330,26 @@ function _M:showUserInfo(login)
 	game:registerDialog(UserInfo.new(data))
 end
 
+--- Get user infos
+function _M:getUserInfo(login)
+	if not profile.auth then return end
+
+	local popup = Dialog:simpleWaiter("Requesting...", "Requesting user info...")
+	core.display.forceRedraw()
+
+	core.profile.pushOrder(string.format("o='ChatUserInfo' login=%q", login))
+	local data = nil
+	profile:waitEvent("UserInfo", function(e) data=e.data end, 5000)
+
+	popup:done()
+
+	if not data then
+		return
+	end
+	data = zlib.decompress(data):unserialize()
+	return data
+end
+
 ----------------------------------------------------------------
 -- UI Section
 ----------------------------------------------------------------
diff --git a/game/modules/tome/class/uiset/Minimalist.lua b/game/modules/tome/class/uiset/Minimalist.lua
index 930d5832d3..59314981f8 100644
--- a/game/modules/tome/class/uiset/Minimalist.lua
+++ b/game/modules/tome/class/uiset/Minimalist.lua
@@ -1949,7 +1949,15 @@ function _M:setupMouse(mouse)
 		else
 			extra.log_str = str
 			if button == "right" and event == "button" then
-				extra.add_map_action = { name="Show chat user", fct=function() profile.chat:showUserInfo(user.login) end }
+				extra.add_map_action = { 
+					{ name="Show chat user", fct=function() profile.chat:showUserInfo(user.login) end },
+					{ name="Report user for bad behavior", fct=function()
+						game:registerDialog(require('engine.dialogs.GetText').new("Reason to report: "..user.login, "Reason", 4, 500, function(text)
+							profile.chat:reportUser(user.login, text)
+							game.log("#VIOLET#", "Report sent.")
+						end))							
+					end },
+				}
 			end
 		end
 		game.tooltip.old_tmx = -100
diff --git a/game/modules/tome/dialogs/MapMenu.lua b/game/modules/tome/dialogs/MapMenu.lua
index 048df9e8c4..dc1c14cdd6 100644
--- a/game/modules/tome/dialogs/MapMenu.lua
+++ b/game/modules/tome/dialogs/MapMenu.lua
@@ -27,9 +27,9 @@ module(..., package.seeall, class.inherit(engine.ui.Dialog))
 function _M:init(mx, my, tmx, tmy, extra)
 	self.tmx, self.tmy = util.bound(tmx, 0, game.level.map.w - 1), util.bound(tmy, 0, game.level.map.h - 1)
 	if tmx == game.player.x and tmy == game.player.y then self.on_player = true end
+	self.extra = extra
 
 	self:generateList()
-	if extra then table.insert(self.list, 1, {name=extra.name, action="extra", action_fct=extra.fct, color=extra.color}) end
 	self.__showup = false
 
 	local name = "Actions"
@@ -180,6 +180,16 @@ function _M:generateList()
 		for i = 1, #tals do list[#list+1] = tals[i] end
 	end
 
+	if self.extra then 
+		if self.extra.name then
+			table.insert(list, 1, {name=self.extra.name, action="extra", action_fct=self.extra.fct, color=self.extra.color}) 
+		else
+			for i, extra in ipairs(self.extra) do
+				table.insert(list, i, {name=extra.name, action="extra", action_fct=extra.fct, color=extra.color}) 
+			end
+		end
+	end
+
 	self.max = 0
 	self.maxh = 0
 	for i, v in ipairs(list) do
diff --git a/game/modules/tome/dialogs/ShowChatLog.lua b/game/modules/tome/dialogs/ShowChatLog.lua
index 20116b6bca..ffc020f9a9 100644
--- a/game/modules/tome/dialogs/ShowChatLog.lua
+++ b/game/modules/tome/dialogs/ShowChatLog.lua
@@ -165,6 +165,30 @@ function _M:mouseEvent(button, x, y, xrel, yrel, bx, by, event)
 					end
 				end
 			end
+
+			if citem and citem.login then
+				local data = profile.chat:getUserInfo(citem.login)
+				if data then
+					local list = {{name="Show infos", ui="show"}, {name="Open profile(in brower)", ui="profile"}, {name="Report for bad behavior", ui="report"}}
+					if data.char_link then table.insert(list, 3, {name="Open charsheet(in brower)", ui="charsheet"}) end
+					Dialog:listPopup("User: "..citem.login, "Action", list, 300, 200, function(sel)
+						if not sel or not sel.ui then return end
+						if sel.ui == "show" then
+							local UserInfo = require "engine.dialogs.UserInfo"
+							game:registerDialog(UserInfo.new(data))
+						elseif sel.ui == "profile" then
+							util.browserOpenUrl(data.profile)
+						elseif sel.ui == "charsheet" then
+							util.browserOpenUrl(data.char_link)
+						elseif sel.ui == "report" then
+							game:registerDialog(require('engine.dialogs.GetText').new("Reason to report: "..citem.login, "Reason", 4, 500, function(text)
+								profile.chat:reportUser(citem.login, text)
+								game.log("#VIOLET#", "Report sent.")
+							end))							
+						end
+					end)
+				end
+			end
 		end
 	end
 end
diff --git a/game/profile-thread/Client.lua b/game/profile-thread/Client.lua
index 4f7b2b65a0..2584ff256f 100644
--- a/game/profile-thread/Client.lua
+++ b/game/profile-thread/Client.lua
@@ -23,7 +23,7 @@ local UserChat = require "profile-thread.UserChat"
 
 module(..., package.seeall, class.make)
 
-local debug = false
+local debug = true
 
 local mport = debug and 2259 or 2257
 local pport = debug and 2260 or 2258
@@ -400,6 +400,11 @@ function _M:orderChatWhisper(o)
 	self:read("200")
 end
 
+function _M:orderReportUser(o)
+	self:command("RPTU", o.target..":=:"..o.msg)
+	self:read("200")
+end
+
 function _M:orderChatAchievement(o)
 	self:command("ACHV", o.channel, o.msg)
 	self:read("200")
-- 
GitLab