Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
l-n-s
gajim
Commits
f2beea0d
Commit
f2beea0d
authored
6 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
Refactor Caps module
parent
a289ad5f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/common/modules/caps.py
+21
-40
21 additions, 40 deletions
gajim/common/modules/caps.py
gajim/common/modules/presence.py
+0
-29
0 additions, 29 deletions
gajim/common/modules/presence.py
with
21 additions
and
69 deletions
gajim/common/modules/caps.py
+
21
−
40
View file @
f2beea0d
# Copyright (C) 2009 Stephan Erb <steve-e AT h3c.de>
# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
#
# This file is part of Gajim.
#
...
...
@@ -19,12 +20,11 @@
import
logging
import
nbxmpp
from
nbxmpp.structs
import
StanzaHandler
from
gajim.common
import
caps_cache
from
gajim.common
import
app
from
gajim.common.nec
import
NetworkEvent
from
gajim.common.modules.presence
import
parse_show
from
gajim.common.modules.presence
import
parse_type
log
=
logging
.
getLogger
(
'
gajim.c.m.caps
'
)
...
...
@@ -35,69 +35,50 @@ class Caps:
self
.
_account
=
con
.
name
self
.
handlers
=
[
(
'
presence
'
,
self
.
_presence_received
,
''
,
nbxmpp
.
NS_CAPS
)
StanzaHandler
(
name
=
'
presence
'
,
callback
=
self
.
_entity_caps
,
ns
=
nbxmpp
.
NS_CAPS
,
priority
=
45
),
]
self
.
_capscache
=
caps_cache
.
capscache
self
.
_create_suitable_client_caps
=
caps_cache
.
create_suitable_client_caps
def
_
presence_received
(
self
,
_con
,
stanza
):
if
stanza
.
getType
()
in
(
'
unavailable
'
,
'
error
'
)
:
def
_
entity_caps
(
self
,
_con
,
_
stanza
,
properties
):
if
properties
.
type
.
is_error
or
properties
.
type
.
is_unavailable
:
return
from_
=
stanza
.
getFrom
()
if
from_
is
None
:
# Presence from ourself
if
properties
.
is_self_presence
:
return
full_jid
=
str
(
from_
)
hash_method
=
node
=
caps_hash
=
None
jid
=
str
(
properties
.
jid
)
caps
=
stanza
.
getTag
(
'
c
'
,
namespace
=
nbxmpp
.
NS_CAPS
)
if
caps
is
not
None
:
hash_method
=
caps
[
'
hash
'
]
node
=
caps
[
'
node
'
]
caps_hash
=
caps
[
'
ver
'
]
show
=
parse_show
(
stanza
)
type_
=
parse_type
(
stanza
)
hash_method
=
properties
.
entity_caps
.
hash
node
=
properties
.
entity_caps
.
node
caps_hash
=
properties
.
entity_caps
.
ver
log
.
info
(
'
Received from %s, type: %s, method: %s, node: %s, hash: %s
'
,
from_
,
stanza
.
getT
ype
()
,
hash_method
,
node
,
caps_hash
)
jid
,
properties
.
t
ype
,
hash_method
,
node
,
caps_hash
)
client_caps
=
self
.
_create_suitable_client_caps
(
node
,
caps_hash
,
hash_method
,
full_
jid
)
node
,
caps_hash
,
hash_method
,
jid
)
# Type is None means 'available'
if
stanza
.
getType
()
is
Non
e
and
client_caps
.
_hash_method
==
'
no
'
:
if
properties
.
type
.
is_availabl
e
and
client_caps
.
_hash_method
==
'
no
'
:
self
.
_capscache
.
forget_caps
(
client_caps
)
client_caps
=
self
.
_create_suitable_client_caps
(
node
,
caps_hash
,
hash_method
)
else
:
self
.
_capscache
.
query_client_of_jid_if_unknown
(
self
.
_con
,
full_
jid
,
client_caps
)
self
.
_con
,
jid
,
client_caps
)
self
.
_update_client_caps_of_contact
(
f
ro
m_
,
client_caps
)
self
.
_update_client_caps_of_contact
(
p
ro
perties
.
jid
,
client_caps
)
# Event is only used by ClientIcons Plugin
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'
caps-
presence-received
'
,
NetworkEvent
(
'
caps-
update
'
,
conn
=
self
.
_con
,
fjid
=
full_jid
,
jid
=
from_
.
getStripped
(),
resource
=
from_
.
getResource
(),
hash_method
=
hash_method
,
node
=
node
,
caps_hash
=
caps_hash
,
client_caps
=
client_caps
,
show
=
show
,
ptype
=
type_
,
stanza
=
stanza
))
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'
caps-update
'
,
conn
=
self
.
_con
,
fjid
=
full_jid
,
jid
=
from_
.
getStripped
()))
fjid
=
jid
,
jid
=
properties
.
jid
.
getBare
()))
def
_update_client_caps_of_contact
(
self
,
from_
,
client_caps
):
contact
=
self
.
_get_contact_or_gc_contact_for_jid
(
from_
)
...
...
This diff is collapsed.
Click to expand it.
gajim/common/modules/presence.py
+
0
−
29
View file @
f2beea0d
...
...
@@ -389,34 +389,5 @@ class Presence:
self
.
_con
.
connection
.
send
(
presence
)
def
parse_show
(
stanza
):
show
=
stanza
.
getShow
()
type_
=
parse_type
(
stanza
)
if
show
is
None
and
type_
is
None
:
return
'
online
'
if
type_
==
'
unavailable
'
:
return
'
offline
'
if
show
not
in
(
None
,
'
chat
'
,
'
away
'
,
'
xa
'
,
'
dnd
'
):
log
.
warning
(
'
Invalid show element: %s
'
,
stanza
)
if
type_
is
None
:
return
'
online
'
return
'
offline
'
if
show
is
None
:
return
'
online
'
return
show
def
parse_type
(
stanza
):
type_
=
stanza
.
getType
()
if
type_
not
in
(
None
,
'
unavailable
'
,
'
error
'
,
'
subscribe
'
,
'
subscribed
'
,
'
unsubscribe
'
,
'
unsubscribed
'
):
log
.
warning
(
'
Invalid type: %s
'
,
stanza
)
return
None
return
type_
def
get_instance
(
*
args
,
**
kwargs
):
return
Presence
(
*
args
,
**
kwargs
),
'
Presence
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment