minor fixes, added system messages

This commit is contained in:
Андреев Григорий 2024-09-05 11:30:40 +03:00
parent 2219653f40
commit 68094f904d
6 changed files with 68 additions and 54 deletions

View File

@ -132,11 +132,10 @@ function updateOffsets(){
} }
function shouldShowDeleteMesgBtn(messageSt){ function shouldShowDeleteMesgBtn(messageSt){
return !messageSt.isSystem && messageSt.exists && (messageSt.myRoleHere !== userChatRoleReadOnly) &&( return !messageSt.isSystem && messageSt.exists && (myRoleHere !== userChatRoleReadOnly) &&(
messageSt.myRoleHere === userChatRoleAdmin || messageSt.senderUserId === userinfo.uid); myRoleHere === userChatRoleAdmin || messageSt.senderUserId === userinfo.uid);
} }
// todo: fix messageboxes
function getMsgTypeClassSenderBased(messageSt){ function getMsgTypeClassSenderBased(messageSt){
if (messageSt.isSystem) if (messageSt.isSystem)
return "message-box-system" return "message-box-system"
@ -153,6 +152,8 @@ function getMsgFullTypeClassName(messageSt){
* Supercontainer.container is persistent, Supercontainer.box can change it's class */ * Supercontainer.container is persistent, Supercontainer.box can change it's class */
function updateMessageSupercontainer(supercontainer, messageSt){ function updateMessageSupercontainer(supercontainer, messageSt){
let box = supercontainer.box; let box = supercontainer.box;
if (messageSt.isSystem)
return;
setElementVisibility(box.querySelector(".message-box-button-delete"), shouldShowDeleteMesgBtn(messageSt), "inline"); setElementVisibility(box.querySelector(".message-box-button-delete"), shouldShowDeleteMesgBtn(messageSt), "inline");
box.className = getMsgFullTypeClassName(messageSt); box.className = getMsgFullTypeClassName(messageSt);
// Notice, that no check of previous state is performed. Double loading is a rare event, I can afford to be slow // Notice, that no check of previous state is performed. Double loading is a rare event, I can afford to be slow
@ -169,13 +170,11 @@ function decodeSystemMessage(text){
if (verb === "kicked"){ if (verb === "kicked"){
return subjectRef + " kicked " + objectRef; return subjectRef + " kicked " + objectRef;
} else if (verb === "summoned"){ } else if (verb === "summoned"){
return subjectRef + " summoned " + objectId; return subjectRef + " summoned " + objectRef;
} else if (verb === "left"){ } else if (verb === "left"){
return subjectRef + " left chat"; return subjectRef + " left chat";
} else if (verb === "joined"){
return subjectId + " joined chat";
} else if (verb === "created"){ } else if (verb === "created"){
return subjectId + " created this chat"; return subjectRef + " created this chat";
} }
return "... Bad log ..."; return "... Bad log ...";
} }
@ -190,6 +189,9 @@ function convertMessageStToSupercontainer(messageSt){
let ID = messageSt.id; let ID = messageSt.id;
if (messageSt.isSystem){
} else {
let topPart = document.createElement("div"); let topPart = document.createElement("div");
box.appendChild(topPart); box.appendChild(topPart);
topPart.className = "message-box-top"; topPart.className = "message-box-top";
@ -239,7 +241,7 @@ function convertMessageStToSupercontainer(messageSt){
document.getElementById("message-input").innerText += (" " + URI + ""); document.getElementById("message-input").innerText += (" " + URI + "");
console.log("Tried to get link on message " + ID); console.log("Tried to get link on message " + ID);
}; };
}
let msgPart = document.createElement("p"); let msgPart = document.createElement("p");
box.appendChild(msgPart); box.appendChild(msgPart);

View File

@ -40,7 +40,6 @@ namespace iu9cawebchat {
void make_her_a_member_of_the_midnight_crew(SqliteConnection& conn, int64_t chatId, int64_t alienUserId, int64_t role) { void make_her_a_member_of_the_midnight_crew(SqliteConnection& conn, int64_t chatId, int64_t alienUserId, int64_t role) {
assert(role != user_chat_role_deleted); assert(role != user_chat_role_deleted);
// int64_t old_role = get_role_of_user_in_chat(conn, alienUserId, chatId);
alter_user_chat_role(conn, chatId, alienUserId, role); alter_user_chat_role(conn, chatId, alienUserId, role);
} }
@ -67,6 +66,7 @@ namespace iu9cawebchat {
} else { } else {
return at_api_error_gen_bad_recv(-2l); return at_api_error_gen_bad_recv(-2l);
} }
insert_system_message_svo(conn, chatId, uid, "summoned", alien.id);
json::JSON Recv; json::JSON Recv;
poll_update_chat(conn, Sent, Recv); poll_update_chat(conn, Sent, Recv);

View File

@ -7,6 +7,7 @@ namespace iu9cawebchat {
if (get_role_of_user_in_chat(conn, uid, chatId) == user_chat_role_deleted) if (get_role_of_user_in_chat(conn, uid, chatId) == user_chat_role_deleted)
een9_THROW("Not a member"); een9_THROW("Not a member");
kick_from_chat(conn, chatId, uid); kick_from_chat(conn, chatId, uid);
insert_system_message_svo(conn, chatId, uid, "left", -1);
json::JSON Recv; json::JSON Recv;
poll_update_chat_list(conn, uid, Sent, Recv); poll_update_chat_list(conn, uid, Sent, Recv);
return Recv; return Recv;

View File

@ -13,6 +13,7 @@ namespace iu9cawebchat {
een9_THROW("Only admin can delete members of chat"); een9_THROW("Only admin can delete members of chat");
int64_t badAlienId = Sent["userId"].asInteger().get_int(); int64_t badAlienId = Sent["userId"].asInteger().get_int();
kick_from_chat(conn, chatId, badAlienId); kick_from_chat(conn, chatId, badAlienId);
insert_system_message_svo(conn, chatId, uid, "kicked", badAlienId);
json::JSON Recv; json::JSON Recv;
poll_update_chat(conn, Sent, Recv); poll_update_chat(conn, Sent, Recv);
return Recv; return Recv;

View File

@ -8,8 +8,7 @@ namespace iu9cawebchat {
* Chat's HistoryId will increment after this operation * Chat's HistoryId will increment after this operation
* if adding system message, uid is ignored * if adding system message, uid is ignored
*/ */
void insert_new_message(SqliteConnection& conn, int64_t uid, int64_t chatId, void insert_new_message(SqliteConnection& conn, int64_t uid, int64_t chatId, const std::string& text, bool isSystem) {
const std::string& text, bool isSystem) {
int64_t chat_HistoryId_BEFORE_MSG = get_current_history_id_of_chat(conn, chatId); int64_t chat_HistoryId_BEFORE_MSG = get_current_history_id_of_chat(conn, chatId);
int64_t chat_lastMsgId = get_lastMsgId_of_chat(conn, chatId); int64_t chat_lastMsgId = get_lastMsgId_of_chat(conn, chatId);
SqliteStatement req(conn, SqliteStatement req(conn,
@ -24,6 +23,13 @@ namespace iu9cawebchat {
{{1, chat_lastMsgId + 1}, {2, chat_HistoryId_BEFORE_MSG + 1}, {3, chatId}}, {}); {{1, chat_lastMsgId + 1}, {2, chat_HistoryId_BEFORE_MSG + 1}, {3, chatId}}, {});
} }
void insert_system_message_svo(SqliteConnection& conn, int64_t chatId,
int64_t subject, const std::string& verb, int64_t object) {
insert_new_message(conn, -1, chatId,
std::to_string(subject) + "," + verb + "," + std::to_string(object), true);
}
json::JSON internalapi_sendMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) { json::JSON internalapi_sendMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) {
debug_print_json(Sent); debug_print_json(Sent);
int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int(); int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int();

View File

@ -70,6 +70,10 @@ namespace iu9cawebchat {
bool is_nickname_taken(SqliteConnection& conn, const std::string& nickname); bool is_nickname_taken(SqliteConnection& conn, const std::string& nickname);
void reserve_nickname(SqliteConnection& conn, const std::string& nickname); void reserve_nickname(SqliteConnection& conn, const std::string& nickname);
void insert_new_message(SqliteConnection& conn, int64_t uid, int64_t chatId, const std::string& text, bool isSystem);
void insert_system_message_svo(SqliteConnection& conn, int64_t chatId,
int64_t subject, const std::string& verb, int64_t object);
/* ============================= API ==================================== */ /* ============================= API ==================================== */
json::JSON internalapi_chatPollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent); json::JSON internalapi_chatPollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);
json::JSON internalapi_chatListPollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent); json::JSON internalapi_chatListPollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent);