master #6

Open
karimov-adel wants to merge 39 commits from master into adel_branch_2.0
6 changed files with 68 additions and 54 deletions
Showing only changes of commit 68094f904d - Show all commits

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,56 +189,59 @@ function convertMessageStToSupercontainer(messageSt){
let ID = messageSt.id; let ID = messageSt.id;
let topPart = document.createElement("div"); if (messageSt.isSystem){
box.appendChild(topPart);
topPart.className = "message-box-top";
if (!members.has(messageSt.senderUserId)) } else {
throw new Error("First - update members"); let topPart = document.createElement("div");
let senderMemberSt = members.get(messageSt.senderUserId); box.appendChild(topPart);
let senderProfileURI = "/user/" + senderMemberSt.nickname; topPart.className = "message-box-top";
let inTopPartSenderName = document.createElement("a"); if (!members.has(messageSt.senderUserId))
topPart.appendChild(inTopPartSenderName); throw new Error("First - update members");
inTopPartSenderName.className = "message-box-sender-name"; let senderMemberSt = members.get(messageSt.senderUserId);
inTopPartSenderName.innerText = senderMemberSt.name; let senderProfileURI = "/user/" + senderMemberSt.nickname;
inTopPartSenderName.href = senderProfileURI;
let inTopPartSenderNickname = document.createElement("a"); let inTopPartSenderName = document.createElement("a");
topPart.appendChild(inTopPartSenderNickname); topPart.appendChild(inTopPartSenderName);
inTopPartSenderNickname.className = "message-box-sender-name message-box-sender-shortname" inTopPartSenderName.className = "message-box-sender-name";
inTopPartSenderNickname.innerText = senderMemberSt.nickname; inTopPartSenderName.innerText = senderMemberSt.name;
inTopPartSenderNickname.href = senderProfileURI; inTopPartSenderName.href = senderProfileURI;
let inTopPartButtonDelete = document.createElement("img"); let inTopPartSenderNickname = document.createElement("a");
topPart.appendChild(inTopPartButtonDelete); topPart.appendChild(inTopPartSenderNickname);
inTopPartButtonDelete.className = "message-box-button message-box-button-delete"; inTopPartSenderNickname.className = "message-box-sender-name message-box-sender-shortname"
inTopPartButtonDelete.src = "/assets/img/delete.svg"; inTopPartSenderNickname.innerText = senderMemberSt.nickname;
inTopPartButtonDelete.onclick = (ev) => { inTopPartSenderNickname.href = senderProfileURI;
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"); let inTopPartButtonDelete = document.createElement("img");
topPart.appendChild(inTopPartButtonGetLink); topPart.appendChild(inTopPartButtonDelete);
inTopPartButtonGetLink.className = "message-box-button"; inTopPartButtonDelete.className = "message-box-button message-box-button-delete";
inTopPartButtonGetLink.src = "/assets/img/link.svg"; inTopPartButtonDelete.src = "/assets/img/delete.svg";
inTopPartButtonGetLink.onclick = (ev) => { inTopPartButtonDelete.onclick = (ev) => {
if (ev.button !== 0) if (ev.button !== 0)
return; return;
let URI = window.location.host + "/chat/" + openedchat.nickname + "/m/" + String(ID); let msgText = box.querySelector(".message-box-msg").innerText;
document.getElementById("message-input").innerText += (" " + URI + ""); let previewText = senderMemberSt.nickname + ":\n" + msgText;
console.log("Tried to get link on message " + ID); 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"); 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);