Tkabber contrib

Check-in [937698bef0]
Login

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

Overview
Comment:[juick] Remove a roster push hook which asks juick.com for my nickname since this query is no lnger supported.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 937698bef056946f63b3906fa134e7d2ba8aaf01
User & Date: sgolovan 2018-03-16 04:16:46
Context
2020-07-06
07:14
Add a set of client icons (thanks to Lev Mikhailov). check-in: e4d9cc5d47 user: sgolovan tags: trunk
2018-03-16
04:16
[juick] Remove a roster push hook which asks juick.com for my nickname since this query is no lnger supported. check-in: 937698bef0 user: sgolovan tags: trunk
2016-06-29
22:55
juick: Code refactoring mixed with handling Juick changes More or less accurate history of changes can be found in [1]. [1]: https://github.com/Totktonada/tkabber4juick/ check-in: 7e0bf9ef1f user: totktonada tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to juick/juick.tcl.

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
option add *juick_tag         ForestGreen  widgetDefault
option add *juick_my_msg      gray         widgetDefault

# Global variables and constants
# ==============================

variable options
variable nicknames

# list of {tag_name xrdb_name xrdb_option} sequences
# used in 'configurator' proc
variable richtext_tags {
    juick_number  juick_number     foreground
    juick_private juick_private_fg foreground
    juick_private juick_private_bg background







<







32
33
34
35
36
37
38

39
40
41
42
43
44
45
option add *juick_tag         ForestGreen  widgetDefault
option add *juick_my_msg      gray         widgetDefault

# Global variables and constants
# ==============================

variable options


# list of {tag_name xrdb_name xrdb_option} sequences
# used in 'configurator' proc
variable richtext_tags {
    juick_number  juick_number     foreground
    juick_private juick_private_fg foreground
    juick_private juick_private_bg background
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    juick_private                 48
    juick_citing                  48
    juick_nicks_tags              49
}

# list of {hook proc priority orig_proc} sequences
variable plugin_hooks {
    roster_push_hook          determine_juick_nick       99 ""
    draw_message_hook         ignore_server_messages      0 ""
    draw_message_hook         draw_message_handle        21 ""
    chat_window_click_hook    insert_by_click            99 ""
    chat_win_popup_menu_hook  add_chat_things_menu       20 ""
    rewrite_message_hook      rewrite_incoming_message   20 ""
    chat_send_message_hook    rewrite_subscribe_plus_cmd 19 ""
    generate_completions_hook juick_commands_comps       99 ""







<







66
67
68
69
70
71
72

73
74
75
76
77
78
79
    juick_private                 48
    juick_citing                  48
    juick_nicks_tags              49
}

# list of {hook proc priority orig_proc} sequences
variable plugin_hooks {

    draw_message_hook         ignore_server_messages      0 ""
    draw_message_hook         draw_message_handle        21 ""
    chat_window_click_hook    insert_by_click            99 ""
    chat_win_popup_menu_hook  add_chat_things_menu       20 ""
    rewrite_message_hook      rewrite_incoming_message   20 ""
    chat_send_message_hook    rewrite_subscribe_plus_cmd 19 ""
    generate_completions_hook juick_commands_comps       99 ""
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
207
208
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
250

        if {$orig_proc ne ""} {
            hook::add $hook $orig_proc $priority
        }
    }
}

proc juick::determine_juick_nick {xlib jid name groups subsc ask} {
    variable options
    variable nicknames

    if {![info exists options(special_update_juick_tab)] \
        || ! $options(special_update_juick_tab)} \
    {
        return
    }

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

    # TODO
    # For Juick contacts connected via j2j transport is difficult
    # to determine user jid.
    # Idea: send iq register to proper j2j, get form, and read
    # second JID from it.
    if {[string first % $jid] >= 0} {
        return
    }

    set my_jid [connection_jid $xlib]
    set my_jid [::xmpp::jid::removeResource $my_jid]
    set nick_request_url "http://api.juick.com/users?jid=$my_jid"

    if {[catch {::http::geturl $nick_request_url} token]} {
        return
    }

    # Data format (json):
    # [{"uid":XXXX,"uname":"XXXX","jid":"XXXX@XXXX"}]
    set data [::http::data $token]
    ::http::cleanup $token

    # If has no json package, try to parse by regexp.
    if {[catch {package require json}]} {
        if {![regexp {\[{.*"uname"\w*:\w*"([^"]+)".*}\]} $data -> uname]} {
            # For vim syntax highlighter: "
            return
        }

        set nicknames($jid) $uname
        return
    }

    set ds [::json::json2dict $data]

    if {[llength $ds] != 1} {
        return
    }

    set d [lindex $ds 0]

    # If dict command not available...
    if {[catch {dict create}]} {
        # Try to load dict package...
        if {[catch {package require dict}]} {
            # If it fails, get uname value without dict command.
            foreach {key value} $d {
                switch -- $key {
                    uname { set uname $value }
                }
            }

            set nicknames($jid) $uname
            return
        }
    }

    if {[catch {dict get $d uname} uname]} {
        return
    }

    set nicknames($jid) $uname
}

proc juick::draw_message_handle {chatid from type body x} {
    if {[is_juick $chatid]} {
        # Allow juick::parser to process given chat as a juick chat.
        ::richtext::property_add {PROCESS_AS_JUICK_MESSAGE} {}
    } elseif {[is_jubo $chatid]} {
        # Allow juick::parser to process given chat as a jubo chat.
        ::richtext::property_add {PROCESS_AS_JUBO_MESSAGE} {}







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







157
158
159
160
161
162
163














































































164
165
166
167
168
169
170

        if {$orig_proc ne ""} {
            hook::add $hook $orig_proc $priority
        }
    }
}















































































proc juick::draw_message_handle {chatid from type body x} {
    if {[is_juick $chatid]} {
        # Allow juick::parser to process given chat as a juick chat.
        ::richtext::property_add {PROCESS_AS_JUICK_MESSAGE} {}
    } elseif {[is_jubo $chatid]} {
        # Allow juick::parser to process given chat as a jubo chat.
        ::richtext::property_add {PROCESS_AS_JUBO_MESSAGE} {}