Tkabber contrib

Check-in [1c5dc5dda0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Juick plugin (svn branch): More simple way to determine personal message. Support of new juick feature (XMPP-API replytoyou attribute), remove deprecated feature (XMPP-API iq).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1c5dc5dda0f21d587988e834c0a8196da7c128bc
User & Date: toktonada 2013-09-18 17:02:58
Context
2013-09-18
17:37
Juick plugin (svn branch): Add option for more exact messages indicating. This option determines whether replies to your posts indicated as personal messages. Enabled by default. check-in: 3d70c858ea user: toktonada tags: trunk
17:02
Juick plugin (svn branch): More simple way to determine personal message. Support of new juick feature (XMPP-API replytoyou attribute), remove deprecated feature (XMPP-API iq). check-in: 1c5dc5dda0 user: toktonada tags: trunk
2013-07-21
15:08
Notes plugin: * Fix typo in TODO comment. * Optimize 'expr' usage and few indent fixes. * Fix string comparison by 'expr'. check-in: 71e0f4186f user: toktonada tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to juick/juick.tcl.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
209
210
211
212
213
214
215
216
217

218
219
220

221
222
223


224
225


226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    catch {source [file join $scriptdir \
        tkabber-0.11.1-compatibility.tcl]} \
        source_compatibility_file_result
}

namespace eval juick {
variable options
variable juick_nicknames
variable chat_things

::msgcat::mcload [file join [file dirname [info script]] msgs]

if {![::plugins::is_registered juick]} {
    ::plugins::register juick \
        -namespace [namespace current] \
................................................................................

    hook::add draw_message_hook \
        [namespace current]::add_number_of_messages_from_juick_to_title 18

    hook::remove draw_message_hook \
        ::::ifacetk::add_number_of_messages_to_title 18

    hook::add roster_push_hook \
        [namespace current]::request_juick_nick 99

    hook::add generate_completions_hook \
        [namespace current]::juick_commands_comps 99
}

proc unload {} {
    hook::remove draw_message_hook        \
        [namespace current]::ignore_server_messages 0
................................................................................

    hook::remove draw_message_hook \
        [namespace current]::add_number_of_messages_from_juick_to_title 18

    hook::add draw_message_hook \
        ::::ifacetk::add_number_of_messages_to_title 18

    hook::remove roster_push_hook \
        [namespace current]::request_juick_nick 99

    hook::remove generate_completions_hook \
        [namespace current]::juick_commands_comps 99

    ::richtext::entity_state juick_numbers 0
    ::richtext::entity_state citing 0
    ::richtext::entity_state juick 0
    ::richtext::entity_state juick_ligth 0
................................................................................

# Determines whether given chatid correspond to Juick
proc is_juick {chatid} {
    set jid [chat::get_jid $chatid]
    return [is_juick_jid $jid]
}

proc request_juick_nick {xlib jid name groups subsc ask} {
    variable juick_nicknames

    if {![is_juick_jid $jid] || [info exists juick_nicknames($jid)]} {
        return
    }

    ::xmpp::sendIQ $xlib get \
        -query [::xmpp::xml::create query \
            -xmlns "http://juick.com/query#users"] \
        -to $jid \
        -command [list [namespace current]::receive_juick_nick $jid]
}

proc receive_juick_nick {jid res child} {
    variable juick_nicknames

    if {![string equal $res ok]} return

    ::xmpp::xml::split $child tag xmlns attrs cdata subels

    if {![string equal $xmlns "http://juick.com/query#users"]} return

    set ch [lindex $subels 0]
    ::xmpp::xml::split $ch stag sxmlns sattrs scdata ssubels

    if {![string equal $sxmlns "http://juick.com/user"]} return

    set uname [::xmpp::xml::getAttr $sattrs uname]
    set juick_nicknames($jid) $uname

#    puts "For $jid: uname is \"$uname\""

    return
}

proc handle_message {chatid from type body x} {
    variable juick_nicknames

    if {![is_juick $chatid]} return

    ::richtext::property_add {JUICK} {}

    set chatw [chat::chat_win $chatid]
    set jid [chat::get_jid $chatid]

................................................................................
        lappend tags JMY
    }

    ::richtext::render_message $chatw $body $tags
    return stop
}

proc get_juick_nickname {jid} {
    variable juick_nicknames


    set uname ""
    set jid [::xmpp::jid::removeResource $jid]


    if {[info exists juick_nicknames($jid)]} {
        set uname $juick_nicknames($jid)


    }



    return $uname
}

proc is_personal_juick_message {from body} {
    variable juick_nicknames
    set reply_to_my_comment 0

    set private_msg [regexp {^Private message from @.+:\n} $body]

    set reply_to_comment [regexp \
        {Reply by @[^\n ]+:\n>.+\n\n@([^\n ]+) .+\n\n#\d+/\d+ http://juick.com/\d+#\d+$} \
        $body -> reply_to_nick]

    if {$reply_to_comment} {
        set reply_to_my_comment [string equal \
            [get_juick_nickname $from] $reply_to_nick]
    }

    return [expr {$private_msg || $reply_to_my_comment}]
}

proc update_juick_tab {chatid from type body x} {
    variable options
    if {!([is_juick_jid $from] && [string equal $type "chat"] \
        && $options(special_update_juick_tab))} \
................................................................................
        {
            return
        }
    }

    set cw [chat::winid $chatid]

    if {[is_personal_juick_message $from $body]} {
        tab_set_updated $cw 1 mesg_to_user
    } else {
        tab_set_updated $cw 1 message
    }
}

proc ignore_server_messages {chatid from type body x} {
................................................................................
    if {$from eq ""} return

    variable ::ifacetk::number_msg
    variable ::ifacetk::personal_msg

    incr number_msg($chatid)

    if {[is_personal_juick_message $from $body]} {
        incr personal_msg($chatid)
    }

    ::ifacetk::update_chat_title $chatid
    ::ifacetk::update_main_window_title
}








<







 







<
<
<







 







<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<







 







|
|
>

<
|
>
|
<
|
>
>
|
|
>
>
|


|
<
<
<

>




<
|
<
<
<







 







|







 







|







14
15
16
17
18
19
20

21
22
23
24
25
26
27
..
82
83
84
85
86
87
88



89
90
91
92
93
94
95
...
117
118
119
120
121
122
123



124
125
126
127
128
129
130
...
147
148
149
150
151
152
153




































154


155
156
157
158
159
160
161
...
164
165
166
167
168
169
170
171
172
173
174

175
176
177

178
179
180
181
182
183
184
185
186
187
188



189
190
191
192
193
194

195



196
197
198
199
200
201
202
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
    catch {source [file join $scriptdir \
        tkabber-0.11.1-compatibility.tcl]} \
        source_compatibility_file_result
}

