Fix notification issue.

This commit is contained in:
Black Hat 2018-09-10 08:06:32 +08:00
parent f5b24f32b8
commit 13a8d6b889
10 changed files with 47 additions and 83 deletions

View File

@ -1,44 +1,7 @@
/* jshint browser: true, devel: true */ .pragma library
/**
* preg_replace (from PHP) in JavaScript!
*
* This is basically a pattern replace. You can use a regex pattern to search and
* another for the replace. For more information see the PHP docs on the original
* function (http://php.net/manual/en/function.preg-replace.php), and for more on
* JavaScript flavour regex visit http://www.regular-expressions.info/javascript.html
*
* NOTE: Unlike the PHP version, this function only deals with string inputs. No arrays.
*
* @author William Duyck <fuzzyfox0@gmail.com>
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License 2.0
*
* @param {String} pattern The pattern to search for.
* @param {String} replace The string to replace.
* @param {String} subject The string to search and replace.
* @param {Integer} limit The maximum possible replacements.
* @return {String} If matches are found, the new subject will be returned.
*/
var preg_replace=function(a,b,c,d){void 0===d&&(d=-1);var e=a.substr(a.lastIndexOf(a[0])+1),f=a.substr(1,a.lastIndexOf(a[0])-1),g=RegExp(f,e),i=[],j=0,k=0,l=c,m=[];if(-1===d){do m=g.exec(c),null!==m&&i.push(m);while(null!==m&&-1!==e.indexOf("g"))}else i.push(g.exec(c));for(j=i.length-1;j>-1;j--){for(m=b,k=i[j].length;k>-1;k--)m=m.replace("${"+k+"}",i[j][k]).replace("$"+k,i[j][k]).replace("\\"+k,i[j][k]);l=l.replace(i[j][0],m)}return l}; var preg_replace=function(a,b,c,d){void 0===d&&(d=-1);var e=a.substr(a.lastIndexOf(a[0])+1),f=a.substr(1,a.lastIndexOf(a[0])-1),g=RegExp(f,e),i=[],j=0,k=0,l=c,m=[];if(-1===d){do m=g.exec(c),null!==m&&i.push(m);while(null!==m&&-1!==e.indexOf("g"))}else i.push(g.exec(c));for(j=i.length-1;j>-1;j--){for(m=b,k=i[j].length;k>-1;k--)m=m.replace("${"+k+"}",i[j][k]).replace("$"+k,i[j][k]).replace("\\"+k,i[j][k]);l=l.replace(i[j][0],m)}return l};
/**
* Basic Markdown Parser
*
* This function parses a small subset of the Markdown language as defined by
* [John Gruber](http://daringfireball.net/projects/markdown). It's very basic
* and needs to be refactored a little, and there are plans to add more support
* for the rest of the language in the near future.
*
* This implimentation is based loosely on
* [slimdown.php](https://gist.github.com/jbroadway/2836900) by Johnny Broadway.
*
* @version 0.1
* @author William Duyck <fuzzyfox0@gmail.com>
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License 2.0
*
* @param {String} str A Markdown string to be converted to HTML.
* @return {String} The HTML for the given Markdown.
*/
var markdown_parser = function(str){ var markdown_parser = function(str){
var rules = [ var rules = [

25
js/util.js Normal file
View File

@ -0,0 +1,25 @@
.pragma library
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
function pushToStack(stack, page) {
if(page && stack.currentItem !== page) {
if(stack.depth === 1) {
stack.replace(page)
} else {
stack.clear()
stack.push(page)
}
}
}

View File

@ -4,6 +4,8 @@ import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import Matrique 0.1 import Matrique 0.1
import "qrc:/js/util.js" as Util
Drawer { Drawer {
property var room property var room
@ -94,6 +96,10 @@ Drawer {
boundsBehavior: Flickable.DragOverBounds boundsBehavior: Flickable.DragOverBounds
model: UserListModel {
room: roomDrawer.room
}
delegate: ItemDelegate { delegate: ItemDelegate {
width: parent.width width: parent.width
height: 48 height: 48
@ -107,6 +113,7 @@ Drawer {
Layout.preferredWidth: height Layout.preferredWidth: height
Layout.fillHeight: true Layout.fillHeight: true
defaultColor: Util.stringToColor(name)
image: avatar image: avatar
hint: name hint: name
} }
@ -119,12 +126,6 @@ Drawer {
} }
} }
model: UserListModel {
id: userListModel
room: roomDrawer.room
}
ScrollBar.vertical: ScrollBar {} ScrollBar.vertical: ScrollBar {}
} }

View File

@ -3,6 +3,8 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
import "qrc:/js/util.js" as Util
ItemDelegate { ItemDelegate {
property var page property var page
readonly property bool selected: stackView.currentItem === page readonly property bool selected: stackView.currentItem === page
@ -18,14 +20,5 @@ ItemDelegate {
} }
} }
onClicked: { onClicked: Util.pushToStack(stackView, page)
if(page && stackView.currentItem !== page) {
if(stackView.depth === 1) {
stackView.replace(page)
} else {
stackView.clear()
stackView.push(page)
}
}
}
} }

