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){
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,6 +189,9 @@ function convertMessageStToSupercontainer(messageSt){
let ID = messageSt.id;
if (messageSt.isSystem){
} else {
let topPart = document.createElement("div");
box.appendChild(topPart);
topPart.className = "message-box-top";
@ -239,7 +241,7 @@ function convertMessageStToSupercontainer(messageSt){
document.getElementById("message-input").innerText += (" " + URI + "");
console.log("Tried to get link on message " + ID);
};
}
let msgPart = document.createElement("p");
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) {
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);

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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);