2017-12-17 15:39:36 +01:00
|
|
|
package extension
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/xmpp"
|
2018-02-10 13:34:42 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/model"
|
2018-02-07 15:34:18 +01:00
|
|
|
"dev.sum7.eu/genofire/yaja/server/utils"
|
2017-12-17 15:39:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//TODO Draft
|
|
|
|
|
|
|
|
type IQLast struct {
|
|
|
|
IQExtension
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ex *IQLast) Spaces() []string { return []string{"jabber:iq:last"} }
|
|
|
|
|
2018-02-14 18:49:26 +01:00
|
|
|
func (ex *IQLast) Get(msg *xmpp.IQClient, client *utils.Client) bool {
|
2017-12-17 15:39:36 +01:00
|
|
|
log := client.Log.WithField("extension", "last").WithField("id", msg.ID)
|
|
|
|
|
|
|
|
// query encode
|
|
|
|
type query struct {
|
|
|
|
XMLName xml.Name `xml:"jabber:iq:last query"`
|
|
|
|
Seconds uint `xml:"seconds,attr,omitempty"`
|
|
|
|
Body []byte `xml:",innerxml"`
|
|
|
|
}
|
|
|
|
q := &query{}
|
2017-12-17 17:50:51 +01:00
|
|
|
if err := xml.Unmarshal(msg.Body, q); err != nil {
|
2017-12-17 15:39:36 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// answer query
|
|
|
|
q.Body = []byte{}
|
|
|
|
|
|
|
|
// build answer body
|
|
|
|
type item struct {
|
|
|
|
XMLName xml.Name `xml:"item"`
|
|
|
|
JID string `xml:"jid,attr"`
|
|
|
|
}
|
|
|
|
// decode query
|
|
|
|
queryByte, err := xml.Marshal(q)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// reply
|
2018-02-14 18:49:26 +01:00
|
|
|
client.Messages <- &xmpp.IQClient{
|
|
|
|
Type: xmpp.IQTypeResult,
|
2018-02-10 13:34:42 +01:00
|
|
|
To: client.JID,
|
2018-02-14 18:49:26 +01:00
|
|
|
From: xmpp.NewJID(client.JID.Domain),
|
2017-12-17 15:39:36 +01:00
|
|
|
ID: msg.ID,
|
|
|
|
Body: queryByte,
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("send")
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|