Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Nheko Reborn
nheko
Commits
7fab9a1d
Verified
Commit
7fab9a1d
authored
1 year ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Prevent new packs from overwriting the default pack by accident
parent
4bf72537
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
src/ImagePackListModel.cpp
+3
-1
3 additions, 1 deletion
src/ImagePackListModel.cpp
src/SingleImagePackModel.cpp
+42
-0
42 additions, 0 deletions
src/SingleImagePackModel.cpp
src/SingleImagePackModel.h
+2
-0
2 additions, 0 deletions
src/SingleImagePackModel.h
with
47 additions
and
1 deletion
src/ImagePackListModel.cpp
+
3
−
1
View file @
7fab9a1d
...
...
@@ -82,8 +82,10 @@ SingleImagePackModel *
ImagePackListModel
::
newPack
(
bool
inRoom
)
{
ImagePackInfo
info
{};
if
(
inRoom
)
if
(
inRoom
)
{
info
.
source_room
=
room_id
;
info
.
state_key
=
SingleImagePackModel
::
unconflictingStatekey
(
room_id
,
""
);
}
return
new
SingleImagePackModel
(
info
);
}
...
...
This diff is collapsed.
Click to expand it.
src/SingleImagePackModel.cpp
+
42
−
0
View file @
7fab9a1d
...
...
@@ -8,6 +8,8 @@
#include
<QFileInfo>
#include
<QMimeDatabase>
#include
<unordered_set>
#include
<mtx/responses/media.hpp>
#include
"Cache_p.h"
...
...
@@ -237,6 +239,12 @@ SingleImagePackModel::setStatekey(QString val)
auto
val_
=
val
.
toStdString
();
if
(
val_
!=
statekey_
)
{
statekey_
=
val_
;
// prevent deleting current pack
if
(
!
roomid_
.
empty
()
&&
statekey_
!=
old_statekey_
)
{
statekey_
=
unconflictingStatekey
(
roomid_
,
statekey_
);
}
emit
statekeyChanged
();
}
}
...
...
@@ -290,6 +298,7 @@ SingleImagePackModel::save()
tr
(
"Failed to delete old image pack: %1"
)
.
arg
(
QString
::
fromStdString
(
e
->
matrix_error
.
error
)));
});
old_statekey_
=
statekey_
;
}
http
::
client
()
->
send_state_event
(
...
...
@@ -398,6 +407,7 @@ std::string
SingleImagePackModel
::
unconflictingShortcode
(
const
std
::
string
&
shortcode
)
{
if
(
pack
.
images
.
count
(
shortcode
))
{
// more images won't fit in an event anyway
for
(
int
i
=
0
;
i
<
64'000
;
i
++
)
{
auto
tempCode
=
shortcode
+
std
::
to_string
(
i
);
if
(
!
pack
.
images
.
count
(
tempCode
))
{
...
...
@@ -408,6 +418,38 @@ SingleImagePackModel::unconflictingShortcode(const std::string &shortcode)
return
shortcode
;
}
std
::
string
SingleImagePackModel
::
unconflictingStatekey
(
const
std
::
string
&
roomid
,
const
std
::
string
&
key
)
{
if
(
roomid
.
empty
())
return
key
;
std
::
unordered_set
<
std
::
string
>
statekeys
;
auto
currentPacks
=
cache
::
client
()
->
getStateEventsWithType
<
mtx
::
events
::
msc2545
::
ImagePack
>
(
roomid
);
for
(
const
auto
&
pack
:
currentPacks
)
{
if
(
!
pack
.
content
.
images
.
empty
())
statekeys
.
insert
(
pack
.
state_key
);
}
auto
defaultPack
=
cache
::
client
()
->
getStateEvent
<
mtx
::
events
::
msc2545
::
ImagePack
>
(
roomid
);
if
(
defaultPack
&&
defaultPack
->
content
.
images
.
size
())
{
statekeys
.
insert
(
defaultPack
->
state_key
);
}
if
(
statekeys
.
count
(
key
))
{
// arbitrary count. More than 64k image packs in a room are unlikely and if you have that,
// you probably know what you are doing :)
for
(
int
i
=
0
;
i
<
64'000
;
i
++
)
{
auto
tempCode
=
key
+
std
::
to_string
(
i
);
if
(
!
statekeys
.
count
(
tempCode
))
{
return
tempCode
;
}
}
}
return
key
;
}
void
SingleImagePackModel
::
addImageCb
(
std
::
string
uri
,
std
::
string
filename
,
mtx
::
common
::
ImageInfo
info
)
{
...
...
This diff is collapsed.
Click to expand it.
src/SingleImagePackModel.h
+
2
−
0
View file @
7fab9a1d
...
...
@@ -71,6 +71,8 @@ public:
Q_INVOKABLE
void
remove
(
int
index
);
Q_INVOKABLE
void
setAvatar
(
QUrl
file
);
static
std
::
string
unconflictingStatekey
(
const
std
::
string
&
roomid
,
const
std
::
string
&
key
);
signals
:
void
globallyEnabledChanged
();
void
statekeyChanged
();
...
...
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