Skip to content

Commit

Permalink
Add personas functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pontaoski committed Nov 17, 2020
1 parent 58cca85 commit b82078b
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 3 deletions.
23 changes: 22 additions & 1 deletion messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ QHash<int,QByteArray> MessagesModel::roleNames() const
return ret;
}

void MessagesModel::sendMessage(const QString& message, const QString &replyTo, const QStringList& attachments)
void MessagesModel::sendMessageFull(const QString& message, const QString &replyTo, const QStringList& attachments, const SendAs& as)
{
ClientContext ctx;
client->authenticate(ctx);
Expand All @@ -220,6 +220,27 @@ void MessagesModel::sendMessage(const QString& message, const QString &replyTo,
req.add_attachments(attachment.toStdString());
}

if (std::holds_alternative<Nobody>(as)) {

} else if (std::holds_alternative<Fronter>(as)) {
auto& fronter = std::get<Fronter>(as);

auto override = new protocol::core::v1::Override();
override->set_name(fronter.name.toStdString());
override->set_allocated_system_plurality(new google::protobuf::Empty{});

req.set_allocated_overrides(override);

} else if (std::holds_alternative<RoleplayCharacter>(as)) {
auto& character = std::get<RoleplayCharacter>(as);

auto override = new protocol::core::v1::Override();
override->set_name(character.name.toStdString());
override->set_user_defined("Roleplay");

req.set_allocated_overrides(override);
}

protocol::core::v1::SendMessageResponse empty;

client->coreKit->SendMessage(&ctx, req, &empty);
Expand Down
28 changes: 27 additions & 1 deletion messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ class MessagesModel : public QAbstractListModel
MessageCombinedAuthorIDAvatarRole
};

struct Fronter {
QString name;
};
struct RoleplayCharacter {
QString name;
};

using Nobody = std::monostate;
using SendAs = std::variant<Nobody, Fronter, RoleplayCharacter>;

protected:
Q_INVOKABLE void customEvent(QEvent *event) override;

