Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
ff518123
Commit
ff518123
authored
Aug 30, 2022
by
Tijmen de Mes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added function to save history message in storage
parent
5f8798e4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
history.py
blink/history.py
+58
-0
No files found.
blink/history.py
View file @
ff518123
...
...
@@ -59,6 +59,7 @@ class HistoryManager(object, metaclass=Singleton):
notification_center
.
add_observer
(
self
,
name
=
'BlinkMessageDidDecrypt'
)
notification_center
.
add_observer
(
self
,
name
=
'BlinkGotDispositionNotification'
)
notification_center
.
add_observer
(
self
,
name
=
'BlinkDidSendDispositionNotification'
)
notification_center
.
add_observer
(
self
,
name
=
'BlinkGotHistoryMessage'
)
@
run_in_thread
(
'file-io'
)
def
save
(
self
):
...
...
@@ -151,6 +152,10 @@ class HistoryManager(object, metaclass=Singleton):
self
.
message_history
.
add_with_session
(
session
,
data
.
message
,
'outgoing'
)
def
_NH_BlinkGotHistoryMessage
(
self
,
notification
):
account
=
notification
.
sender
self
.
message_history
.
add_from_history
(
account
,
**
notification
.
data
.
__dict__
)
def
_NH_BlinkMessageDidSucceed
(
self
,
notification
):
data
=
notification
.
data
self
.
message_history
.
update
(
data
.
id
,
'accepted'
)
...
...
@@ -299,6 +304,59 @@ class MessageHistory(object, metaclass=Singleton):
else
:
self
.
table_versions
.
set_version
(
Message
.
sqlmeta
.
table
,
self
.
__version__
)
@
classmethod
@
run_in_thread
(
'db'
)
def
add_from_history
(
cls
,
account
,
remote_uri
,
message
,
state
=
None
,
encryption
=
None
):
if
message
.
content
.
startswith
(
'?OTRv'
):
return
print
(
f
"-- Adding {message.direction} history message to storage: {message.id} {state} {remote_uri}"
)
match
=
cls
.
phone_number_re
.
match
(
remote_uri
)
if
match
:
remote_uri
=
match
.
group
(
'number'
)
if
message
.
direction
==
'outgoing'
:
display_name
=
message
.
sender
.
display_name
else
:
try
:
contact
=
next
(
contact
for
contact
in
AddressbookManager
()
.
get_contacts
()
if
remote_uri
in
(
addr
.
uri
for
addr
in
contact
.
uris
))
except
StopIteration
:
display_name
=
''
else
:
display_name
=
contact
.
name
timestamp_native
=
message
.
timestamp
timestamp_utc
=
timestamp_native
.
replace
(
tzinfo
=
timezone
.
utc
)
message
.
timestamp
=
timestamp_utc
-
message
.
timestamp
.
utcoffset
()
timestamp
=
parse
(
str
(
message
.
timestamp
))
optional_fields
=
{}
if
state
is
not
None
:
optional_fields
[
'state'
]
=
state
if
encryption
is
not
None
:
optional_fields
[
'encryption_type'
]
=
str
([
f
'{encryption}'
])
uri
=
str
(
message
.
sender
.
uri
)
if
not
uri
.
startswith
((
'sip:'
,
'sips:'
)):
uri
=
f
'sip:{uri}'
try
:
Message
(
remote_uri
=
remote_uri
,
display_name
=
display_name
,
uri
=
uri
,
content
=
message
.
content
,
content_type
=
message
.
content_type
,
message_id
=
message
.
id
,
account_id
=
str
(
account
.
id
),
direction
=
message
.
direction
,
timestamp
=
timestamp
,
disposition
=
str
(
message
.
disposition
),
**
optional_fields
)
except
dberrors
.
DuplicateEntryError
:
pass
@
classmethod
@
run_in_thread
(
'db'
)
def
add_with_session
(
cls
,
session
,
message
,
direction
,
state
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment