Make a cache for text to each chat rooms.

Display a draft icon in timeline if a etxt has been cached.
This commit is contained in:
Julien Wadel 2022-10-20 15:25:23 +02:00
parent 2f8f3b356e
commit 610097c5a5
9 changed files with 118 additions and 20 deletions

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="80"
height="80"
viewBox="0 0 80 80"
version="1.1"
id="svg8"
sodipodi:docname="menu_forward_custom.svg"
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs12" />
<sodipodi:namedview
id="namedview10"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="4.85"
inkscape:cx="-16.597938"
inkscape:cy="43.917526"
inkscape:window-width="1920"
inkscape:window-height="1043"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg8" />
<g
fill="none"
fill-rule="evenodd"
id="g6"
transform="matrix(0.94339623,0,0,0.90909091,15,19.609091)">
<g
fill="#444444"
fill-rule="nonzero"
id="g4">
<path
d="M 24.071,28.481 V 26.72 h 1.625 c 1.553,0 2.931,0.043 4.13,0.126 1.15,0.08 2.294,0.223 3.428,0.429 1.003,0.182 1.83,0.418 2.48,0.697 0.632,0.271 1.22,0.618 1.772,1.046 0.425,0.33 0.759,0.708 1.02,1.15 0.308,0.521 0.571,1.195 0.775,2.03 0.213,0.872 0.325,1.914 0.325,3.123 l -0.003,0.362 c -0.008,0.496 -0.033,1.038 -0.074,1.628 l -0.043,0.548 -0.018,0.125 c -0.073,0.46 -0.113,0.841 -0.113,1.229 0,1.225 0.446,2.401 1.308,3.312 0.95,0.999 2.203,1.475 3.496,1.475 1.48,0 2.772,-0.657 3.687,-1.716 l 0.04,-0.047 c 0.335,-0.388 0.616,-0.814 0.855,-1.277 l 0.245,-0.483 0.418,-0.853 C 51.77,34.91 53,30.994 53,27.76 53,24.254 52.46,21.216 51.328,18.652 l -0.15,-0.324 C 47.572,10.724 38.85,7.2 25.697,7.2 H 24.072 V 5.44 C 24.072,3.882 23.409,2.474 22.265,1.449 21.208,0.503 19.88,0 18.464,0 17.048,0 15.72,0.503 14.664,1.45 L 1.808,12.968 C 0.663,13.996 0,15.403 0,16.96 c 0,1.557 0.664,2.965 1.807,3.99 l 12.858,11.522 c 1.058,0.946 2.385,1.448 3.8,1.448 1.414,0 2.742,-0.502 3.797,-1.446 1.146,-1.027 1.81,-2.436 1.81,-3.994 z M 18.464,4 c 0.436,0 0.812,0.143 1.13,0.428 0.278,0.249 0.435,0.538 0.47,0.868 l 0.007,0.144 v 5.76 h 5.625 c 11.936,0 19.26,3.023 21.973,9.068 0.887,2.01 1.331,4.508 1.331,7.493 0,2.401 -0.989,5.632 -2.965,9.692 l -0.666,1.355 -0.16,0.314 c -0.102,0.196 -0.21,0.36 -0.327,0.496 C 44.681,39.873 44.447,40 44.179,40 c -0.251,0 -0.448,-0.075 -0.59,-0.225 -0.143,-0.15 -0.214,-0.337 -0.214,-0.562 l 0.003,-0.089 0.02,-0.223 0.087,-0.613 0.014,-0.148 0.002,-0.052 c 0.083,-1.02 0.125,-1.942 0.125,-2.767 0,-1.515 -0.147,-2.873 -0.44,-4.073 -0.292,-1.2 -0.698,-2.238 -1.217,-3.116 -0.52,-0.878 -1.189,-1.635 -2.01,-2.273 -0.82,-0.637 -1.703,-1.158 -2.649,-1.563 -0.946,-0.406 -2.06,-0.724 -3.34,-0.957 -1.28,-0.232 -2.57,-0.394 -3.867,-0.484 -1.135,-0.078 -2.402,-0.123 -3.8,-0.132 l -0.607,-0.002 h -5.625 v 5.76 c 0,0.39 -0.159,0.728 -0.477,1.013 -0.318,0.284 -0.695,0.427 -1.13,0.427 -0.38,0 -0.716,-0.11 -1.008,-0.327 L 17.334,29.494 4.477,17.973 C 4.16,17.688 4,17.351 4,16.961 4,16.619 4.122,16.318 4.365,16.057 L 4.477,15.947 17.334,4.427 C 17.652,4.143 18.029,4 18.464,4 Z"
transform="matrix(-1,0,0,1,53,0.43)"
id="path2" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -77,6 +77,7 @@
<file>assets/images/declined_outgoing_call_custom.svg</file>
<file>assets/images/delete_custom.svg</file>
<file>assets/images/download_custom.svg</file>
<file>assets/images/draft_custom.svg</file>
<file>assets/images/drop_down_custom.svg</file>
<file>assets/images/edit_custom.svg</file>
<file>assets/images/ended_call_custom.svg</file>

