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
4e703358
Commit
4e703358
authored
Jul 03, 2021
by
Adrian Georgescu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed encoding inline images in chat window
parent
f14f3cf6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
7 deletions
+11
-7
chatwindow.py
blink/chatwindow.py
+11
-7
No files found.
blink/chatwindow.py
View file @
4e703358
import
base64
import
locale
import
os
import
re
...
...
@@ -557,7 +558,7 @@ class Thumbnail(object):
if
image_reader
.
canRead
()
and
image_reader
.
size
()
.
isValid
():
if
image_reader
.
supportsAnimation
()
and
image_reader
.
imageCount
()
>
1
:
image_format
=
str
(
image_reader
.
format
())
image_data
=
str
(
image_reader
.
device
()
.
readAll
()
)
image_data
=
image_reader
.
device
()
.
read
(
)
else
:
file_format
=
str
(
image_reader
.
format
())
file_size
=
image_reader
.
device
()
.
size
()
...
...
@@ -568,7 +569,7 @@ class Thumbnail(object):
image_buffer
=
QBuffer
()
image_format
=
'png'
if
image
.
hasAlphaChannel
()
or
(
file_format
in
{
'png'
,
'tiff'
,
'ico'
}
and
file_size
<=
100
*
1024
)
else
'jpeg'
image
.
save
(
image_buffer
,
image_format
)
image_data
=
str
(
image_buffer
.
data
()
)
image_data
=
image_buffer
.
data
(
)
instance
=
super
(
Thumbnail
,
cls
)
.
__new__
(
cls
)
instance
.
__dict__
[
'data'
]
=
image_data
instance
.
__dict__
[
'type'
]
=
'image/{}'
.
format
(
image_format
)
...
...
@@ -751,11 +752,12 @@ class ChatWidget(base_class, ui_class):
for
image
in
image_descriptors
:
try
:
self
.
send_message
(
image
.
thumbnail
.
data
,
content_type
=
image
.
thumbnail
.
type
)
image_data
=
base64
.
b64encode
(
image
.
thumbnail
.
data
)
.
decode
()
self
.
send_message
(
image_data
,
content_type
=
image
.
thumbnail
.
type
)
except
Exception
as
e
:
self
.
add_message
(
ChatStatus
(
"Error sending image '
%
s':
%
s"
%
(
os
.
path
.
basename
(
image
.
filename
),
e
)))
# decide what type to use here. -Dan
self
.
add_message
(
ChatStatus
(
"Error sending image '
%
s':
%
s"
%
(
os
.
path
.
basename
(
image
.
filename
),
str
(
e
)
)))
# decide what type to use here. -Dan
else
:
content
=
'''<a href="{}"><img src="data:{};base64,{}" class="scaled-to-fit" /></a>'''
.
format
(
image
.
fileurl
,
image
.
thumbnail
.
type
,
image
.
thumbnail
.
data
.
encode
(
'base64'
)
.
rstrip
()
)
content
=
'''<a href="{}"><img src="data:{};base64,{}" class="scaled-to-fit" /></a>'''
.
format
(
image
.
fileurl
,
image
.
thumbnail
.
type
,
image
_data
)
sender
=
ChatSender
(
blink_session
.
account
.
display_name
,
blink_session
.
account
.
id
,
self
.
user_icon
.
filename
)
self
.
add_message
(
ChatMessage
(
content
,
sender
,
'outgoing'
))
...
...
@@ -766,9 +768,11 @@ class ChatWidget(base_class, ui_class):
match
=
self
.
image_data_re
.
match
(
text
)
if
match
is
not
None
:
try
:
self
.
send_message
(
match
.
group
(
'data'
)
.
decode
(
'base64'
),
content_type
=
match
.
group
(
'type'
))
data
=
match
.
group
(
'data'
)
if
isinstance
(
match
.
group
(
'data'
),
bytes
)
else
match
.
group
(
'data'
)
.
encode
()
image_data
=
base64
.
b64encode
(
data
)
.
decode
()
self
.
send_message
(
image_data
,
content_type
=
match
.
group
(
'type'
))
except
Exception
as
e
:
self
.
add_message
(
ChatStatus
(
'Error sending image:
%
s'
%
e
))
# decide what type to use here. -Dan
self
.
add_message
(
ChatStatus
(
'Error sending image:
%
s'
%
str
(
e
)))
else
:
account
=
self
.
session
.
blink_session
.
account
content
=
'''<img src="{}" class="scaled-to-fit" />'''
.
format
(
text
)
...
...
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