Skip to content

Commit

Permalink
Make nick click and reply click working
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 30, 2024
1 parent ca2cf66 commit 2d5823c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/chatview_webkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ class ChatViewJSObject : public ChatViewThemeSession {

Q_INVOKABLE void deleteMessage(const QString &messageId) { qDebug() << "deleteMessage" << messageId; }

Q_INVOKABLE void replyMessage(const QString &messageId) { qDebug() << "replyMessage" << messageId; }
Q_INVOKABLE void replyMessage(const QString &messageId, const QString &quotedHtml)
{
auto plainText = TextUtil::rich2plain(quotedHtml);
emit _view->quote(plainText);
qDebug() << "replyMessage" << messageId;
}

Q_INVOKABLE void copyMessage(const QString &messageId) { qDebug() << "copyMessage" << messageId; }

Expand Down
40 changes: 33 additions & 7 deletions themes/chatview/psi/bubble/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>
<span class="time" title="%time{LL}%">%time%</span>
%quoteTxt%
<span class="msgtext">%message%</span>
<span class="%msgtextClasses%">%message%</span>
</div>%next%`;

shared.initTheme({
Expand All @@ -47,7 +47,7 @@
dateFormat : "HH:mm",
proxy : function() { //optional
if (shared.cdata.mtype == "reactions") {
render_reactions(shared.cdata);
renderReactions(shared.cdata);
return false;
}
},
Expand All @@ -62,6 +62,13 @@
}
return classes.join(" ");
},
msgtextClasses: function() {
let classes = ["msgtext"];
if (shared.cdata.alert) {
classes.push("alert");
}
return classes.join(" ");
},
nickControl: function() {
return shared.cdata.local? "": `<div class="reply">Reply</div>`;
},
Expand All @@ -86,10 +93,23 @@
bq.addEventListener("click", () => { quoteMsg.scrollIntoView({ "behavior": "smooth", "block": "center" }) });
}
}
var replyBtn = el.getElementsByClassName("reply").item(0);
if (replyBtn) {
replyBtn.addEventListener("click", ()=>{onReplyClicked(el);});
}
var nickEl = el.getElementsByClassName("nick").item(0);
if (nickEl) {
nickEl.addEventListener("click", ()=>{shared.session.nickInsertClick(nickEl.textContent);});
}
}
});

function setup_context_menu() {
function onReplyClicked(el) {
var textEl = el.getElementsByClassName("msgtext").item(0);
shared.session.replyMessage(el.id, textEl.innerHTML);
}

function setupContextMenu() {
chatMenu.addItemProvider((event) => {
const isNick = event.target.className == "nick";
let msgNode;
Expand All @@ -113,7 +133,7 @@
} else {
items = [
{ text: "Delete", action: ()=>{ shared.session.deleteMessage(msgNode.id); } },
{ text: "Reply", action: ()=>{ shared.session.replyMessage(msgNode.id); } },
{ text: "Reply", action: ()=>{ onReplyClicked(msgNode); } },
{ text: "Forward", action: ()=>{ shared.session.forwardMessage(msgNode.id); } },
{ text: "Copy", action: ()=>{ shared.session.copyMessage(msgNode.id); } }
]
Expand All @@ -125,7 +145,7 @@
}


function render_reactions(event) {
function renderReactions(event) {
const msg = document.getElementById(event.messageid);
if (!msg) {
return;
Expand Down Expand Up @@ -154,7 +174,9 @@
const nicks = value.nicks.sort().filter((x, i, a) => !i || x != a[i-1]);
const reaction = document.createElement("span");
reaction.innerHTML = `${nicks.length} ${value.text}`;
reaction.title = nicks.join("\n");
if (shared.isMuc) {
reaction.title = nicks.join("\n");
}
reaction.addEventListener("click", (event)=>{
if (event.target.nodeName == "EM") {
shared.session.react(msg.id, event.target.textContent);
Expand All @@ -166,7 +188,7 @@
}
}

setup_context_menu();
setupContextMenu();

applyPsiSettings();

Expand Down Expand Up @@ -262,6 +284,10 @@
clip: rect(0.6rem, 3rem, 1.5rem, 2rem);
}

.msg:hover::before {
border-color: #ffffff;
}

.mymsg {
margin-left: 0.5rem;
margin-right: 3rem;
Expand Down

0 comments on commit 2d5823c

Please sign in to comment.