View file

@ -523,6 +523,14 @@ int ChatRoomModel::getAllUnreadCount(){
return mUnreadMessagesCount + mMissedCallsCount;
}
QString ChatRoomModel::getCachedText()const{
return mCachedText;
}
bool ChatRoomModel::hasDraft() const{
return mHasDraft;
}
//------------------------------------------------------------------------------------------------
void ChatRoomModel::setSubject(QString& subject){
@ -597,6 +605,23 @@ void ChatRoomModel::enableMarkAsRead(const bool& enable){
}
}
bool ChatRoomModel::setCachedText(const QString& text){
if(mCachedText != text){
mCachedText = text;
emit cachedTextChanged();
setHasDraft(!mCachedText.isEmpty());
return true;
}else
return false;
}
void ChatRoomModel::setHasDraft(const bool& cached){
if(mHasDraft != cached){
mHasDraft = cached;
emit hasDraftChanged();
}
}
void ChatRoomModel::setReply(ChatMessageModel * model){
if(model != mReplyModel.get()){
if( model && model->getChatMessage() )
@ -699,6 +724,7 @@ void ChatRoomModel::sendMessage (const QString &message) {
if(recorder->haveVocalRecorder())
recorder->clearVocalRecorder();
CoreManager::getInstance()->getChatModel()->clear();
setCachedText("");
}
}
@ -718,8 +744,8 @@ void ChatRoomModel::forwardMessage(ChatMessageModel * model){
}
// -----------------------------------------------------------------------------
void ChatRoomModel::compose () {
if( mChatRoom)
void ChatRoomModel::compose (const QString& text) {
if( setCachedText(text) && mChatRoom)// only send a compose if text has changed
mChatRoom->compose();
}

View file

@ -92,6 +92,9 @@ public:
Q_PROPERTY(bool entriesLoading READ isEntriesLoading WRITE setEntriesLoading NOTIFY entriesLoadingChanged)
Q_PROPERTY(QString cachedText READ getCachedText WRITE setCachedText NOTIFY cachedTextChanged)
Q_PROPERTY(bool hasDraft READ hasDraft WRITE setHasDraft NOTIFY hasDraftChanged)
static QSharedPointer<ChatRoomModel> create(std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs = std::list<std::shared_ptr<linphone::CallLog>>());
ChatRoomModel (std::shared_ptr<linphone::ChatRoom> chatRoom, const std::list<std::shared_ptr<linphone::CallLog>>& callLogs = std::list<std::shared_ptr<linphone::CallLog>>(), QObject * parent = nullptr);
@ -141,6 +144,8 @@ public:
QList<QString> getComposers();
QString getParticipantAddress(); // return peerAddress if not secure else return the first participant SIP address.
int getAllUnreadCount(); // Return unread messages and missed call.
QString getCachedText() const;
bool hasDraft() const;
//---- Setters
void setSubject(QString& subject);
@ -154,6 +159,8 @@ public:
void setEphemeralEnabled(bool enabled);
void setEphemeralLifetime(long lifetime);
void enableMarkAsRead(const bool& enable);
bool setCachedText(const QString& text); // return true if cache changed
void setHasDraft(const bool& draft);
void setReply(ChatMessageModel * model);
ChatMessageModel * getReply()const;
@ -168,7 +175,7 @@ public:
Q_INVOKABLE void updateParticipants(const QVariantList& participants);
void sendMessage (const QString &message);
Q_INVOKABLE void forwardMessage(ChatMessageModel * model);
void compose ();
void compose (const QString& text);
Q_INVOKABLE void resetMessageCount ();
void initEntries();
Q_INVOKABLE int loadMoreEntries(); // return new entries count
@ -273,6 +280,8 @@ signals:
void markAsReadEnabledChanged();
void chatRoomDeleted();// Must be connected with DirectConnection mode
void replyChanged();
void cachedTextChanged();
void hasDraftChanged();
// Chat Room listener callbacks
@ -305,6 +314,8 @@ private:
QSharedPointer<ChatMessageModel> mReplyModel;
QSharedPointer<ChatNoticeModel> mUnreadMessageNotice;
int mBindingCalls = 0;
QString mCachedText; // TODO : replace it by content to manage files/audio etc.
bool mHasDraft = false;
QWeakPointer<ChatRoomModel> mSelf;
};

View file

@ -36,8 +36,6 @@
using namespace std;
QString ChatRoomProxyModel::gCachedText;
// =============================================================================
ChatRoomProxyModel::ChatRoomProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
@ -101,8 +99,7 @@ CREATE_PARENT_MODEL_FUNCTION(deleteChatRoom)
void ChatRoomProxyModel::compose (const QString& text) {
if (mChatRoomModel)
mChatRoomModel->compose();
gCachedText = text;
mChatRoomModel->compose(text);
}
int ChatRoomProxyModel::getEntryTypeFilter () {
@ -242,10 +239,6 @@ QVariant ChatRoomProxyModel::getAt(int row){
return sourceModel()->data(sourceIndex);
}
QString ChatRoomProxyModel::getCachedText() const{
return gCachedText;
}
void ChatRoomProxyModel::setIsCall(const bool& isCall){
if(mIsCall != isCall) {
if(mChatRoomModel){

View file

@ -40,7 +40,6 @@ class ChatRoomProxyModel : public QSortFilterProxyModel {
Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged)
Q_PROPERTY(ChatRoomModel *chatRoomModel READ getChatRoomModel WRITE setChatRoomModel NOTIFY chatRoomModelChanged)
Q_PROPERTY(QList<QString> composers READ getComposers NOTIFY isRemoteComposingChanged)
Q_PROPERTY(QString cachedText READ getCachedText)
Q_PROPERTY(QString filterText MEMBER mFilterText WRITE setFilterText NOTIFY filterTextChanged)
Q_PROPERTY(bool markAsReadEnabled READ markAsReadEnabled WRITE enableMarkAsRead NOTIFY markAsReadEnabledChanged)// Focus is at end of the list. Used to reset message count if not at end
@ -120,9 +119,6 @@ private:
void setChatRoomModel (ChatRoomModel *chatRoomModel);
QList<QString> getComposers () const;
QString getCachedText() const;
void reload (ChatRoomModel *chatRoomModel);
void handleIsActiveChanged (QWindow *window);
@ -138,7 +134,6 @@ private:
QString mLocalAddress;
QString mFullPeerAddress;
QString mFullLocalAddress;
static QString gCachedText;
bool mMarkAsReadEnabled;
bool mIsCall = false;

View file

@ -445,7 +445,10 @@ Rectangle {
}
}
onAudioRecordRequest: RecorderManager.resetVocalRecorder()
Component.onCompleted: {text = proxyModel.cachedText; cursorPosition=text.length}
Component.onCompleted: {
text = proxyModel.chatRoomModel.cachedText
cursorPosition=text.length
}
Rectangle{
anchors.fill:parent
color:'white'

View file

@ -17,6 +17,13 @@ QtObject {
property color selectedTimerColor: ColorsList.addImageColor(sectionName+'_ephemeralTimer_c', icon, 'q').color
}
property QtObject draft: QtObject{
property string icon: 'draft_custom'
property int iconSize : 30
property color color: ColorsList.addImageColor(sectionName+'_draft', icon, 'ad').color
property color selectedColor: ColorsList.addImageColor(sectionName+'_draft_c', icon, 'q').color
}
property QtObject contact: QtObject {
property int height: 60

View file

@ -73,14 +73,27 @@ Item {
text: mainItem.timelineModel && UtilsCpp.toDateTimeString(mainItem.timelineModel.chatRoomModel.lastUpdateTime)
isClickable: true
}
Icon{
id: draft
icon: TimelineStyle.draft.icon
iconSize: visible ? TimelineStyle.draft.iconSize : 0
overwriteColor: mainItem.timelineModel && mainItem.timelineModel.selected ? TimelineStyle.draft.selectedColor : TimelineStyle.draft.color
anchors.right:parent.right
anchors.bottom:parent.bottom
anchors.bottomMargin: 3
anchors.rightMargin: 7
visible: mainItem.timelineModel && mainItem.timelineModel.chatRoomModel.hasDraft
}
Icon{
icon: TimelineStyle.ephemeralTimer.icon
iconSize: TimelineStyle.ephemeralTimer.iconSize
overwriteColor: mainItem.timelineModel && mainItem.timelineModel.selected ? TimelineStyle.ephemeralTimer.selectedTimerColor : TimelineStyle.ephemeralTimer.timerColor
anchors.right:parent.right
anchors.right:draft.left
anchors.bottom:parent.bottom
anchors.bottomMargin: 7
anchors.rightMargin: 7
anchors.bottomMargin: 3
anchors.rightMargin: draft.visible ? 0 : 7
visible: mainItem.timelineModel && mainItem.timelineModel.chatRoomModel.ephemeralEnabled
}
MouseArea {