View File

@ -9,6 +9,7 @@ import SortFilterProxyModel 0.2
import Matrique.Settings 0.1 import Matrique.Settings 0.1
import "../component" import "../component"
import "qrc:/js/util.js" as Util
Item { Item {
property alias listModel: roomListProxyModel.sourceModel property alias listModel: roomListProxyModel.sourceModel
@ -142,14 +143,6 @@ Item {
spacing: 12 spacing: 12
// ImageStatus {
// Layout.preferredWidth: height
// Layout.fillHeight: true
// source: avatar ? "image://mxc/" + avatar : ""
// displayText: name
// }
ImageItem { ImageItem {
id: imageItem id: imageItem
@ -157,7 +150,7 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
hint: name || "No Name" hint: name || "No Name"
defaultColor: stringToColor(name || "No Name") defaultColor: Util.stringToColor(name || "No Name")
image: avatar image: avatar
} }
@ -224,17 +217,4 @@ Item {
} }
} }
} }
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
} }

View File

@ -290,7 +290,7 @@ ApplicationWindow {
id: stackView id: stackView
// initialItem: roomPage initialItem: roomPage
} }
} }

View File

@ -30,5 +30,6 @@
<file>qml/component/StateDelegate.qml</file> <file>qml/component/StateDelegate.qml</file>
<file>qml/component/AutoLabel.qml</file> <file>qml/component/AutoLabel.qml</file>
<file>qml/component/RoomDrawer.qml</file> <file>qml/component/RoomDrawer.qml</file>
<file>js/util.js</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -82,7 +82,7 @@ int AccountListModel::rowCount(const QModelIndex& parent) const {
} }
void AccountListModel::connectConnectionSignals(Connection* conn) { void AccountListModel::connectConnectionSignals(Connection* conn) {
connect(conn->user(), &User::avatarChanged, [=] { connect(conn->user(), &User::avatarChanged, this, [=] {
const auto it = std::find(m_connections.begin(), m_connections.end(), conn); const auto it = std::find(m_connections.begin(), m_connections.end(), conn);
if (it == m_connections.end()) { if (it == m_connections.end()) {
return; return;

View File

@ -92,8 +92,8 @@ void Controller::addConnection(Connection* c) {
m_connections.push_back(c); m_connections.push_back(c);
connect(c, &Connection::syncDone, this, [=] { connect(c, &Connection::syncDone, this, [=] {
static int counter = 0; c->saveState();
if (++counter % 17 == 2) c->saveState(); c->sync(30000);
}); });
connect(c, &Connection::loggedOut, this, [=] { dropConnection(c); }); connect(c, &Connection::loggedOut, this, [=] { dropConnection(c); });

View File

@ -15,9 +15,9 @@ RoomListModel::~RoomListModel() {}
void RoomListModel::setConnection(Connection* connection) { void RoomListModel::setConnection(Connection* connection) {
if (connection == m_connection) return; if (connection == m_connection) return;
m_connection->disconnect(this);
if (!connection) { if (!connection) {
qDebug() << "Removing current connection..."; qDebug() << "Removing current connection...";
m_connection->disconnect(this);
m_connection = nullptr; m_connection = nullptr;
beginResetModel(); beginResetModel();
m_rooms.clear(); m_rooms.clear();
@ -25,9 +25,10 @@ void RoomListModel::setConnection(Connection* connection) {
return; return;
} }
using QMatrixClient::Room;
m_connection = connection; m_connection = connection;
for (MatriqueRoom* room : m_rooms) room->disconnect(this);
connect(connection, &Connection::connected, this, connect(connection, &Connection::connected, this,
&RoomListModel::doResetModel); &RoomListModel::doResetModel);
connect(connection, &Connection::invitedRoom, this, connect(connection, &Connection::invitedRoom, this,
@ -73,7 +74,7 @@ void RoomListModel::connectRoomSignals(MatriqueRoom* room) {
[=] { refresh(room, {AvatarRole}); }); [=] { refresh(room, {AvatarRole}); });
connect(room, &Room::addedMessages, this, connect(room, &Room::addedMessages, this,
[=] { refresh(room, {LastEventRole}); }); [=] { refresh(room, {LastEventRole}); });
connect(room, &QMatrixClient::Room::aboutToAddNewMessages, this, connect(room, &Room::aboutToAddNewMessages, this,
[=](QMatrixClient::RoomEventsRange eventsRange) { [=](QMatrixClient::RoomEventsRange eventsRange) {
RoomEvent* event = (eventsRange.end() - 1)->get(); RoomEvent* event = (eventsRange.end() - 1)->get();
if (event->isStateEvent()) return; if (event->isStateEvent()) return;