minor fixes, added system messages
This commit is contained in:
parent
2219653f40
commit
68094f904d
@ -132,11 +132,10 @@ function updateOffsets(){
|
||||
}
|
||||
|
||||
function shouldShowDeleteMesgBtn(messageSt){
|
||||
return !messageSt.isSystem && messageSt.exists && (messageSt.myRoleHere !== userChatRoleReadOnly) &&(
|
||||
messageSt.myRoleHere === userChatRoleAdmin || messageSt.senderUserId === userinfo.uid);
|
||||
return !messageSt.isSystem && messageSt.exists && (myRoleHere !== userChatRoleReadOnly) &&(
|
||||
myRoleHere === userChatRoleAdmin || messageSt.senderUserId === userinfo.uid);
|
||||
}
|
||||
|
||||
// todo: fix messageboxes
|
||||
function getMsgTypeClassSenderBased(messageSt){
|
||||
if (messageSt.isSystem)
|
||||
return "message-box-system"
|
||||
@ -153,6 +152,8 @@ function getMsgFullTypeClassName(messageSt){
|
||||
* Supercontainer.container is persistent, Supercontainer.box can change it's class */
|
||||
function updateMessageSupercontainer(supercontainer, messageSt){
|
||||
let box = supercontainer.box;
|
||||
if (messageSt.isSystem)
|
||||
return;
|
||||
setElementVisibility(box.querySelector(".message-box-button-delete"), shouldShowDeleteMesgBtn(messageSt), "inline");
|
||||
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
|
||||
@ -169,13 +170,11 @@ function decodeSystemMessage(text){
|
||||
if (verb === "kicked"){
|
||||
return subjectRef + " kicked " + objectRef;
|
||||
} else if (verb === "summoned"){
|
||||
return subjectRef + " summoned " + objectId;
|
||||
return subjectRef + " summoned " + objectRef;
|
||||
} else if (verb === "left"){
|
||||
return subjectRef + " left chat";
|
||||
} else if (verb === "joined"){
|
||||
return subjectId + " joined chat";
|
||||
} else if (verb === "created"){
|
||||
return subjectId + " created this chat";
|
||||
return subjectRef + " created this chat";
|
||||
}
|
||||
return "... Bad log ...";
|
||||
}
|
||||
@ -190,56 +189,59 @@ function convertMessageStToSupercontainer(messageSt){
|
||||
|
||||
let ID = messageSt.id;
|
||||
|
||||
let topPart = document.createElement("div");
|
||||
box.appendChild(topPart);
|
||||
topPart.className = "message-box-top";
|
||||
if (messageSt.isSystem){
|
||||
|
||||
if (!members.has(messageSt.senderUserId))
|
||||
throw new Error("First - update members");
|
||||
let senderMemberSt = members.get(messageSt.senderUserId);
|
||||
let senderProfileURI = "/user/" + senderMemberSt.nickname;
|
||||
} else {
|
||||
let topPart = document.createElement("div");
|
||||
box.appendChild(topPart);
|
||||
topPart.className = "message-box-top";
|
||||
|
||||
let inTopPartSenderName = document.createElement("a");
|
||||
topPart.appendChild(inTopPartSenderName);
|
||||
inTopPartSenderName.className = "message-box-sender-name";
|
||||
inTopPartSenderName.innerText = senderMemberSt.name;
|
||||
inTopPartSenderName.href = senderProfileURI;
|
||||
if (!members.has(messageSt.senderUserId))
|
||||
throw new Error("First - update members");
|
||||
let senderMemberSt = members.get(messageSt.senderUserId);
|
||||
let senderProfileURI = "/user/" + senderMemberSt.nickname;
|
||||
|
||||
let inTopPartSenderNickname = document.createElement("a");
|
||||
topPart.appendChild(inTopPartSenderNickname);
|
||||
inTopPartSenderNickname.className = "message-box-sender-name message-box-sender-shortname"
|
||||
inTopPartSenderNickname.innerText = senderMemberSt.nickname;
|
||||
inTopPartSenderNickname.href = senderProfileURI;
|
||||
let inTopPartSenderName = document.createElement("a");
|
||||
topPart.appendChild(inTopPartSenderName);
|
||||
inTopPartSenderName.className = "message-box-sender-name";
|
||||
inTopPartSenderName.innerText = senderMemberSt.name;
|
||||
inTopPartSenderName.href = senderProfileURI;
|
||||
|
||||
let inTopPartButtonDelete = document.createElement("img");
|
||||
topPart.appendChild(inTopPartButtonDelete);
|
||||
inTopPartButtonDelete.className = "message-box-button message-box-button-delete";
|
||||
inTopPartButtonDelete.src = "/assets/img/delete.svg";
|
||||
inTopPartButtonDelete.onclick = (ev) => {
|
||||
if (ev.button !== 0)
|
||||
return;
|
||||
let msgText = box.querySelector(".message-box-msg").innerText;
|
||||
let previewText = senderMemberSt.nickname + ":\n" + msgText;
|
||||
if (previewText.length > 1000)
|
||||
previewText = previewText.substring(0, 1000 - 3);
|
||||
document.getElementById("win-deletion-msg-preview").innerText = previewText;
|
||||
storeHiddenMsgIdForDeletionWin = ID;
|
||||
activatePopupWindowById("msg-deletion-win");
|
||||
};
|
||||
setElementVisibility(inTopPartButtonDelete, shouldShowDeleteMesgBtn(messageSt), "inline");
|
||||
let inTopPartSenderNickname = document.createElement("a");
|
||||
topPart.appendChild(inTopPartSenderNickname);
|
||||
inTopPartSenderNickname.className = "message-box-sender-name message-box-sender-shortname"
|
||||
inTopPartSenderNickname.innerText = senderMemberSt.nickname;
|
||||
inTopPartSenderNickname.href = senderProfileURI;
|
||||
|
||||
let inTopPartButtonGetLink = document.createElement("img");
|
||||
topPart.appendChild(inTopPartButtonGetLink);
|
||||
inTopPartButtonGetLink.className = "message-box-button";
|
||||
inTopPartButtonGetLink.src = "/assets/img/link.svg";
|
||||
inTopPartButtonGetLink.onclick = (ev) => {
|
||||
if (ev.button !== 0)
|
||||
return;
|
||||
let URI = window.location.host + "/chat/" + openedchat.nickname + "/m/" + String(ID);
|
||||
document.getElementById("message-input").innerText += (" " + URI + "");
|
||||
console.log("Tried to get link on message " + ID);
|
||||
};
|
||||
let inTopPartButtonDelete = document.createElement("img");
|
||||
topPart.appendChild(inTopPartButtonDelete);
|
||||
inTopPartButtonDelete.className = "message-box-button message-box-button-delete";
|
||||
inTopPartButtonDelete.src = "/assets/img/delete.svg";
|
||||
inTopPartButtonDelete.onclick = (ev) => {
|
||||
if (ev.button !== 0)
|
||||
return;
|
||||
let msgText = box.querySelector(".message-box-msg").innerText;
|
||||
let previewText = senderMemberSt.nickname + ":\n" + msgText;
|
||||
if (previewText.length > 1000)
|
||||
previewText = previewText.substring(0, 1000 - 3);
|
||||
document.getElementById("win-deletion-msg-preview").innerText = previewText;
|
||||
storeHiddenMsgIdForDeletionWin = ID;
|
||||
activatePopupWindowById("msg-deletion-win");
|
||||
};
|
||||
setElementVisibility(inTopPartButtonDelete, shouldShowDeleteMesgBtn(messageSt), "inline");
|
||||
|
||||
let inTopPartButtonGetLink = document.createElement("img");
|
||||
topPart.appendChild(inTopPartButtonGetLink);
|
||||
inTopPartButtonGetLink.className = "message-box-button";
|
||||
inTopPartButtonGetLink.src = "/assets/img/link.svg";
|
||||
inTopPartButtonGetLink.onclick = (ev) => {
|
||||
if (ev.button !== 0)
|
||||
return;
|
||||
let URI = window.location.host + "/chat/" + openedchat.nickname + "/m/" + String(ID);
|
||||
document.getElementById("message-input").innerText += (" " + URI + "");
|
||||
console.log("Tried to get link on message " + ID);
|
||||
};
|
||||
}
|
||||
|
||||
let msgPart = document.createElement("p");
|
||||
box.appendChild(msgPart);
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -67,6 +66,7 @@ namespace iu9cawebchat {
|
||||
} else {
|
||||
return at_api_error_gen_bad_recv(-2l);
|
||||
}
|
||||
insert_system_message_svo(conn, chatId, uid, "summoned", alien.id);
|
||||
|
||||
json::JSON Recv;
|
||||
poll_update_chat(conn, Sent, Recv);
|
||||
|
@ -7,6 +7,7 @@ namespace iu9cawebchat {
|
||||
if (get_role_of_user_in_chat(conn, uid, chatId) == user_chat_role_deleted)
|
||||
een9_THROW("Not a member");
|
||||
kick_from_chat(conn, chatId, uid);
|
||||
insert_system_message_svo(conn, chatId, uid, "left", -1);
|
||||
json::JSON Recv;
|
||||
poll_update_chat_list(conn, uid, Sent, Recv);
|
||||
return Recv;
|
||||
|
@ -13,6 +13,7 @@ namespace iu9cawebchat {
|
||||
een9_THROW("Only admin can delete members of chat");
|
||||
int64_t badAlienId = Sent["userId"].asInteger().get_int();
|
||||
kick_from_chat(conn, chatId, badAlienId);
|
||||
insert_system_message_svo(conn, chatId, uid, "kicked", badAlienId);
|
||||
json::JSON Recv;
|
||||
poll_update_chat(conn, Sent, Recv);
|
||||
return Recv;
|
||||
|
@ -8,8 +8,7 @@ namespace iu9cawebchat {
|
||||
* Chat's HistoryId will increment after this operation
|
||||
* if adding system message, uid is ignored
|
||||
*/
|
||||
void insert_new_message(SqliteConnection& conn, int64_t uid, int64_t chatId,
|
||||
const std::string& text, bool isSystem) {
|
||||
void insert_new_message(SqliteConnection& conn, int64_t uid, int64_t chatId, const std::string& text, bool isSystem) {
|
||||
int64_t chat_HistoryId_BEFORE_MSG = get_current_history_id_of_chat(conn, chatId);
|
||||
int64_t chat_lastMsgId = get_lastMsgId_of_chat(conn, chatId);
|
||||
SqliteStatement req(conn,
|
||||
@ -24,6 +23,13 @@ namespace iu9cawebchat {
|
||||
{{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) {
|
||||
debug_print_json(Sent);
|
||||
int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int();
|
||||
|
@ -70,6 +70,10 @@ namespace iu9cawebchat {
|
||||
bool is_nickname_taken(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 ==================================== */
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user