Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chat
RocketChatMobileEngine
Commits
bd69e2a2
Commit
bd69e2a2
authored
Feb 09, 2019
by
Armin Felder
Browse files
fixed channel sorting
parent
52e8b616
Changes
4
Hide whitespace changes
Inline
Side-by-side
CustomModels/channelmodel.cpp
View file @
bd69e2a2
...
...
@@ -143,10 +143,12 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const
bool
ChannelModel
::
addChannel
(
const
QSharedPointer
<
RocketChatChannel
>
&
channel
)
{
if
(
!
channel
.
isNull
()
&&
channel
->
getRoomId
()
!=
""
&&
!
duplicateCheck
.
contains
(
channel
->
getRoomId
()
)
)
{
connect
(
channel
.
data
(),
&
RocketChatChannel
::
messageAdded
,
this
,
&
ChannelModel
::
onNewerMessage
,
Qt
::
UniqueConnection
);
//
connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect
(
channel
.
data
(),
&
RocketChatChannel
::
unreadMessagesChanged
,
this
,
&
ChannelModel
::
onUnreadMessageChanged
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
dataChanged
,
this
,
&
ChannelModel
::
onDataChanged
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
channelDeleted
,
this
,
&
ChannelModel
::
onDeleted
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
updatedChanged
,
this
,
&
ChannelModel
::
onChannelOrderChanged
);
duplicateCheck
.
insert
(
channel
->
getRoomId
()
);
int
pos
=
channelList
.
findPosition
(
channel
);
if
(
pos
<
0
){
...
...
@@ -168,10 +170,11 @@ bool ChannelModel::addChannelsSlot(const QVector<QSharedPointer<RocketChatChanne
beginResetModel
();
for
(
const
auto
&
channel
:
pChannels
){
if
(
!
channel
.
isNull
()
&&
channel
->
getRoomId
()
!=
""
&&
!
duplicateCheck
.
contains
(
channel
->
getRoomId
()
)
)
{
connect
(
channel
.
data
(),
&
RocketChatChannel
::
messageAdded
,
this
,
&
ChannelModel
::
onNewerMessage
,
Qt
::
UniqueConnection
);
//
connect( channel.data(), &RocketChatChannel::messageAdded, this, &ChannelModel::onNewerMessage, Qt::UniqueConnection );
connect
(
channel
.
data
(),
&
RocketChatChannel
::
unreadMessagesChanged
,
this
,
&
ChannelModel
::
onUnreadMessageChanged
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
dataChanged
,
this
,
&
ChannelModel
::
onDataChanged
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
channelDeleted
,
this
,
&
ChannelModel
::
onDeleted
,
Qt
::
UniqueConnection
);
connect
(
channel
.
data
(),
&
RocketChatChannel
::
updatedChanged
,
this
,
&
ChannelModel
::
onChannelOrderChanged
);
duplicateCheck
.
insert
(
channel
->
getRoomId
()
);
channelList
.
insertSort
(
channel
);
}
...
...
@@ -220,7 +223,7 @@ void ChannelModel::onNewerMessage( const QString &id, qint64 timestamp )
//emit dataChanged(index(pos),index(pos),{lastMessageText});
}
sortChanged
();
//
sortChanged();
}
void
ChannelModel
::
onUnreadMessageChanged
(
const
QString
&
id
,
int
number
)
...
...
@@ -291,6 +294,13 @@ void ChannelModel::onDeleted( const QString &pId, bool deleted )
}
void
ChannelModel
::
onChannelOrderChanged
(
const
QString
&
pId
,
qint64
pTimestamp
)
{
beginResetModel
();
channelList
.
reOrder
();
endResetModel
();
}
void
ChannelModel
::
addChannelSlot
(
const
QSharedPointer
<
RocketChatChannel
>
&
channel
)
{
addChannel
(
channel
);
...
...
container/sortedvector.cpp
View file @
bd69e2a2
...
...
@@ -20,7 +20,7 @@
#include "sortedvector.h"
#include <execution>
template
<
typename
T
>
...
...
@@ -32,33 +32,13 @@ int SortedVector<T>::insertSort( const QSharedPointer<T> &pointer )
this
->
append
(
pointer
);
row
=
0
;
}
else
{
bool
lastElementGreaterThanNew
=
*
(
*
this
)[
this
->
count
()
-
1
]
>
*
pointer
;
if
(
lastElementGreaterThanNew
)
{
for
(
int
i
=
0
;
i
<
this
->
count
();
i
++
)
{
if
(
*
(
*
this
)[
i
]
>
*
pointer
)
{
this
->
insert
(
i
,
pointer
);
row
=
i
;
break
;
}
}
}
else
{
for
(
int
i
=
this
->
count
()
-
1
;
i
;
i
--
)
{
if
(
*
(
*
this
)[
i
]
<
*
pointer
)
{
this
->
insert
(
i
,
pointer
);
row
=
i
;
break
;
}
}
}
if
(
row
==
-
1
)
{
row
=
this
->
count
();
this
->
append
(
pointer
);
}
}
auto
elementSmallerThanNew
=
std
::
lower_bound
(
this
->
begin
(),
this
->
end
(),
pointer
,[](
const
auto
&
first
,
const
auto
&
second
)
->
bool
{
return
(
*
first
)
>
(
*
second
);
});
insert
(
elementSmallerThanNew
,
pointer
);
row
=
elementSmallerThanNew
-
begin
();
}
return
row
;
}
...
...
@@ -66,17 +46,11 @@ template<typename T>
int
SortedVector
<
T
>::
findInsertPosition
(
const
QSharedPointer
<
T
>
&
pointer
)
const
{
int
row
=
-
1
;
auto
elementSmallerThanNew
=
std
::
lower_bound
(
this
->
begin
(),
this
->
end
(),
pointer
,[](
const
auto
&
first
,
const
auto
&
second
)
->
bool
{
return
(
*
first
)
>
(
*
second
);
});
for
(
int
i
=
0
;
i
<
this
->
count
();
i
++
)
{
if
(
*
(
*
this
)[
i
]
>
*
pointer
)
{
row
=
i
;
break
;
}
}
if
(
row
==
-
1
)
{
row
=
this
->
count
();
}
row
=
elementSmallerThanNew
-
begin
();
return
row
;
}
...
...
@@ -86,19 +60,15 @@ int SortedVector<T>::findPosition( const QSharedPointer<T> &pointer ) const
{
int
row
=
-
1
;
for
(
int
i
=
0
;
i
<
this
->
count
();
i
++
)
{
if
(
(
*
this
)[
i
]
==
pointer
)
{
row
=
i
;
break
;
}
}
return
row
;
auto
pos
=
find
(
begin
(),
end
(),
pointer
);
return
pos
-
begin
();
}
template
<
typename
T
>
void
SortedVector
<
T
>::
reOrder
()
{
std
::
sort
(
this
->
begin
(),
this
->
end
());
std
::
sort
(
std
::
execution
::
par
,
this
->
begin
(),
this
->
end
(),[
=
](
const
auto
&
first
,
const
auto
&
second
)
->
bool
{
return
(
*
first
)
>
(
*
second
);
});
}
container/sortedvector.h
View file @
bd69e2a2
...
...
@@ -24,6 +24,7 @@
#include <QVector>
#include <QSharedPointer>
#include <QMutex>
template
<
typename
T
>
class
SortedVector
:
public
QVector
<
QSharedPointer
<
T
>>
{
public:
...
...
@@ -37,6 +38,8 @@ template<typename T> class SortedVector : public QVector<QSharedPointer<T>>
this
->
append
(
o
);
return
true
;
}
private:
mutable
QMutex
mSortMutex
;
};
#include "sortedvector.cpp"
#endif // SORTEDVECTOR_H
repos/entities/rocketchatchannel.cpp
View file @
bd69e2a2
...
...
@@ -168,7 +168,7 @@ QList<QSharedPointer<RocketChatMessage>> RocketChatChannel::addMessages( const Q
}
}
if
(
newMessages
.
count
()){
emit
messageAdded
(
getRoomId
(),
0
);
//
emit messageAdded( getRoomId(), 0 );
}
return
newMessages
;
}
...
...
@@ -192,8 +192,10 @@ unsigned int RocketChatChannel::getUnreadMessages() const
void
RocketChatChannel
::
setUnreadMessages
(
unsigned
int
value
)
{
qDebug
()
<<
"set unread to: "
<<
value
;
mUnreadMessages
=
value
;
emit
unreadMessagesChanged
(
mRoomId
,
value
);
if
(
mUnreadMessages
!=
value
){
mUnreadMessages
=
value
;
emit
unreadMessagesChanged
(
mRoomId
,
value
);
}
}
const
QString
&
RocketChatChannel
::
getType
()
const
...
...
@@ -262,12 +264,12 @@ void RocketChatChannel::setSelfMuted( bool value )
int
RocketChatChannel
::
operator
>
(
const
RocketChatChannel
&
channel
)
const
{
return
channel
.
getUpdatedAt
()
>
channel
.
getUpdatedAt
();
return
getUpdatedAt
()
>
channel
.
getUpdatedAt
();
}
int
RocketChatChannel
::
operator
<
(
const
RocketChatChannel
&
channel
)
const
{
return
channel
.
getUpdatedAt
()
<
channel
.
getUpdatedAt
();
return
getUpdatedAt
()
<
channel
.
getUpdatedAt
();
}
bool
RocketChatChannel
::
getDeleted
()
const
...
...
@@ -327,10 +329,12 @@ const QSharedPointer<RocketChatUser> &RocketChatChannel::getChatPartner() const
void
RocketChatChannel
::
setChatPartner
(
const
QSharedPointer
<
RocketChatUser
>
&
chatPartner
)
{
mChatPartner
=
chatPartner
;
connect
(
chatPartner
.
data
(),
&
RocketChatUser
::
statusChanged
,
this
,
[
=
]()
{
emit
dataChanged
(
mRoomId
,
"userStatus"
);
}
);
if
(
mChatPartner
!=
chatPartner
){
mChatPartner
=
chatPartner
;
connect
(
chatPartner
.
data
(),
&
RocketChatUser
::
statusChanged
,
this
,
[
=
]()
{
emit
dataChanged
(
mRoomId
,
"userStatus"
);
}
);
}
}
const
QString
&
RocketChatChannel
::
getChatPartnerId
()
const
...
...
@@ -367,8 +371,10 @@ qint64 RocketChatChannel::getUpdatedAt() const
void
RocketChatChannel
::
setUpdatedAt
(
const
qint64
&
updatedAt
)
{
if
(
mUpdatedAt
!=
updatedAt
){
if
(
mUpdatedAt
!=
-
1
){
emit
updatedChanged
(
mRoomId
,
mUpdatedAt
);
}
mUpdatedAt
=
updatedAt
;
emit
updatedChanged
(
mRoomId
,
mUpdatedAt
);
}
}
...
...
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