Expand All @@ -138,7 +148,23 @@ class MessagesModel : public QAbstractListModel
Q_INVOKABLE bool isOwner() { return isGuildOwner; }
Q_INVOKABLE QString userID() { return QString::number(client->userID); }
Q_INVOKABLE QVariantMap peekMessage(const QString& id);
Q_INVOKABLE void sendMessage(const QString& content, const QString& replyTo, const QStringList& attachments);
Q_INVOKABLE void sendMessageFull(const QString& content, const QString& replyTo, const QStringList& attachments, const SendAs& as);
Q_INVOKABLE void sendMessage(const QString& content, const QString& replyTo, const QStringList& attachments)
{
sendMessageFull(content, replyTo, attachments, SendAs(Nobody{}));
}
Q_INVOKABLE void sendMessageAsSystem(const QString& content, const QString& replyTo, const QStringList& attachments, const QString& memberName)
{
sendMessageFull(content, replyTo, attachments, SendAs(Fronter {
.name = memberName
}));
}
Q_INVOKABLE void sendMessageAsRoleplay(const QString& content, const QString& replyTo, const QStringList& attachments, const QString& characterName)
{
sendMessageFull(content, replyTo, attachments, SendAs(RoleplayCharacter {
.name = characterName
}));
}
Q_INVOKABLE void editMessage(const QString& id, const QString& content);
Q_INVOKABLE void deleteMessage(const QString& id);
Q_INVOKABLE void triggerAction(const QString& messageID, const QString& name, const QString& data);
Expand Down
22 changes: 21 additions & 1 deletion resources/ComposeBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ QQC2.ToolBar {
Layout.fillWidth: true
}
RowLayout {
QQC2.ComboBox {
id: settingsCombo
model: [{
"name": qsTr("Default"),
"kind": "default"
}].concat(uiSettings.personas)
visible: uiSettings.personas.length > 0
textRole: "name"
}
QQC2.TextField {
id: messageField
//: Placeholder text for the message field
Expand All @@ -115,7 +124,18 @@ QQC2.ToolBar {
Layout.fillWidth: true

function send() {
Kirigami.PageRouter.data.sendMessage(text, replyingBar.replyingToID, [])
if (uiSettings.personas.length == 0) {
Kirigami.PageRouter.data.sendMessage(text, replyingBar.replyingToID, [])
} else {
switch (settingsCombo.model[settingsCombo.currentIndex].kind) {
case "default":
Kirigami.PageRouter.data.sendMessage(text, replyingBar.replyingToID, []); break
case "roleplay":
Kirigami.PageRouter.data.sendMessageAsRoleplay(text, replyingBar.replyingToID, [], settingsCombo.model[settingsCombo.currentIndex].name); break
case "plurality":
Kirigami.PageRouter.data.sendMessageAsSystem(text, replyingBar.replyingToID, [], settingsCombo.model[settingsCombo.currentIndex].name); break
}
}
text = ""
replyingBar.replyingToID = ""
}
Expand Down
100 changes: 100 additions & 0 deletions resources/MurmurSettings.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Layouts 1.10
import org.kde.kirigami 2.13 as Kirigami
import QtQuick.Controls 2.10 as QQC2
import com.github.HarmonyDevelopment.Staccato 1.0

Kirigami.Page {
id: invitePage
title: qsTr("Settings")
padding: 0
Kirigami.Theme.colorSet: Kirigami.Theme.View

Kirigami.SwipeNavigator {
anchors.fill: parent

Kirigami.ScrollablePage {
//: Personas are alternate identities; e.g. for roleplay reasons
title: qsTr("Personas")
actions.main: Kirigami.Action {
text: qsTr("New Persona")
iconName: "list-add"
onTriggered: personaAddSheet.begin()
}

Kirigami.OverlaySheet {
id: personaAddSheet
parent: root

Kirigami.FormLayout {
QQC2.TextField {
id: nameField

Kirigami.FormData.label: qsTr("Persona Name:")
}
QQC2.ComboBox {
id: reasonField
model: [
{
"uiString": qsTr("Roleplay"),
"id": "roleplay"
},
{
"uiString": "System Member",
"id": "plurality"
}
]
textRole: "uiString"
Kirigami.FormData.label: qsTr("Persona Kind:")
}
QQC2.Button {
text: qsTr("Create")
onClicked: {
let settings = uiSettings.personas
settings.push({
"name": nameField.text,
"kind": reasonField.model[reasonField.currentIndex].id
})
uiSettings.personas = settings
personaAddSheet.close()
}
}
}

function begin() {
nameField.text = ""
reasonField.currentIndex = 0
this.open()
}
}

ListView {
model: uiSettings.personas
delegate: Kirigami.SwipeListItem {
id: personaDelegate

contentItem: QQC2.Label {
text: modelData["name"]
verticalAlignment: Text.AlignVCenter
}
actions: [
Kirigami.Action {
icon.name: "edit-delete"
onTriggered: {
let a = uiSettings.personas
print(index)
a.splice(index)
uiSettings.personas = a
}
}
]
}
}
}
}
}
4 changes: 4 additions & 0 deletions resources/StaccatoDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Item {
Menu {
id: appMenu

MenuItem {
text: qsTr("Settings")
onTriggered: root.pageStack.layers.push(Qt.resolvedUrl("MurmurSettings.qml"), {})
}
MenuItem {
text: qsTr("Log Out")
onTriggered: routerInstance.navigateToRoute("login")
Expand Down
5 changes: 5 additions & 0 deletions resources/UISettings.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Qt.labs.settings 1.0 as Labs

Labs.Settings {
property var personas: []
}
3 changes: 3 additions & 0 deletions resources/data.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<file>RecursiveMenuActionComponent.qml</file>
<file>RightDrawer.qml</file>
<file>StaccatoDrawer.qml</file>
<file>MurmurSettings.qml</file>
<file>UISettings.qml</file>
<file>qmldir</file>
</qresource>
<qresource prefix="/img">
<file>com.github.Harmony.Murmur.svg</file>
Expand Down
2 changes: 2 additions & 0 deletions resources/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Kirigami.ApplicationWindow {
minimumWidth: 300
width: 1000

UISettings { id: uiSettings }

pageStack.globalToolBar.showNavigationButtons: 0
pageStack.initialPage: Kirigami.Page {
padding: 0
Expand Down
Empty file added resources/qmldir
Empty file.

0 comments on commit b82078b

Please sign in to comment.