refactor/cleanup previous

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-08 13:09:04 +12:00
parent 22f08d6d57
commit 714e3b8437

View File

@ -141,11 +141,39 @@ func (s *Server) RunWorker() {
s.DisconnectClient() // if not already done s.DisconnectClient() // if not already done
} }
func (s *Server) upstreamWorker() { func (s *Server) postGeneralMessageInRoom(msg string) {
// FIXME blank names work well in hexchat, but not in yaaic // FIXME blank names work well in hexchat, but not in yaaic
var BLANK_NICK = "" // "!@" + s.name // "PtokaX" // "\xC2\xA0" var BLANK_NICK = "" // "!@" + s.name // "PtokaX" // "\xC2\xA0"
// CTCP action conversion
words := strings.Split(msg, " ")
firstWord := words[0]
remainder := strings.Join(words[1:], " ")
if firstWord == "*" {
firstWord = words[1]
remainder = strings.Join(words[2:], " ")
}
if s.upstream.UserExists(firstWord) {
// it's a /me in disguise - convert back to a CTCP ACTION
// If it's **our own** action, skip it
if firstWord != s.upstreamLauncher.Self.Nick {
s.reply(
rplMsg, firstWord+"!"+firstWord+"@"+firstWord, BLESSED_CHANNEL,
"\x01ACTION "+remainder+"\x01",
)
}
} else {
// genuine system message
s.reply(rplMsg, BLANK_NICK, BLESSED_CHANNEL, msg)
}
}
func (s *Server) upstreamWorker() {
// Read loop // Read loop
for { for {
select { select {
@ -168,7 +196,8 @@ func (s *Server) upstreamWorker() {
// description change - no relevance for IRC users // description change - no relevance for IRC users
case libnmdc.EVENT_CONNECTION_STATE_CHANGED: case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
s.reply(rplMsg, BLANK_NICK, BLESSED_CHANNEL, "* Upstream: "+hubEvent.StateChange.Format()) s.postGeneralMessageInRoom("* Upstream: " + hubEvent.StateChange.Format())
if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_CONNECTED { if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_CONNECTED {
s.sendNames() // delay doing this until now s.sendNames() // delay doing this until now
} }
@ -192,28 +221,7 @@ func (s *Server) upstreamWorker() {
} }
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB: case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
words := strings.Split(hubEvent.Message, " ") s.postGeneralMessageInRoom(hubEvent.Message)
firstWord := words[0]
remainder := strings.Join(words[1:], " ")
if firstWord == "*" {
firstWord = words[1]
remainder = strings.Join(words[2:], " ")
}
if s.upstream.UserExists(firstWord) {
// it's a /me in disguise - convert back to a CTCP ACTION
// If it's **our own** action, skip it
if firstWord != s.upstreamLauncher.Self.Nick {
s.reply(
rplMsg, firstWord+"!"+firstWord+"@"+firstWord, BLESSED_CHANNEL,
"\x01ACTION "+remainder+"\x01",
)
}
} else {
// genuine system message
s.reply(rplMsg, BLANK_NICK, BLESSED_CHANNEL, hubEvent.Message)
}
} }
} }