Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Python Briar Wrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
briar
Python Briar Wrapper
Merge requests
!10
Add method to watch connection state of contacts
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add method to watch connection state of contacts
watch-contact-state
into
main
Overview
0
Commits
1
Pipelines
6
Changes
2
Merged
Nico
requested to merge
watch-contact-state
into
main
5 years ago
Overview
0
Commits
1
Pipelines
6
Changes
2
Expand
Related to:
briar-gtk#19 (closed)
briar!1260 (merged)
0
0
Merge request reports
Compare
main
version 5
a121c076
5 years ago
version 4
6abd0c98
5 years ago
version 3
98942266
5 years ago
version 2
53ad4df3
5 years ago
version 1
46be979d
5 years ago
main (base)
and
latest version
latest version
8969b057
1 commit,
5 years ago
version 5
a121c076
1 commit,
5 years ago
version 4
6abd0c98
1 commit,
5 years ago
version 3
98942266
1 commit,
5 years ago
version 2
53ad4df3
1 commit,
5 years ago
version 1
46be979d
1 commit,
5 years ago
2 files
+
46
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
briar_wrapper/models/contacts.py
+
22
−
0
Options
@@ -15,6 +15,9 @@ from briar_wrapper.model import Model
class
Contacts
(
Model
):
API_ENDPOINT
=
"
contacts/
"
CONNECTION_EVENTS
=
(
"
ContactConnectedEvent
"
,
"
ContactDisconnectedEvent
"
)
_connections_callback
=
None
def
add_pending
(
self
,
link
,
alias
):
url
=
urljoin
(
BASE_HTTP_URL
,
self
.
API_ENDPOINT
+
"
add/pending/
"
)
@@ -32,6 +35,25 @@ class Contacts(Model):
request
=
_get
(
url
,
headers
=
self
.
_headers
).
json
()
return
request
[
'
link
'
]
def
watch_connections
(
self
,
callback
):
self
.
_connections_callback
=
callback
signal_ids
=
list
()
event_callback
=
self
.
_handle_connections_callback
for
event
in
self
.
CONNECTION_EVENTS
:
signal_id
=
self
.
_api
.
socket_listener
.
connect
(
event
,
event_callback
)
signal_ids
.
append
(
signal_id
)
return
signal_ids
def
_handle_connections_callback
(
self
,
message
):
contact_id
=
message
[
"
data
"
][
"
contactId
"
]
if
message
[
"
name
"
]
==
"
ContactConnectedEvent
"
:
self
.
_connections_callback
(
contact_id
,
True
)
elif
message
[
"
name
"
]
==
"
ContactDisconnectedEvent
"
:
self
.
_connections_callback
(
contact_id
,
False
)
else
:
raise
Exception
(
f
"
Wrong event in callback:
{
message
[
'
name
'
]
}
"
)
def
_sort_contact_list
(
contacts
):
contacts
.
sort
(
key
=
itemgetter
(
"
lastChatActivity
"
),
reverse
=
True
)
Loading