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
04d0d413
Commit
04d0d413
authored
3 years ago
by
kamathmanu
Browse files
Options
Downloads
Patches
Plain Diff
Linted code
parent
93f8c24f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/RoomDirectoryModel.cpp
+112
-106
112 additions, 106 deletions
src/RoomDirectoryModel.cpp
src/RoomDirectoryModel.h
+55
-53
55 additions, 53 deletions
src/RoomDirectoryModel.h
src/timeline/TimelineViewManager.cpp
+2
-2
2 additions, 2 deletions
src/timeline/TimelineViewManager.cpp
with
169 additions
and
161 deletions
src/RoomDirectoryModel.cpp
+
112
−
106
View file @
04d0d413
...
...
@@ -8,164 +8,170 @@
#include
<algorithm>
RoomDirectoryModel
::
RoomDirectoryModel
(
QObject
*
parent
,
const
std
::
string
&
s
)
:
QAbstractListModel
(
parent
)
,
server_
(
s
)
,
canFetchMore_
(
true
)
:
QAbstractListModel
(
parent
)
,
server_
(
s
)
,
canFetchMore_
(
true
)
{
connect
(
this
,
&
RoomDirectoryModel
::
fetchedRoomsBatch
,
this
,
&
RoomDirectoryModel
::
displayRooms
,
Qt
::
QueuedConnection
);
connect
(
this
,
&
RoomDirectoryModel
::
fetchedRoomsBatch
,
this
,
&
RoomDirectoryModel
::
displayRooms
,
Qt
::
QueuedConnection
);
}
QHash
<
int
,
QByteArray
>
QHash
<
int
,
QByteArray
>
RoomDirectoryModel
::
roleNames
()
const
{
return
{
{
Roles
::
Name
,
"name"
},
{
Roles
::
Id
,
"roomid"
},
{
Roles
::
AvatarUrl
,
"avatarUrl"
},
{
Roles
::
Topic
,
"topic"
},
{
Roles
::
MemberCount
,
"numMembers"
},
{
Roles
::
Previewable
,
"canPreview"
},};
return
{
{
Roles
::
Name
,
"name"
},
{
Roles
::
Id
,
"roomid"
},
{
Roles
::
AvatarUrl
,
"avatarUrl"
},
{
Roles
::
Topic
,
"topic"
},
{
Roles
::
MemberCount
,
"numMembers"
},
{
Roles
::
Previewable
,
"canPreview"
},
};
}
void
RoomDirectoryModel
::
resetDisplayedData
()
{
beginResetModel
();
beginResetModel
();
prevBatch_
=
""
;
nextBatch_
=
""
;
canFetchMore_
=
true
;
prevBatch_
=
""
;
nextBatch_
=
""
;
canFetchMore_
=
true
;
beginRemoveRows
(
QModelIndex
(),
0
,
static_cast
<
int
>
(
publicRoomsData_
.
size
()));
publicRoomsData_
.
clear
();
endRemoveRows
();
beginRemoveRows
(
QModelIndex
(),
0
,
static_cast
<
int
>
(
publicRoomsData_
.
size
()));
publicRoomsData_
.
clear
();
endRemoveRows
();
endResetModel
();
endResetModel
();
}
void
RoomDirectoryModel
::
setMatrixServer
(
const
QString
&
s
)
{
server_
=
s
.
toStdString
();
server_
=
s
.
toStdString
();
nhlog
::
ui
()
->
debug
(
"Received matrix server: {}"
,
server_
);
nhlog
::
ui
()
->
debug
(
"Received matrix server: {}"
,
server_
);
resetDisplayedData
();
resetDisplayedData
();
}
void
RoomDirectoryModel
::
setSearchTerm
(
const
QString
&
f
)
{
userSearchString_
=
f
.
toStdString
();
userSearchString_
=
f
.
toStdString
();
nhlog
::
ui
()
->
debug
(
"Received user query: {}"
,
userSearchString_
);
nhlog
::
ui
()
->
debug
(
"Received user query: {}"
,
userSearchString_
);
resetDisplayedData
();
resetDisplayedData
();
}
std
::
vector
<
std
::
string
>
RoomDirectoryModel
::
getViasForRoom
(
const
std
::
vector
<
std
::
string
>
&
aliases
)
{
std
::
vector
<
std
::
string
>
vias
;
vias
.
reserve
(
aliases
.
size
());
std
::
vector
<
std
::
string
>
vias
;
std
::
transform
(
aliases
.
begin
(),
aliases
.
end
(),
std
::
back_inserter
(
vias
),
[](
const
auto
&
alias
)
{
const
auto
roomAliasDelimiter
=
":"
;
return
alias
.
substr
(
alias
.
find
(
roomAliasDelimiter
)
+
1
);
});
vias
.
reserve
(
aliases
.
size
());
return
vias
;
std
::
transform
(
aliases
.
begin
(),
aliases
.
end
(),
std
::
back_inserter
(
vias
),
[](
const
auto
&
alias
)
{
const
auto
roomAliasDelimiter
=
":"
;
return
alias
.
substr
(
alias
.
find
(
roomAliasDelimiter
)
+
1
);
});
return
vias
;
}
void
RoomDirectoryModel
::
joinRoom
(
const
int
&
index
)
{
if
(
index
>=
0
&&
static_cast
<
size_t
>
(
index
)
<
publicRoomsData_
.
size
())
{
const
auto
&
chunk
=
publicRoomsData_
[
index
];
nhlog
::
ui
()
->
debug
(
"'Joining room {}"
,
chunk
.
room_id
);
ChatPage
::
instance
()
->
joinRoomVia
(
chunk
.
room_id
,
getViasForRoom
(
chunk
.
aliases
));
}
if
(
index
>=
0
&&
static_cast
<
size_t
>
(
index
)
<
publicRoomsData_
.
size
())
{
const
auto
&
chunk
=
publicRoomsData_
[
index
];
nhlog
::
ui
()
->
debug
(
"'Joining room {}"
,
chunk
.
room_id
);
ChatPage
::
instance
()
->
joinRoomVia
(
chunk
.
room_id
,
getViasForRoom
(
chunk
.
aliases
));
}
}
QVariant
RoomDirectoryModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
hasIndex
(
index
.
row
(),
index
.
column
(),
index
.
parent
()))
{
const
auto
&
room_chunk
=
publicRoomsData_
[
index
.
row
()];
switch
(
role
)
{
case
Roles
::
Name
:
return
QString
::
fromStdString
(
room_chunk
.
name
);
case
Roles
::
Id
:
return
QString
::
fromStdString
(
room_chunk
.
room_id
);
case
Roles
::
AvatarUrl
:
return
QString
::
fromStdString
(
room_chunk
.
avatar_url
);
case
Roles
::
Topic
:
return
QString
::
fromStdString
(
room_chunk
.
topic
);
case
Roles
::
MemberCount
:
return
QVariant
::
fromValue
(
room_chunk
.
num_joined_members
);
case
Roles
::
Previewable
:
return
QVariant
::
fromValue
(
room_chunk
.
world_readable
);
if
(
hasIndex
(
index
.
row
(),
index
.
column
(),
index
.
parent
()))
{
const
auto
&
room_chunk
=
publicRoomsData_
[
index
.
row
()];
switch
(
role
)
{
case
Roles
::
Name
:
return
QString
::
fromStdString
(
room_chunk
.
name
);
case
Roles
::
Id
:
return
QString
::
fromStdString
(
room_chunk
.
room_id
);
case
Roles
::
AvatarUrl
:
return
QString
::
fromStdString
(
room_chunk
.
avatar_url
);
case
Roles
::
Topic
:
return
QString
::
fromStdString
(
room_chunk
.
topic
);
case
Roles
::
MemberCount
:
return
QVariant
::
fromValue
(
room_chunk
.
num_joined_members
);
case
Roles
::
Previewable
:
return
QVariant
::
fromValue
(
room_chunk
.
world_readable
);
}
}
}
return
{};
return
{};
}
void
RoomDirectoryModel
::
fetchMore
(
const
QModelIndex
&
)
RoomDirectoryModel
::
fetchMore
(
const
QModelIndex
&
)
{
nhlog
::
net
()
->
debug
(
"Fetching more rooms from mtxclient..."
);
nhlog
::
net
()
->
debug
(
"Prev batch: {} | Next batch: {}"
,
prevBatch_
,
nextBatch_
);
mtx
::
requests
::
PublicRooms
req
;
req
.
limit
=
limit_
;
req
.
since
=
prevBatch_
;
req
.
filter
.
generic_search_term
=
userSearchString_
;
// req.third_party_instance_id = third_party_instance_id;
auto
requested_server
=
server_
;
http
::
client
()
->
post_public_rooms
(
req
,
[
requested_server
,
this
,
req
]
(
const
mtx
::
responses
::
PublicRooms
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
nhlog
::
net
()
->
error
(
"Failed to retrieve rooms from mtxclient - {} - {} - {}"
,
mtx
::
errors
::
to_string
(
err
->
matrix_error
.
errcode
),
err
->
matrix_error
.
error
,
err
->
parse_error
);
}
else
if
(
req
.
filter
.
generic_search_term
==
this
->
userSearchString_
&&
req
.
since
==
this
->
prevBatch_
&&
requested_server
==
this
->
server_
)
{
nhlog
::
net
()
->
debug
(
"signalling chunk to GUI thread"
);
emit
fetchedRoomsBatch
(
res
.
chunk
,
res
.
prev_batch
,
res
.
next_batch
);
}
},
requested_server
);
nhlog
::
net
()
->
debug
(
"Fetching more rooms from mtxclient..."
);
nhlog
::
net
()
->
debug
(
"Prev batch: {} | Next batch: {}"
,
prevBatch_
,
nextBatch_
);
mtx
::
requests
::
PublicRooms
req
;
req
.
limit
=
limit_
;
req
.
since
=
prevBatch_
;
req
.
filter
.
generic_search_term
=
userSearchString_
;
// req.third_party_instance_id = third_party_instance_id;
auto
requested_server
=
server_
;
http
::
client
()
->
post_public_rooms
(
req
,
[
requested_server
,
this
,
req
](
const
mtx
::
responses
::
PublicRooms
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
nhlog
::
net
()
->
error
(
"Failed to retrieve rooms from mtxclient - {} - {} - {}"
,
mtx
::
errors
::
to_string
(
err
->
matrix_error
.
errcode
),
err
->
matrix_error
.
error
,
err
->
parse_error
);
}
else
if
(
req
.
filter
.
generic_search_term
==
this
->
userSearchString_
&&
req
.
since
==
this
->
prevBatch_
&&
requested_server
==
this
->
server_
)
{
nhlog
::
net
()
->
debug
(
"signalling chunk to GUI thread"
);
emit
fetchedRoomsBatch
(
res
.
chunk
,
res
.
prev_batch
,
res
.
next_batch
);
}
}
,
requested_server
);
}
void
RoomDirectoryModel
::
displayRooms
(
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
fetched_rooms
,
const
std
::
string
&
prev_batch
,
const
std
::
string
&
next_batch
)
const
std
::
string
&
prev_batch
,
const
std
::
string
&
next_batch
)
{
nhlog
::
net
()
->
debug
(
"Prev batch: {} | Next batch: {}"
,
prevBatch_
,
nextBatch_
);
nhlog
::
net
()
->
debug
(
"NP batch: {} | NN batch: {}"
,
prev_batch
,
next_batch
);
if
(
fetched_rooms
.
empty
())
{
nhlog
::
net
()
->
error
(
"mtxclient helper thread yielded empty chunk!"
);
return
;
}
beginInsertRows
(
QModelIndex
(),
static_cast
<
int
>
(
publicRoomsData_
.
size
()),
static_cast
<
int
>
(
publicRoomsData_
.
size
()
+
fetched_rooms
.
size
())
-
1
);
this
->
publicRoomsData_
.
insert
(
this
->
publicRoomsData_
.
end
(),
fetched_rooms
.
begin
(),
fetched_rooms
.
end
());
endInsertRows
();
if
(
next_batch
.
empty
())
{
canFetchMore_
=
false
;
}
prevBatch_
=
std
::
exchange
(
nextBatch_
,
next_batch
);
nhlog
::
net
()
->
debug
(
"Prev batch: {} | Next batch: {}"
,
prevBatch_
,
nextBatch_
);
nhlog
::
net
()
->
debug
(
"NP batch: {} | NN batch: {}"
,
prev_batch
,
next_batch
);
if
(
fetched_rooms
.
empty
())
{
nhlog
::
net
()
->
error
(
"mtxclient helper thread yielded empty chunk!"
);
return
;
}
beginInsertRows
(
QModelIndex
(),
static_cast
<
int
>
(
publicRoomsData_
.
size
()),
static_cast
<
int
>
(
publicRoomsData_
.
size
()
+
fetched_rooms
.
size
())
-
1
);
this
->
publicRoomsData_
.
insert
(
this
->
publicRoomsData_
.
end
(),
fetched_rooms
.
begin
(),
fetched_rooms
.
end
());
endInsertRows
();
if
(
next_batch
.
empty
())
{
canFetchMore_
=
false
;
}
prevBatch_
=
std
::
exchange
(
nextBatch_
,
next_batch
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/RoomDirectoryModel.h
+
55
−
53
View file @
04d0d413
...
...
@@ -7,12 +7,12 @@
#include
<QAbstractListModel>
#include
<QHash>
#include
<QString>
#include
<vector>
#include
<string>
#include
<vector>
#include
"MatrixClient.h"
#include
<mtxclient/http/errors.hpp>
#include
<mtx/responses/public_rooms.hpp>
#include
<mtxclient/http/errors.hpp>
#include
"Logging.h"
...
...
@@ -25,61 +25,63 @@ struct PublicRooms;
class
RoomDirectoryModel
:
public
QAbstractListModel
{
Q_OBJECT
public:
explicit
RoomDirectoryModel
(
QObject
*
parent
=
nullptr
,
const
std
::
string
&
s
=
""
);
enum
Roles
{
Name
=
Qt
::
UserRole
,
Id
,
AvatarUrl
,
Topic
,
MemberCount
,
Previewable
};
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
inline
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
{
(
void
)
parent
;
return
static_cast
<
int
>
(
publicRoomsData_
.
size
());
}
inline
bool
canFetchMore
(
const
QModelIndex
&
)
const
override
{
nhlog
::
net
()
->
debug
(
"determining if can fetch more"
);
return
canFetchMore_
;
}
void
fetchMore
(
const
QModelIndex
&
)
override
;
Q_INVOKABLE
void
joinRoom
(
const
int
&
index
=
-
1
);
Q_OBJECT
public:
explicit
RoomDirectoryModel
(
QObject
*
parent
=
nullptr
,
const
std
::
string
&
s
=
""
);
enum
Roles
{
Name
=
Qt
::
UserRole
,
Id
,
AvatarUrl
,
Topic
,
MemberCount
,
Previewable
};
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
inline
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
{
(
void
)
parent
;
return
static_cast
<
int
>
(
publicRoomsData_
.
size
());
}
inline
bool
canFetchMore
(
const
QModelIndex
&
)
const
override
{
nhlog
::
net
()
->
debug
(
"determining if can fetch more"
);
return
canFetchMore_
;
}
void
fetchMore
(
const
QModelIndex
&
)
override
;
Q_INVOKABLE
void
joinRoom
(
const
int
&
index
=
-
1
);
signals
:
void
fetchedRoomsBatch
(
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
rooms
,
const
std
::
string
&
prev_batch
,
const
std
::
string
&
next_batch
);
void
serverChanged
();
void
searchTermEntered
();
void
fetchedRoomsBatch
(
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
rooms
,
const
std
::
string
&
prev_batch
,
const
std
::
string
&
next_batch
);
void
serverChanged
();
void
searchTermEntered
();
public
slots
:
void
displayRooms
(
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
rooms
,
const
std
::
string
&
prev
,
const
std
::
string
&
next
);
void
setMatrixServer
(
const
QString
&
s
=
""
);
void
setSearchTerm
(
const
QString
&
f
);
void
displayRooms
(
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
rooms
,
const
std
::
string
&
prev
,
const
std
::
string
&
next
);
void
setMatrixServer
(
const
QString
&
s
=
""
);
void
setSearchTerm
(
const
QString
&
f
);
private
:
static
constexpr
size_t
limit_
=
50
;
std
::
string
server_
;
std
::
string
userSearchString_
;
std
::
string
prevBatch_
;
std
::
string
nextBatch_
;
bool
canFetchMore_
;
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
publicRoomsData_
;
std
::
vector
<
std
::
string
>
getViasForRoom
(
const
std
::
vector
<
std
::
string
>
&
room
);
void
resetDisplayedData
();
static
constexpr
size_t
limit_
=
50
;
std
::
string
server_
;
std
::
string
userSearchString_
;
std
::
string
prevBatch_
;
std
::
string
nextBatch_
;
bool
canFetchMore_
;
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>
publicRoomsData_
;
std
::
vector
<
std
::
string
>
getViasForRoom
(
const
std
::
vector
<
std
::
string
>
&
room
);
void
resetDisplayedData
();
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/timeline/TimelineViewManager.cpp
+
2
−
2
View file @
04d0d413
...
...
@@ -153,7 +153,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
qRegisterMetaType
<
mtx
::
events
::
msg
::
KeyVerificationStart
>
();
qRegisterMetaType
<
CombinedImagePackModel
*>
();
qRegisterMetaType
<
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>>
();
qRegisterMetaType
<
std
::
vector
<
mtx
::
responses
::
PublicRoomsChunk
>>
();
qmlRegisterUncreatableMetaObject
(
qml_mtx_events
::
staticMetaObject
,
"im.nheko"
,
...
...
@@ -278,7 +278,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"EmojiCategory"
,
"Error: Only enums"
);
qmlRegisterType
<
RoomDirectoryModel
>
(
qmlRegisterType
<
RoomDirectoryModel
>
(
"im.nheko.RoomDirectoryModel"
,
1
,
0
,
"RoomDirectoryModel"
);
#ifdef USE_QUICK_VIEW
...
...
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