From: Pat Thoyts Date: Fri, 20 Jun 2008 10:11:09 +0000 (+0100) Subject: xep-0203: handle delayed delivery of messages in groupchat. X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=1f39feb34ccfc6ca787691eea05e56919855eff7;p=Bullfrog xep-0203: handle delayed delivery of messages in groupchat. --- diff --git a/bin/bf_xmpp.tcl b/bin/bf_xmpp.tcl index 82b7233..f70fe2b 100644 --- a/bin/bf_xmpp.tcl +++ b/bin/bf_xmpp.tcl @@ -632,6 +632,15 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { [wrapper::getfirstchildwithxmlns $xmldata http://jabber.org/protocol/chatstates]] set receipt [wrapper::getchildswithtagandxmlns $xmldata request urn:xmpp:receipts] + set time [clock seconds] + set delay [lindex [wrapper::getchildswithtag $xmldata delay] 0] + if {$delay ne {}} { + set stamp [wrapper::getattribute $delay stamp] + if {[catch {set time [clock scan $stamp -format {%Y-%m-%dT%H:%M:%S%Z}]} err]} { + Log $ctx "Delayed delivery error \"$stamp\": $err" + } + } + foreach x [wrapper::getchildswithtag $xmldata x] { switch -exact -- [wrapper::getattribute $x xmlns] { "jabber:x:delay" {} @@ -671,7 +680,8 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { set newnick [lindex [split $msg] 4] } } - Callback $ctx traffic $what $fromjid $fromres $newnick -group irc + Callback $ctx traffic $what $fromjid $fromres \ + $newnick $time -group irc return 0 } elseif {[regexp {^\* (\S+) (.*)$} $msg -> fromres msg]} { set what action @@ -683,7 +693,7 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { set msg [string range $msg 3 end] } if {[string length $msg] > 0} { - Callback $ctx chat $fromjid $fromres $msg $what + Callback $ctx chat $fromjid $fromres $msg $what $time } } chat { @@ -719,7 +729,7 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { if {[llength $body] > 0} { Callback $ctx chat $a(from) $nick \ - [wrapper::getcdata [lindex $body 0]] normal + [wrapper::getcdata [lindex $body 0]] normal $time } } normal { @@ -728,13 +738,6 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { if {[llength $nicktag] >0} { set from "[wrapper::getcdata [lindex $nicktag 0]] <$from>" } - set time [clock seconds] - set delay [lindex [wrapper::getchildswithtag $xmldata delay] 0] - if {$delay ne {}} { - set stamp [wrapper::getattribute $delay stamp] - catch {set time [clock scan $da(stamp) \ - -format {%Y-%m-%dT%H:%M:%S%Z}]} - } set p [list -date $time -subject $subject] if {$thread ne {}} {lappend p -thread $thread} lappend p -body [set bodydata [wrapper::getcdata [lindex $body 0]]] @@ -744,7 +747,7 @@ proc ::xmppplugin::OnMessage2 {ctx jlib xmldata} { } headline { Callback $ctx chat $a(to) $a(from) \ - "header: [wrapper::etcdata [lindex $body 0]]" normal + "header: [wrapper::etcdata [lindex $body 0]]" normal $time Log $ctx "$a(from)->$a(to) headline $xmldata" } error { @@ -788,16 +791,6 @@ proc ::xmppplugin::query_user {Chat user what} { return } -proc ::xmppplugin::SendReceipt {Chat} { - lappend xlist [wrapper::createtag received \ - -attrlist {xmlns urn:xmpp:receipts}] - set margs [list -type $chat(type) -xlist $xlist] - if {![catch {set thread [dict get $xmpp(opts) $chat(channel) -thread]}]} { - lappend margs -thread $thread - } - eval [linsert $margs 0 $xmpp(jlib) send_message $chat(channel)] -} - package provide xmppplugin $::xmppplugin::version # ------------------------------------------------------------------------- @@ -1287,7 +1280,7 @@ proc XmppCallback {Session context state args} { } close { foreach {target} $args break - Debug $Session [mc "closing $s" $target] + Debug $Session [mc "closing %s" $target] XmppRemoveWindow $Session $target } addchat { @@ -1351,14 +1344,15 @@ proc XmppCallback {Session context state args} { } } chat { - foreach {target nick msg type} $args break + foreach {target nick msg type time} $args break if {$type eq ""} {set type normal} + if {$time eq ""} {set time [clock seconds]} set w [XmppCreateWindow $Session $target -type chat] XmppAlert $Session $target switch -exact -- [winfo class $w] { - Chatwidget {$w message $msg -nick $nick -type $type} + Chatwidget {$w message $msg -nick $nick -type $type -time $time} Messagewidget { - $w add -from $nick -to Me -body $msg -date [clock seconds] + $w add -from $nick -to Me -body $msg -date $time } default {puts stderr "invalid chat target \"$target\""} } @@ -1393,27 +1387,28 @@ proc XmppCallback {Session context state args} { } } traffic { - foreach {action target nick new} $args break + foreach {action target nick new time} $args break + if {$time eq ""} {set time [clock seconds]} set w [XmppFindWindow $Session $target] if {[winfo class $w] ne "Chatwidget"} {return} switch -exact -- $action { joining { XmppCreateWindow $Session $target -type groupchat} entered { eval [linsert $args 0 $w name add $nick] - $w message [mc "%s entered" $nick] -nick $nick -type system + $w message [mc "%s entered" $nick] -nick $nick -time $time -type system } left { $w name delete $nick - $w message [mc "%s left" $nick] -nick $nick -type system + $w message [mc "%s left" $nick] -nick $nick -time $time -type system } nickchange { $w name delete $nick eval [linsert $args 0 $w name add $new] $w message [mc "%s is now known as %s" $nick $new] \ - -nick $nick -type system + -nick $nick -time $time -type system } default { - $w message "$nick $action" -nick $nick -type system + $w message "$nick $action" -nick $nick -time $time -type system } } } diff --git a/bin/message.tcl b/bin/message.tcl index a186c28..a7ab287 100644 --- a/bin/message.tcl +++ b/bin/message.tcl @@ -142,6 +142,8 @@ proc messagewidget::DisplayTime {time} { return $r } +# -date : date/time as clock seconds +# proc messagewidget::Add {self args} { upvar #0 [namespace current]::$self state set msg [eval [linsert $args 0 dict create -state U \