namespace eval juick {
variable options

variable chat_things

::msgcat::mcload [file join [file dirname [info script]] msgs]

if {![::plugins::is_registered juick]} {
    ::plugins::register juick \
        -namespace [namespace current] \
................................................................................

    hook::add draw_message_hook \
        [namespace current]::add_number_of_messages_from_juick_to_title 18

    hook::remove draw_message_hook \
        ::::ifacetk::add_number_of_messages_to_title 18




    hook::add generate_completions_hook \
        [namespace current]::juick_commands_comps 99
}

proc unload {} {
    hook::remove draw_message_hook        \
        [namespace current]::ignore_server_messages 0
................................................................................

    hook::remove draw_message_hook \
        [namespace current]::add_number_of_messages_from_juick_to_title 18

    hook::add draw_message_hook \
        ::::ifacetk::add_number_of_messages_to_title 18




    hook::remove generate_completions_hook \
        [namespace current]::juick_commands_comps 99

    ::richtext::entity_state juick_numbers 0
    ::richtext::entity_state citing 0
    ::richtext::entity_state juick 0
    ::richtext::entity_state juick_ligth 0
................................................................................

# Determines whether given chatid correspond to Juick
proc is_juick {chatid} {
    set jid [chat::get_jid $chatid]
    return [is_juick_jid $jid]
}





































proc handle_message {chatid from type body x} {


    if {![is_juick $chatid]} return

    ::richtext::property_add {JUICK} {}

    set chatw [chat::chat_win $chatid]
    set jid [chat::get_jid $chatid]

................................................................................
        lappend tags JMY
    }

    ::richtext::render_message $chatw $body $tags
    return stop
}

proc is_reply_to_you {x} {
    foreach xe $x {
        ::xmpp::xml::split $xe tag xmlns attrs cdata subels


        if {[string equal $tag "juick"] && \
            [string equal $xmlns "http://juick.com/message"]} \
        {

            set replytoyou [::xmpp::xml::getAttr $attrs replytoyou false]
            if {[string equal $replytoyou true]} {
                return 1
            }
        }
    }

    return 0
}

proc is_personal_juick_message {from body x} {



    set private_msg [regexp {^Private message from @.+:\n} $body]

    set reply_to_comment [regexp \
        {Reply by @[^\n ]+:\n>.+\n\n@([^\n ]+) .+\n\n#\d+/\d+ http://juick.com/\d+#\d+$} \
        $body -> reply_to_nick]


    set reply_to_my_comment [expr {$reply_to_comment && [is_reply_to_you $x]}]



    return [expr {$private_msg || $reply_to_my_comment}]
}

proc update_juick_tab {chatid from type body x} {
    variable options
    if {!([is_juick_jid $from] && [string equal $type "chat"] \
        && $options(special_update_juick_tab))} \
................................................................................
        {
            return
        }
    }

    set cw [chat::winid $chatid]

    if {[is_personal_juick_message $from $body $x]} {
        tab_set_updated $cw 1 mesg_to_user
    } else {
        tab_set_updated $cw 1 message
    }
}

proc ignore_server_messages {chatid from type body x} {
................................................................................
    if {$from eq ""} return

    variable ::ifacetk::number_msg
    variable ::ifacetk::personal_msg

    incr number_msg($chatid)

    if {[is_personal_juick_message $from $body $x]} {
        incr personal_msg($chatid)
    }

    ::ifacetk::update_chat_title $chatid
    ::ifacetk::update_main_window_title
}

Changes to juick/tkabber-0.11.1-compatibility.tcl.

179
180
181
182
183
184
185
186
187








188
189
190
191
192
193
194
    if {[string equal $res OK]} {
        set res ok
    }

    uplevel #0 $cmd [list $res $child]
}

proc ::xmpp::xml::getAttr {attrList attrName} {
    ::jlib::wrapper:getattr $attrList $attrName








}

proc ::chat::activate {chatid} {
    raise_win [winid $chatid]
    focus -force [input_win $chatid]
}








|
|
>
>
>
>
>
>
>
>







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
    if {[string equal $res OK]} {
        set res ok
    }

    uplevel #0 $cmd [list $res $child]
}

proc ::xmpp::xml::getAttr {attrList attrName {fallback ""}} {
    set res $fallback

    foreach {attr val} $attrList {
        if {[string equal $attr $attrName]} {
            set res $val
        }
    }

    return $res
}

proc ::chat::activate {chatid} {
    raise_win [winid $chatid]
    focus -force [input_win $chatid]
}