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
1afdc7cc
Commit
1afdc7cc
authored
May 31, 2022
by
Tijmen de Mes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Altered message storage to prevent duplicate messages
parent
0e160ed3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
15 deletions
+35
-15
history.py
blink/history.py
+35
-15
No files found.
blink/history.py
View file @
1afdc7cc
...
@@ -184,7 +184,7 @@ class Message(SQLObject):
...
@@ -184,7 +184,7 @@ class Message(SQLObject):
disposition
=
StringCol
(
default
=
''
)
disposition
=
StringCol
(
default
=
''
)
remote_idx
=
DatabaseIndex
(
'remote_uri'
)
remote_idx
=
DatabaseIndex
(
'remote_uri'
)
id_idx
=
DatabaseIndex
(
'message_id'
)
id_idx
=
DatabaseIndex
(
'message_id'
)
unq_idx
=
DatabaseIndex
(
message_id
,
account_id
,
remote_uri
,
unique
=
True
)
class
TableVersions
(
object
,
metaclass
=
Singleton
):
class
TableVersions
(
object
,
metaclass
=
Singleton
):
__version__
=
1
__version__
=
1
...
@@ -238,7 +238,7 @@ class TableVersions(object, metaclass=Singleton):
...
@@ -238,7 +238,7 @@ class TableVersions(object, metaclass=Singleton):
class
MessageHistory
(
object
,
metaclass
=
Singleton
):
class
MessageHistory
(
object
,
metaclass
=
Singleton
):
__version__
=
1
__version__
=
2
phone_number_re
=
re
.
compile
(
r'^(?P<number>(0|00|\+)[1-9]\d{7,14})@'
)
phone_number_re
=
re
.
compile
(
r'^(?P<number>(0|00|\+)[1-9]\d{7,14})@'
)
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -264,7 +264,25 @@ class MessageHistory(object, metaclass=Singleton):
...
@@ -264,7 +264,25 @@ class MessageHistory(object, metaclass=Singleton):
def
_check_table_version
(
self
):
def
_check_table_version
(
self
):
db_table_version
=
self
.
table_versions
.
version
(
Message
.
sqlmeta
.
table
)
db_table_version
=
self
.
table_versions
.
version
(
Message
.
sqlmeta
.
table
)
if
self
.
__version__
!=
db_table_version
:
if
self
.
__version__
!=
db_table_version
:
if
db_table_version
==
1
:
query
=
f
'CREATE UNIQUE INDEX messages_msg_id ON {Message.sqlmeta.table} (message_id, account_id, remote_uri)'
try
:
self
.
db
.
queryAll
(
query
)
except
(
dberrors
.
IntegrityError
,
dberrors
.
DuplicateEntryError
):
fix_query
=
f
'select message_id from {Message.sqlmeta.table} group by message_id having count(id) > 1'
result
=
self
.
db
.
queryAll
(
fix_query
)
for
row
in
result
:
messages
=
Message
.
selectBy
(
message_id
=
row
[
0
])
for
message
in
list
(
messages
)[
1
:]:
message
.
destroySelf
()
try
:
self
.
db
.
queryAll
(
query
)
except
(
dberrors
.
IntegrityError
,
dberrors
.
DuplicateEntryError
):
pass
pass
else
:
self
.
table_versions
.
set_version
(
Message
.
sqlmeta
.
table
,
self
.
__version__
)
else
:
self
.
table_versions
.
set_version
(
Message
.
sqlmeta
.
table
,
self
.
__version__
)
@
classmethod
@
classmethod
@
run_in_thread
(
'db'
)
@
run_in_thread
(
'db'
)
...
@@ -308,8 +326,8 @@ class MessageHistory(object, metaclass=Singleton):
...
@@ -308,8 +326,8 @@ class MessageHistory(object, metaclass=Singleton):
optional_fields
[
'encryption_type'
]
=
str
([
'{0.encryption} ({0.encryption_cipher}'
.
format
(
chat_info
)])
optional_fields
[
'encryption_type'
]
=
str
([
'{0.encryption} ({0.encryption_cipher}'
.
format
(
chat_info
)])
elif
chat_info
.
transport
==
'tls'
:
elif
chat_info
.
transport
==
'tls'
:
optional_fields
[
'encryption_type'
]
=
str
([
'TLS'
])
optional_fields
[
'encryption_type'
]
=
str
([
'TLS'
])
try
:
db_message
=
Message
(
remote_uri
=
remote_uri
,
Message
(
remote_uri
=
remote_uri
,
display_name
=
display_name
,
display_name
=
display_name
,
uri
=
str
(
message
.
sender
.
uri
),
uri
=
str
(
message
.
sender
.
uri
),
content
=
message
.
content
,
content
=
message
.
content
,
...
@@ -320,6 +338,8 @@ class MessageHistory(object, metaclass=Singleton):
...
@@ -320,6 +338,8 @@ class MessageHistory(object, metaclass=Singleton):
timestamp
=
timestamp
,
timestamp
=
timestamp
,
disposition
=
str
(
message
.
disposition
),
disposition
=
str
(
message
.
disposition
),
**
optional_fields
)
**
optional_fields
)
except
dberrors
.
DuplicateEntryError
:
pass
@
run_in_thread
(
'db'
)
@
run_in_thread
(
'db'
)
def
update
(
self
,
id
,
state
):
def
update
(
self
,
id
,
state
):
...
...
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