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
72fc96ae
Commit
72fc96ae
authored
6 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
Refactor Annotations
- Simplify modules because nbxmpp handles more stuff
parent
11c5fd29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gajim/common/connection.py
+2
-2
2 additions, 2 deletions
gajim/common/connection.py
gajim/common/modules/annotations.py
+25
-63
25 additions, 63 deletions
gajim/common/modules/annotations.py
gajim/vcard.py
+10
-8
10 additions, 8 deletions
gajim/vcard.py
with
37 additions
and
73 deletions
gajim/common/connection.py
+
2
−
2
View file @
72fc96ae
...
...
@@ -1488,7 +1488,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self
.
get_module
(
'
Bookmarks
'
).
request_bookmarks
()
# Get annotations
self
.
get_module
(
'
Annotations
'
).
ge
t_annotations
()
self
.
get_module
(
'
Annotations
'
).
reques
t_annotations
()
# Blocking
self
.
get_module
(
'
Blocking
'
).
get_blocking_list
()
...
...
@@ -1614,7 +1614,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self
.
get_module
(
'
VCardTemp
'
).
request_vcard
()
self
.
get_module
(
'
Bookmarks
'
).
request_bookmarks
()
self
.
get_module
(
'
Annotations
'
).
ge
t_annotations
()
self
.
get_module
(
'
Annotations
'
).
reques
t_annotations
()
self
.
get_module
(
'
Blocking
'
).
get_blocking_list
()
# Inform GUI we just signed in
...
...
This diff is collapsed.
Click to expand it.
gajim/common/modules/annotations.py
+
25
−
63
View file @
72fc96ae
...
...
@@ -16,87 +16,49 @@
from
typing
import
Any
from
typing
import
Dict
# pylint: disable=unused-import
from
typing
import
List
# pylint: disable=unused-import
from
typing
import
Tuple
import
logging
import
nbxmpp
from
nbxmpp
.util
import
is_error_result
from
gajim.common
import
app
from
gajim.common
import
helpers
from
gajim.common.types
import
ConnectionT
from
gajim.common.modules.base
import
BaseModule
log
=
logging
.
getLogger
(
'
gajim.c.m.annotations
'
)
class
Annotations
:
def
__init__
(
self
,
con
:
ConnectionT
)
->
None
:
self
.
_con
=
con
self
.
_account
=
con
.
name
self
.
_server
=
self
.
_con
.
get_own_jid
().
getDomain
()
class
Annotations
(
BaseModule
):
self
.
handlers
=
[]
# type: List[Tuple[Any, ...]]
self
.
annotations
=
{}
# type: Dict[str, str]
_nbxmpp_extends
=
'
Annotations
'
_nbxmpp_methods
=
[
'
request_annotations
'
,
'
set_annotations
'
,
]
def
get_annotations
(
self
)
->
None
:
if
not
app
.
account_is_connected
(
self
.
_account
):
return
log
.
info
(
'
Request annotations for %s
'
,
self
.
_server
)
iq
=
nbxmpp
.
Iq
(
typ
=
'
get
'
)
iq2
=
iq
.
addChild
(
name
=
'
query
'
,
namespace
=
nbxmpp
.
NS_PRIVATE
)
iq2
.
addChild
(
name
=
'
storage
'
,
namespace
=
'
storage:rosternotes
'
)
def
__init__
(
self
,
con
:
ConnectionT
):
BaseModule
.
__init__
(
self
,
con
)
self
.
_con
.
connection
.
SendAndCallForResponse
(
iq
,
self
.
_result_received
)
self
.
_register_callback
(
'
request_annotations
'
,
self
.
_annotations_received
)
self
.
_annotations
=
{}
# type: Dict[str, Any]
def
_result_received
(
self
,
stanza
:
nbxmpp
.
Iq
)
->
None
:
if
not
nbxmpp
.
isResultNode
(
stanza
):
log
.
info
(
'
Error: %s
'
,
stanza
.
getError
())
return
def
set_annotations
(
self
):
self
.
_nbxmpp
(
'
Annotations
'
).
set_annotations
(
self
.
_annotations
.
values
())
log
.
info
(
'
Received annotations from %s
'
,
self
.
_server
)
self
.
annotations
=
{}
query
=
stanza
.
getTag
(
'
query
'
)
storage_node
=
query
.
getTag
(
'
storage
'
)
if
storage_node
is
None
:
def
_annotations_received
(
self
,
result
):
if
is_error_result
(
result
):
self
.
_annotations
=
{}
return
for
note
in
result
:
self
.
_annotations
[
note
.
jid
]
=
note
notes
=
storage_node
.
getTags
(
'
note
'
)
if
notes
is
None
:
return
def
get_note
(
self
,
jid
):
return
self
.
_annotations
.
get
(
jid
)
for
note
in
notes
:
try
:
jid
=
helpers
.
parse_jid
(
note
.
getAttr
(
'
jid
'
))
except
helpers
.
InvalidFormat
:
log
.
warning
(
'
Invalid JID: %s, ignoring it
'
,
note
.
getAttr
(
'
jid
'
))
continue
self
.
annotations
[
jid
]
=
note
.
getData
()
def
store_annotations
(
self
)
->
None
:
if
not
app
.
account_is_connected
(
self
.
_account
):
return
iq
=
nbxmpp
.
Iq
(
typ
=
'
set
'
)
iq2
=
iq
.
addChild
(
name
=
'
query
'
,
namespace
=
nbxmpp
.
NS_PRIVATE
)
iq3
=
iq2
.
addChild
(
name
=
'
storage
'
,
namespace
=
'
storage:rosternotes
'
)
for
jid
in
self
.
annotations
:
if
self
.
annotations
[
jid
]:
iq4
=
iq3
.
addChild
(
name
=
'
note
'
)
iq4
.
setAttr
(
'
jid
'
,
jid
)
iq4
.
setData
(
self
.
annotations
[
jid
])
self
.
_con
.
connection
.
SendAndCallForResponse
(
iq
,
self
.
_store_result_received
)
@staticmethod
def
_store_result_received
(
stanza
:
nbxmpp
.
Iq
)
->
None
:
if
not
nbxmpp
.
isResultNode
(
stanza
):
log
.
warning
(
'
Storing rosternotes failed: %s
'
,
stanza
.
getError
())
return
log
.
info
(
'
Storing rosternotes successful
'
)
def
set_note
(
self
,
note
):
self
.
_annotations
[
note
.
jid
]
=
note
self
.
set_annotations
()
def
get_instance
(
*
args
:
Any
,
**
kwargs
:
Any
)
->
Tuple
[
Annotations
,
str
]:
...
...
This diff is collapsed.
Click to expand it.
gajim/vcard.py
+
10
−
8
View file @
72fc96ae
...
...
@@ -32,6 +32,7 @@ import binascii
from
gi.repository
import
Gtk
from
gi.repository
import
GLib
from
gi.repository
import
Gdk
from
nbxmpp.structs
import
AnnotationNote
from
gajim
import
gtkgui_helpers
from
gajim.gui_menu_builder
import
show_save_as_menu
...
...
@@ -108,10 +109,10 @@ class VcardWindow:
self
.
fill_jabber_page
()
con
=
app
.
connections
[
self
.
account
]
an
not
ations
=
con
.
get_module
(
'
Annotations
'
).
annotations
if
self
.
contact
.
jid
in
annotati
on
s
:
not
e
=
con
.
get_module
(
'
Annotations
'
).
get_note
(
self
.
contact
.
jid
)
if
note
is
not
N
on
e
:
buffer_
=
self
.
xml
.
get_object
(
'
textview_annotation
'
).
get_buffer
()
buffer_
.
set_text
(
an
not
ations
[
self
.
contact
.
jid
]
)
buffer_
.
set_text
(
not
e
.
data
)
for
widget_name
in
(
'
URL_label
'
,
'
EMAIL_WORK_USERID_label
'
,
...
...
@@ -140,12 +141,13 @@ class VcardWindow:
del
app
.
interface
.
instances
[
self
.
account
][
'
infos
'
][
self
.
contact
.
jid
]
buffer_
=
self
.
xml
.
get_object
(
'
textview_annotation
'
).
get_buffer
()
new_annotation
=
buffer_
.
get_text
(
buffer_
.
get_start_iter
(),
buffer_
.
get_end_iter
(),
True
)
buffer_
.
get_end_iter
(),
True
)
con
=
app
.
connections
[
self
.
account
]
an
not
ations
=
con
.
get_module
(
'
Annotations
'
).
annotations
if
new_annotation
!=
an
not
ations
.
get
(
self
.
contact
.
jid
,
''
)
:
annotations
[
self
.
contact
.
jid
]
=
new_annotation
con
.
get_module
(
'
Annotations
'
).
s
tore_annotations
(
)
not
e
=
con
.
get_module
(
'
Annotations
'
).
get_note
(
self
.
contact
.
jid
)
if
note
is
None
or
new_annotation
!=
not
e
.
data
:
new_note
=
AnnotationNote
(
jid
=
self
.
contact
.
jid
,
data
=
new_annotation
)
con
.
get_module
(
'
Annotations
'
).
s
et_note
(
new_note
)
app
.
ged
.
remove_event_handler
(
'
version-result-received
'
,
ged
.
GUI1
,
self
.
set_os_info
)
app
.
ged
.
remove_event_handler
(
'
time-result-received
'
,
ged
.
GUI1
,
...
...
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