Merge pull request #55 from ordbogen/master

Include delay in chats
This commit is contained in:
mattn 2015-05-17 08:48:20 +09:00
commit b5c8af17a7

25
xmpp.go
View File

@ -30,6 +30,7 @@ import (
"net/url" "net/url"
"os" "os"
"strings" "strings"
"time"
) )
const ( const (
@ -274,11 +275,11 @@ func (c *Client) init(o *Options) error {
var domain string var domain string
a := strings.SplitN(o.User, "@", 2) a := strings.SplitN(o.User, "@", 2)
if len(o.User) > 0 { if len(o.User) > 0 {
if len(a) != 2 { if len(a) != 2 {
return errors.New("xmpp: invalid username (want user@domain): " + o.User) return errors.New("xmpp: invalid username (want user@domain): " + o.User)
} }
domain = a[1] domain = a[1]
} // Otherwise, we'll be attempting ANONYMOUS } // Otherwise, we'll be attempting ANONYMOUS
// Declare intent to be a jabber client and gather stream features. // Declare intent to be a jabber client and gather stream features.
@ -531,6 +532,7 @@ type Chat struct {
Text string Text string
Roster Roster Roster Roster
Other []string Other []string
Stamp time.Time
} }
type Roster []Contact type Roster []Contact
@ -559,7 +561,18 @@ func (c *Client) Recv() (stanza interface{}, err error) {
} }
switch v := val.(type) { switch v := val.(type) {
case *clientMessage: case *clientMessage:
return Chat{Remote: v.From, Type: v.Type, Text: v.Body, Other: v.Other}, nil stamp, _ := time.Parse(
"2006-01-02T15:04:05Z",
v.Delay.Stamp,
)
chat := Chat{
Remote: v.From,
Type: v.Type,
Text: v.Body,
Other: v.Other,
Stamp: stamp,
}
return chat, nil
case *clientQuery: case *clientQuery:
var r Roster var r Roster
for _, item := range v.Item { for _, item := range v.Item {
@ -679,6 +692,12 @@ type clientMessage struct {
// Any hasn't matched element // Any hasn't matched element
Other []string `xml:",any"` Other []string `xml:",any"`
Delay Delay `xml:"delay"`
}
type Delay struct {
Stamp string `xml:"stamp,attr"`
} }
type clientText struct { type clientText struct {