update// fixed wrong savings
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
ChatModel::ChatModel(std::map<long, ChatItem> chatItems)
|
||||
ChatModel::ChatModel(std::map<QString, ChatItem> chatItems)
|
||||
{
|
||||
this->chatItems = chatItems;
|
||||
}
|
||||
@@ -24,12 +24,26 @@ ChatModel::ChatModel(std::vector<ChatItem> chatItems)
|
||||
this->setItems(chatItems);
|
||||
}
|
||||
|
||||
std::map<long, ChatItem> ChatModel::getItems()
|
||||
QString ChatModel::generateChatItemID(ChatItem item)
|
||||
{
|
||||
QString key = QString::number(item.getTimestamp()) + QString("-");
|
||||
key += QString(QCryptographicHash::hash(
|
||||
QString(
|
||||
QString::number(item.getTimestamp()) +
|
||||
item.getAddress() +
|
||||
item.getContact() +
|
||||
item.getMemo()
|
||||
).toUtf8()
|
||||
,QCryptographicHash::Md5).toHex());
|
||||
return key;
|
||||
}
|
||||
|
||||
std::map<QString, ChatItem> ChatModel::getItems()
|
||||
{
|
||||
return this->chatItems;
|
||||
}
|
||||
|
||||
void ChatModel::setItems(std::map<long, ChatItem> items)
|
||||
void ChatModel::setItems(std::map<QString, ChatItem> items)
|
||||
{
|
||||
this->chatItems = chatItems;
|
||||
}
|
||||
@@ -38,7 +52,7 @@ void ChatModel::setItems(std::vector<ChatItem> items)
|
||||
{
|
||||
for(ChatItem c : items)
|
||||
{
|
||||
this->chatItems[c.getTimestamp()] = c;
|
||||
this->chatItems[this->generateChatItemID(c)] = c;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -50,12 +64,16 @@ void ChatModel::clear()
|
||||
|
||||
void ChatModel::addMessage(ChatItem item)
|
||||
{
|
||||
this->chatItems[item.getTimestamp()] = item;
|
||||
QString key = this->generateChatItemID(item);
|
||||
qDebug() << "inserting chatitem with id: " << key;
|
||||
this->chatItems[key] = item;
|
||||
}
|
||||
|
||||
void ChatModel::addMessage(long timestamp, ChatItem item)
|
||||
void ChatModel::addMessage(QString timestamp, ChatItem item)
|
||||
{
|
||||
this->chatItems[timestamp] = item;
|
||||
QString key = this->generateChatItemID(item);
|
||||
timestamp = "0";
|
||||
this->chatItems[key] = item;
|
||||
}
|
||||
|
||||
void ChatModel::showMessages()
|
||||
@@ -120,6 +138,26 @@ void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget *view)
|
||||
|
||||
}
|
||||
|
||||
void ChatModel::addCid(QString tx, QString cid)
|
||||
{
|
||||
this->cidMap[tx] = cid;
|
||||
}
|
||||
|
||||
QString ChatModel::getCidByTx(QString tx)
|
||||
{
|
||||
if(this->cidMap.count(tx) > 0)
|
||||
{
|
||||
return this->cidMap[tx];
|
||||
}
|
||||
|
||||
return QString("0xdeadbeef");
|
||||
}
|
||||
|
||||
void ChatModel::killCidCache()
|
||||
{
|
||||
this->cidMap.clear();
|
||||
}
|
||||
|
||||
QString MainWindow::createHeaderMemo(QString type, QString cid, QString zaddr, int version=0, int headerNumber=1)
|
||||
{
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class ChatItem
|
||||
return _cid;
|
||||
}
|
||||
|
||||
QString getTxid()
|
||||
QString getTxid()
|
||||
{
|
||||
return _txid;
|
||||
}
|
||||
@@ -130,17 +130,19 @@ class ChatItem
|
||||
class ChatModel
|
||||
{
|
||||
private:
|
||||
std::map<long, ChatItem> chatItems;
|
||||
std::map<QString, ChatItem> chatItems;
|
||||
QTableView* parent;
|
||||
Ui::MainWindow* ui;
|
||||
MainWindow* main;
|
||||
std::map<QString, QString> cidMap;
|
||||
|
||||
public:
|
||||
ChatModel() {};
|
||||
ChatModel(std::map<long, ChatItem> chatItems);
|
||||
ChatModel(std::map<QString, ChatItem> chatItems);
|
||||
ChatModel(std::vector<ChatItem> chatItems);
|
||||
std::map<long, ChatItem> getItems();
|
||||
void setItems(std::map<long, ChatItem> items);
|
||||
QString generateChatItemID(ChatItem item);
|
||||
std::map<QString, ChatItem> getItems();
|
||||
void setItems(std::map<QString, ChatItem> items);
|
||||
QString zaddr();
|
||||
void setItems(std::vector<ChatItem> items);
|
||||
void renderChatBox(Ui::MainWindow* ui, QListWidget &view);
|
||||
@@ -148,7 +150,10 @@ class ChatModel
|
||||
void showMessages();
|
||||
void clear();
|
||||
void addMessage(ChatItem item);
|
||||
void addMessage(long timestamp, ChatItem item);
|
||||
void addMessage(QString timestamp, ChatItem item);
|
||||
void addCid(QString tx, QString cid);
|
||||
QString getCidByTx(QString tx);
|
||||
void killCidCache();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -940,11 +940,10 @@ void Controller::refreshTransactions() {
|
||||
txdata.push_back(tx);
|
||||
|
||||
QString cid = "";
|
||||
// if (memo.startsWith("{")) {
|
||||
|
||||
// cid = memo.mid(14,36);
|
||||
|
||||
// }else{ cid = "";}
|
||||
if (memo.startsWith("{")) {
|
||||
cid = memo.mid(14,36);
|
||||
chatModel->addCid(txid, cid);
|
||||
}else{ cid = "";}
|
||||
|
||||
ChatItem item = ChatItem(
|
||||
datetime,
|
||||
|
||||
Reference in New Issue
Block a user