fix extra star-space prefix on system messages breaking heuristic action detection

This commit is contained in:
mappu 2018-06-05 18:41:19 +12:00
parent bafc724b8a
commit 2668a6abbd

View File

@ -290,12 +290,15 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) {
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
// This includes "want to register your nick?" and chat-catchup messages
// But it also includes /me messages
// Hard to tell them apart - heuristic detection by matching the first space-separated word against known online users
// First, remove system characters from the front (star, space)
systemMessage := strings.TrimLeft(msg.evt.Message, `* `)
// Heuristic detect action messages if the first space-separated word is a known online user
isActionMessage := false
if conn, ok := this.conns[msg.hubNick]; ok {
firstWord := strings.SplitN(msg.evt.Message, ` `, 2)[0]
firstWord := strings.SplitN(systemMessage, ` `, 2)[0]
_ = conn.Users(func(umap *map[string]libnmdc.UserInfo) error {
for knownHubNick, _ := range *umap {
if knownHubNick == firstWord {
@ -311,18 +314,19 @@ func (this *NTFServer) HandleHubMessage(msg upstreamMessage) {
// Treat it as a full post
// Coalesce from multiple connections
if this.Coalesce("*", msg.evt.Message) {
if this.Coalesce("*", systemMessage) {
return // ignore - we heard this message already recently
}
// Display the message
htmlMsg := "<i>* " + html.EscapeString(msg.evt.Message) + "</i>"
htmlMsg := "<i>* " + html.EscapeString(systemMessage) + "</i>"
err := this.GroupChatSayHTML(htmlMsg)
if err != nil {
log.Printf("Delivering action message to group chat: %s", err.Error())
}
} else {
// Not an action message, just clerical notices
// Don't mirror them into telegram
log.Printf("Hub(%s): * %s", msg.hubNick, msg.evt.Message)
}