Add support chatstates notification (issue #23)
This commit is contained in:
parent
ba48518357
commit
7e2db9f58b
|
|
@ -2,6 +2,7 @@ package gateway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Philipp15b/go-steam"
|
"github.com/Philipp15b/go-steam"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -24,6 +25,7 @@ type GatewayInfo struct {
|
||||||
XMPP_JID_Client string
|
XMPP_JID_Client string
|
||||||
XMPP_Out chan interface{}
|
XMPP_Out chan interface{}
|
||||||
XMPP_Connected_Client map[string]bool
|
XMPP_Connected_Client map[string]bool
|
||||||
|
XMPP_Composing_Timers map[string]*time.Timer
|
||||||
DebugMessage bool
|
DebugMessage bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,11 @@ func (g *GatewayInfo) mainSteam() {
|
||||||
|
|
||||||
case *steam.ChatMsgEvent:
|
case *steam.ChatMsgEvent:
|
||||||
// Message received
|
// Message received
|
||||||
g.SendXmppMessage(e.ChatterId.ToString()+"@"+XmppJidComponent, "", e.Message)
|
if e.EntryType == steamlang.EChatEntryType_Typing {
|
||||||
|
g.SendXmppMessageComposing(e.ChatterId.ToString() + "@" + XmppJidComponent)
|
||||||
|
} else {
|
||||||
|
g.SendXmppMessage(e.ChatterId.ToString()+"@"+XmppJidComponent, "", e.Message)
|
||||||
|
}
|
||||||
|
|
||||||
case *steam.ChatInviteEvent:
|
case *steam.ChatInviteEvent:
|
||||||
// Invitation to play
|
// Invitation to play
|
||||||
|
|
@ -219,6 +223,14 @@ func (g *GatewayInfo) DisconnectAllSteamFriend() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) SendSteamMessage(steamId, message string) {
|
func (g *GatewayInfo) SendSteamMessage(steamId, message string) {
|
||||||
|
g.sendSteamMessage(steamId, message, steamlang.EChatEntryType_ChatMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) SendSteamMessageComposing(steamId string) {
|
||||||
|
g.sendSteamMessage(steamId, "", steamlang.EChatEntryType_Typing)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) sendSteamMessage(steamId, message string, chatEntryType steamlang.EChatEntryType) {
|
||||||
if !g.IsSteamConnected() {
|
if !g.IsSteamConnected() {
|
||||||
log.Printf("%sTry to send message, but disconnected", LogSteamDebug)
|
log.Printf("%sTry to send message, but disconnected", LogSteamDebug)
|
||||||
return
|
return
|
||||||
|
|
@ -226,7 +238,7 @@ func (g *GatewayInfo) SendSteamMessage(steamId, message string) {
|
||||||
|
|
||||||
steamIdUint64, err := strconv.ParseUint(steamId, 10, 64)
|
steamIdUint64, err := strconv.ParseUint(steamId, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
g.SteamClient.Social.SendMessage(steamid.SteamId(steamIdUint64), steamlang.EChatEntryType_ChatMsg, message)
|
g.SteamClient.Social.SendMessage(steamid.SteamId(steamIdUint64), chatEntryType, message)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%sFailed to get SteamId from %s", LogSteamError, steamId)
|
log.Printf("%sFailed to get SteamId from %s", LogSteamError, steamId)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -124,7 +125,19 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
|
|
||||||
func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) {
|
func (g *GatewayInfo) ReceivedXMPP_Message(message *xmpp.Message) {
|
||||||
steamID := strings.SplitN(message.To, "@", 2)[0]
|
steamID := strings.SplitN(message.To, "@", 2)[0]
|
||||||
g.SendSteamMessage(steamID, message.Body)
|
if message.Composing != nil {
|
||||||
|
g.SendSteamMessageComposing(steamID)
|
||||||
|
} else if message.Paused != nil {
|
||||||
|
return
|
||||||
|
} else if message.Inactive != nil {
|
||||||
|
return
|
||||||
|
} else if message.Gone != nil {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if message.Body != "" {
|
||||||
|
g.SendSteamMessage(steamID, message.Body)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) XMPP_Disconnect() {
|
func (g *GatewayInfo) XMPP_Disconnect() {
|
||||||
|
|
@ -163,6 +176,37 @@ func (g *GatewayInfo) SendXmppPresence(status, tpye, to, from, message, nick str
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GatewayInfo) SendXmppMessage(from, subject, message string) {
|
func (g *GatewayInfo) SendXmppMessage(from, subject, message string) {
|
||||||
|
g.sendXmppMessage(from, subject, message, &xmpp.Active{})
|
||||||
|
g.stopComposingTimer(from)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) SendXmppMessageComposing(from string) {
|
||||||
|
g.sendXmppMessage(from, "", "", &xmpp.Composing{})
|
||||||
|
g.stopComposingTimer(from)
|
||||||
|
|
||||||
|
timer := time.AfterFunc(20*time.Second, func() {
|
||||||
|
g.sendXmppMessage(from, "", "", &xmpp.Paused{})
|
||||||
|
|
||||||
|
t := time.AfterFunc(100*time.Second, func() {
|
||||||
|
g.sendXmppMessage(from, "", "", &xmpp.Inactive{})
|
||||||
|
})
|
||||||
|
g.XMPP_Composing_Timers[from] = t
|
||||||
|
})
|
||||||
|
g.XMPP_Composing_Timers[from] = timer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) stopComposingTimer(from string) {
|
||||||
|
if t, ok := g.XMPP_Composing_Timers[from]; ok {
|
||||||
|
// Delete previous timer if exist
|
||||||
|
if !t.Stop() {
|
||||||
|
// Prevent firing after stop
|
||||||
|
<-t.C
|
||||||
|
}
|
||||||
|
delete(g.XMPP_Composing_Timers, from)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GatewayInfo) sendXmppMessage(from, subject, message string, chatState interface{}) {
|
||||||
if from != XmppJidComponent || from == XmppJidComponent && g.DebugMessage {
|
if from != XmppJidComponent || from == XmppJidComponent && g.DebugMessage {
|
||||||
m := xmpp.Message{To: g.XMPP_JID_Client, From: from, Body: message, Type: "chat"}
|
m := xmpp.Message{To: g.XMPP_JID_Client, From: from, Body: message, Type: "chat"}
|
||||||
|
|
||||||
|
|
@ -170,6 +214,21 @@ func (g *GatewayInfo) SendXmppMessage(from, subject, message string) {
|
||||||
m.Subject = subject
|
m.Subject = subject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch v := chatState.(type) {
|
||||||
|
case *xmpp.Active:
|
||||||
|
m.Active = v
|
||||||
|
case *xmpp.Composing:
|
||||||
|
m.Composing = v
|
||||||
|
case *xmpp.Paused:
|
||||||
|
m.Paused = v
|
||||||
|
case *xmpp.Inactive:
|
||||||
|
m.Inactive = v
|
||||||
|
case *xmpp.Gone:
|
||||||
|
m.Gone = v
|
||||||
|
default:
|
||||||
|
m.Active = &xmpp.Active{}
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("%sSend message %v", LogXmppInfo, m)
|
log.Printf("%sSend message %v", LogXmppInfo, m)
|
||||||
g.XMPP_Out <- m
|
g.XMPP_Out <- m
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"Addresses":[{"IP":"146.66.152.11","Port":27019},{"IP":"162.254.197.40","Port":27021},{"IP":"146.66.152.11","Port":27020},{"IP":"146.66.152.10","Port":27018},{"IP":"146.66.152.11","Port":27017},{"IP":"162.254.197.41","Port":27021},{"IP":"146.66.152.11","Port":27018},{"IP":"146.66.152.10","Port":27020},{"IP":"146.66.152.10","Port":27019},{"IP":"146.66.152.10","Port":27017},{"IP":"162.254.197.41","Port":27020},{"IP":"162.254.197.42","Port":27021},{"IP":"162.254.197.41","Port":27017},{"IP":"162.254.197.40","Port":27017},{"IP":"162.254.197.40","Port":27019},{"IP":"162.254.197.40","Port":27020},{"IP":"162.254.197.41","Port":27019},{"IP":"162.254.197.40","Port":27018},{"IP":"162.254.197.41","Port":27018},{"IP":"162.254.197.42","Port":27017},{"IP":"162.254.197.42","Port":27019},{"IP":"162.254.197.42","Port":27018},{"IP":"162.254.197.42","Port":27020},{"IP":"162.254.196.43","Port":27021},{"IP":"162.254.196.41","Port":27021},{"IP":"162.254.196.43","Port":27018},{"IP":"162.254.196.43","Port":27020},{"IP":"162.254.196.40","Port":27017},{"IP":"162.254.196.41","Port":27017},{"IP":"162.254.196.43","Port":27019},{"IP":"162.254.196.40","Port":27018},{"IP":"162.254.196.41","Port":27019},{"IP":"162.254.196.42","Port":27021},{"IP":"162.254.196.42","Port":27020},{"IP":"162.254.196.42","Port":27018},{"IP":"162.254.196.42","Port":27017},{"IP":"162.254.196.43","Port":27017},{"IP":"162.254.196.40","Port":27020},{"IP":"162.254.196.41","Port":27020},{"IP":"162.254.196.40","Port":27021},{"IP":"162.254.196.41","Port":27018},{"IP":"162.254.196.40","Port":27019},{"IP":"162.254.196.42","Port":27019},{"IP":"185.25.180.14","Port":27020},{"IP":"155.133.242.9","Port":27018},{"IP":"155.133.242.9","Port":27017},{"IP":"185.25.180.14","Port":27019},{"IP":"155.133.242.9","Port":27020},{"IP":"146.66.155.8","Port":27018},{"IP":"146.66.155.8","Port":27017},{"IP":"146.66.155.8","Port":27020},{"IP":"185.25.182.10","Port":27018},{"IP":"185.25.180.14","Port":27018},{"IP":"155.133.242.8","Port":27017},{"IP":"185.25.180.15","Port":27019},{"IP":"155.133.242.9","Port":27019},{"IP":"146.66.155.8","Port":27019},{"IP":"185.25.182.10","Port":27017},{"IP":"185.25.182.10","Port":27019},{"IP":"185.25.180.15","Port":27020},{"IP":"185.25.180.15","Port":27018},{"IP":"155.133.242.8","Port":27019},{"IP":"155.133.242.8","Port":27018},{"IP":"155.133.242.8","Port":27020},{"IP":"185.25.180.15","Port":27017},{"IP":"185.25.180.14","Port":27017},{"IP":"185.25.182.10","Port":27020},{"IP":"208.78.164.14","Port":27018},{"IP":"208.78.164.12","Port":27017},{"IP":"208.78.164.10","Port":27017},{"IP":"208.78.164.14","Port":27017},{"IP":"208.78.164.12","Port":27018},{"IP":"208.78.164.13","Port":27019},{"IP":"208.78.164.14","Port":27019},{"IP":"208.78.164.13","Port":27017},{"IP":"208.78.164.10","Port":27019},{"IP":"208.78.164.12","Port":27019},{"IP":"208.78.164.10","Port":27018},{"IP":"208.78.164.13","Port":27018},{"IP":"162.254.195.45","Port":27021}]}
|
{"Addresses":[{"IP":"162.254.197.42","Port":27021},{"IP":"146.66.152.10","Port":27020},{"IP":"162.254.197.42","Port":27018},{"IP":"162.254.197.41","Port":27019},{"IP":"146.66.152.10","Port":27017},{"IP":"146.66.152.11","Port":27017},{"IP":"146.66.152.11","Port":27019},{"IP":"146.66.152.11","Port":27018},{"IP":"146.66.152.11","Port":27020},{"IP":"162.254.197.40","Port":27018},{"IP":"162.254.197.41","Port":27018},{"IP":"162.254.197.42","Port":27019},{"IP":"162.254.197.42","Port":27020},{"IP":"162.254.197.40","Port":27017},{"IP":"162.254.197.40","Port":27020},{"IP":"146.66.152.10","Port":27019},{"IP":"162.254.197.42","Port":27017},{"IP":"162.254.197.41","Port":27017},{"IP":"162.254.197.40","Port":27019},{"IP":"162.254.197.41","Port":27021},{"IP":"146.66.152.10","Port":27018},{"IP":"162.254.197.41","Port":27020},{"IP":"162.254.196.43","Port":27020},{"IP":"162.254.196.43","Port":27017},{"IP":"162.254.196.42","Port":27019},{"IP":"162.254.196.42","Port":27017},{"IP":"162.254.196.43","Port":27019},{"IP":"162.254.196.43","Port":27018},{"IP":"162.254.196.42","Port":27018},{"IP":"162.254.196.41","Port":27021},{"IP":"162.254.196.40","Port":27020},{"IP":"162.254.196.40","Port":27019},{"IP":"162.254.196.41","Port":27017},{"IP":"162.254.196.40","Port":27018},{"IP":"162.254.196.43","Port":27021},{"IP":"162.254.196.41","Port":27018},{"IP":"162.254.196.41","Port":27020},{"IP":"162.254.197.40","Port":27021},{"IP":"162.254.196.41","Port":27019},{"IP":"162.254.196.40","Port":27021},{"IP":"162.254.196.42","Port":27021},{"IP":"162.254.196.40","Port":27017},{"IP":"162.254.196.42","Port":27020},{"IP":"146.66.155.8","Port":27019},{"IP":"185.25.182.10","Port":27018},{"IP":"185.25.182.10","Port":27020},{"IP":"185.25.182.10","Port":27017},{"IP":"146.66.155.8","Port":27017},{"IP":"185.25.180.14","Port":27018},{"IP":"185.25.180.14","Port":27017},{"IP":"185.25.182.10","Port":27019},{"IP":"146.66.155.8","Port":27018},{"IP":"185.25.180.15","Port":27018},{"IP":"155.133.242.9","Port":27017},{"IP":"185.25.180.15","Port":27017},{"IP":"185.25.180.15","Port":27019},{"IP":"155.133.242.8","Port":27019},{"IP":"155.133.242.9","Port":27019},{"IP":"185.25.180.14","Port":27020},{"IP":"155.133.242.9","Port":27020},{"IP":"155.133.242.8","Port":27020},{"IP":"185.25.180.14","Port":27019},{"IP":"146.66.155.8","Port":27020},{"IP":"185.25.180.15","Port":27020},{"IP":"155.133.242.8","Port":27017},{"IP":"155.133.242.9","Port":27018},{"IP":"155.133.242.8","Port":27018},{"IP":"208.78.164.13","Port":27017},{"IP":"208.78.164.12","Port":27018},{"IP":"208.78.164.10","Port":27019},{"IP":"208.78.164.10","Port":27018},{"IP":"208.78.164.13","Port":27019},{"IP":"208.78.164.12","Port":27019},{"IP":"208.78.164.14","Port":27017},{"IP":"208.78.164.13","Port":27018},{"IP":"208.78.164.14","Port":27019},{"IP":"208.78.164.12","Port":27017},{"IP":"208.78.164.14","Port":27018},{"IP":"208.78.164.10","Port":27017},{"IP":"162.254.195.44","Port":27018}]}
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -202,6 +203,7 @@ func AddNewUser(jid, steamLogin, steamPwd string, debugMessage bool) {
|
||||||
|
|
||||||
g.XMPP_Out = comp.Out
|
g.XMPP_Out = comp.Out
|
||||||
g.XMPP_Connected_Client = make(map[string]bool)
|
g.XMPP_Connected_Client = make(map[string]bool)
|
||||||
|
g.XMPP_Composing_Timers = make(map[string]*time.Timer)
|
||||||
g.DebugMessage = debugMessage
|
g.DebugMessage = debugMessage
|
||||||
|
|
||||||
MapGatewayInfo[jid] = g
|
MapGatewayInfo[jid] = g
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue