channels and history commiting
parent
0de6e2a439
commit
191ffcee71
|
@ -64,6 +64,7 @@ namespace db
|
||||||
blt::u64 channelID;
|
blt::u64 channelID;
|
||||||
blt::u64 time_changed;
|
blt::u64 time_changed;
|
||||||
std::string old_channel_name;
|
std::string old_channel_name;
|
||||||
|
std::string old_channel_topic;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct message_t
|
struct message_t
|
||||||
|
@ -94,6 +95,7 @@ namespace db
|
||||||
{
|
{
|
||||||
blt::u64 messageID;
|
blt::u64 messageID;
|
||||||
blt::u64 channelID;
|
blt::u64 channelID;
|
||||||
|
blt::u64 userID;
|
||||||
std::string content;
|
std::string content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ namespace db
|
||||||
make_column("channelID", &channel_history_t::channelID),
|
make_column("channelID", &channel_history_t::channelID),
|
||||||
make_column("time_changed", &channel_history_t::time_changed),
|
make_column("time_changed", &channel_history_t::time_changed),
|
||||||
make_column("old_channel_name", &channel_history_t::old_channel_name),
|
make_column("old_channel_name", &channel_history_t::old_channel_name),
|
||||||
|
make_column("old_channel_topic", &channel_history_t::old_channel_topic),
|
||||||
foreign_key(&channel_history_t::channelID).references(&channel_info_t::channelID),
|
foreign_key(&channel_history_t::channelID).references(&channel_info_t::channelID),
|
||||||
primary_key(&channel_history_t::channelID, &channel_history_t::time_changed));
|
primary_key(&channel_history_t::channelID, &channel_history_t::time_changed));
|
||||||
}
|
}
|
||||||
|
@ -213,10 +216,12 @@ namespace db
|
||||||
return make_table("message_deletes",
|
return make_table("message_deletes",
|
||||||
make_column("messageID", &message_deletes_t::messageID),
|
make_column("messageID", &message_deletes_t::messageID),
|
||||||
make_column("channelID", &message_deletes_t::channelID),
|
make_column("channelID", &message_deletes_t::channelID),
|
||||||
|
make_column("userID", &message_deletes_t::userID),
|
||||||
make_column("content", &message_deletes_t::content),
|
make_column("content", &message_deletes_t::content),
|
||||||
foreign_key(&message_deletes_t::messageID).references(&message_t::messageID),
|
foreign_key(&message_deletes_t::messageID).references(&message_t::messageID),
|
||||||
foreign_key(&message_deletes_t::channelID).references(&channel_info_t::channelID),
|
foreign_key(&message_deletes_t::channelID).references(&channel_info_t::channelID),
|
||||||
primary_key(&message_deletes_t::messageID, &message_deletes_t::channelID));
|
foreign_key(&message_deletes_t::userID).references(&user_info_t::userID),
|
||||||
|
primary_key(&message_deletes_t::messageID, &message_deletes_t::channelID, &message_deletes_t::userID));
|
||||||
}
|
}
|
||||||
|
|
||||||
using message_deletes_table_t = decltype(make_message_deletes_table());
|
using message_deletes_table_t = decltype(make_message_deletes_table());
|
||||||
|
|
34
src/main.cpp
34
src/main.cpp
|
@ -130,7 +130,24 @@ struct db_obj
|
||||||
|
|
||||||
void commit(const channel_info_t& channel)
|
void commit(const channel_info_t& channel)
|
||||||
{
|
{
|
||||||
|
using namespace sql;
|
||||||
|
auto existing_channel = db
|
||||||
|
.select(object<channel_info_t>(), from<channel_info_t>(), where(c(&channel_info_t::channelID) == channel.channelID));
|
||||||
|
|
||||||
|
if (!existing_channel.empty())
|
||||||
|
{
|
||||||
|
for (const auto& v : existing_channel)
|
||||||
|
{
|
||||||
|
channel_history_t history;
|
||||||
|
history.channelID = v.channelID;
|
||||||
|
history.old_channel_name = v.channel_name;
|
||||||
|
history.old_channel_topic = v.channel_topic;
|
||||||
|
history.time_changed = blt::system::getCurrentTimeMilliseconds();
|
||||||
|
commit(history);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db.replace(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commit(const channel_history_t& channel)
|
void commit(const channel_history_t& channel)
|
||||||
|
@ -153,8 +170,21 @@ struct db_obj
|
||||||
db.insert(edited);
|
db.insert(edited);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commit(const message_deletes_t& deleted)
|
void commit(message_deletes_t& deleted)
|
||||||
{
|
{
|
||||||
|
using namespace sql;
|
||||||
|
auto message_content = db.select(columns(&message_t::content, &message_t::userID), from<message_t>(),
|
||||||
|
where(c(&message_t::messageID) == deleted.messageID));
|
||||||
|
|
||||||
|
if (message_content.empty())
|
||||||
|
{
|
||||||
|
BLT_WARN("Unable to delete message when no message exists!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleted.content = std::get<0>(message_content[0]);
|
||||||
|
deleted.userID = std::get<1>(message_content[0]);
|
||||||
|
|
||||||
db.insert(deleted);
|
db.insert(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue