Skip to content

Commit

Permalink
Merge pull request xmppo#55 from ordbogen/master
Browse files Browse the repository at this point in the history
Include delay in chats
  • Loading branch information
mattn committed May 16, 2015
2 parents c8c5371 + 02e4234 commit b5c8af1
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions xmpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net/url"
"os"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -274,11 +275,11 @@ func (c *Client) init(o *Options) error {

var domain string
a := strings.SplitN(o.User, "@", 2)
if len(o.User) > 0 {
if len(o.User) > 0 {
if len(a) != 2 {
return errors.New("xmpp: invalid username (want user@domain): " + o.User)
}
domain = a[1]
domain = a[1]
} // Otherwise, we'll be attempting ANONYMOUS

// Declare intent to be a jabber client and gather stream features.
Expand Down Expand Up @@ -531,6 +532,7 @@ type Chat struct {
Text string
Roster Roster
Other []string
Stamp time.Time
}

type Roster []Contact
Expand Down Expand Up @@ -559,7 +561,18 @@ func (c *Client) Recv() (stanza interface{}, err error) {
}
switch v := val.(type) {
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:
var r Roster
for _, item := range v.Item {
Expand Down Expand Up @@ -679,6 +692,12 @@ type clientMessage struct {

// Any hasn't matched element
Other []string `xml:",any"`

Delay Delay `xml:"delay"`
}

type Delay struct {
Stamp string `xml:"stamp,attr"`
}

type clientText struct {
Expand Down

0 comments on commit b5c8af1

Please sign in to comment.