implement trust reason in cli

pull/24/head
Zlatin Balevsky 2019-11-08 14:41:10 +00:00
parent 71298e5e73
commit 72960c24a8
5 changed files with 30 additions and 17 deletions

View File

@ -0,0 +1,7 @@
package com.muwire.clilanterna
import com.muwire.core.trust.TrustService
class TrustEntryWrapper {
TrustService.TrustEntry entry
}

View File

@ -16,8 +16,8 @@ class TrustListModel {
this.trustList = trustList this.trustList = trustList
this.core = core this.core = core
trustedTableModel = new TableModel("Trusted User","Your Trust") trustedTableModel = new TableModel("Trusted User","Reason","Your Trust")
distrustedTableModel = new TableModel("Distrusted User", "Your Trust") distrustedTableModel = new TableModel("Distrusted User", "Reason", "Your Trust")
refreshModels() refreshModels()
core.eventBus.register(TrustEvent.class, this) core.eventBus.register(TrustEvent.class, this)
@ -36,10 +36,10 @@ class TrustListModel {
distrustRows.times { distrustedTableModel.removeRow(0) } distrustRows.times { distrustedTableModel.removeRow(0) }
trustList.good.each { trustList.good.each {
trustedTableModel.addRow(new PersonaWrapper(it), core.trustService.getLevel(it.destination)) trustedTableModel.addRow(new PersonaWrapper(it.persona),it.reason, core.trustService.getLevel(it.persona.destination))
} }
trustList.bad.each { trustList.bad.each {
distrustedTableModel.addRow(new PersonaWrapper(it), core.trustService.getLevel(it.destination)) distrustedTableModel.addRow(new PersonaWrapper(it.persona),it.reason, core.trustService.getLevel(it.persona.destination))
} }
} }

View File

@ -12,6 +12,7 @@ import com.googlecode.lanterna.gui2.TextGUI
import com.googlecode.lanterna.gui2.Window import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.gui2.dialogs.MessageDialog import com.googlecode.lanterna.gui2.dialogs.MessageDialog
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton
import com.googlecode.lanterna.gui2.dialogs.TextInputDialog
import com.googlecode.lanterna.gui2.table.Table import com.googlecode.lanterna.gui2.table.Table
import com.muwire.core.Core import com.muwire.core.Core
import com.muwire.core.Persona import com.muwire.core.Persona
@ -48,7 +49,7 @@ class TrustListView extends BasicWindow {
Panel topPanel = new Panel() Panel topPanel = new Panel()
topPanel.setLayoutManager(new GridLayout(2)) topPanel.setLayoutManager(new GridLayout(2))
trusted = new Table("Trusted User","Your Trust") trusted = new Table("Trusted User","Reason","Your Trust")
trusted.with { trusted.with {
setCellSelection(false) setCellSelection(false)
setTableModel(model.trustedTableModel) setTableModel(model.trustedTableModel)
@ -57,7 +58,7 @@ class TrustListView extends BasicWindow {
trusted.setSelectAction({ actionsForUser(true) }) trusted.setSelectAction({ actionsForUser(true) })
topPanel.addComponent(trusted, layoutData) topPanel.addComponent(trusted, layoutData)
distrusted = new Table("Distrusted User", "Your Trust") distrusted = new Table("Distrusted User","Reason", "Your Trust")
distrusted.with { distrusted.with {
setCellSelection(false) setCellSelection(false)
setTableModel(model.distrustedTableModel) setTableModel(model.distrustedTableModel)
@ -90,7 +91,8 @@ class TrustListView extends BasicWindow {
LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER) LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER)
Button trustButton = new Button("Trust",{ Button trustButton = new Button("Trust",{
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.TRUSTED)) String reason = TextInputDialog.showDialog(textGUI, "Reason", "Enter reason (optional)", "")
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.TRUSTED, reason : reason))
MessageDialog.showMessageDialog(textGUI, "Marked Trusted", persona.getHumanReadableName() + "has been marked trusted", MessageDialog.showMessageDialog(textGUI, "Marked Trusted", persona.getHumanReadableName() + "has been marked trusted",
MessageDialogButton.OK) MessageDialogButton.OK)
}) })
@ -100,7 +102,8 @@ class TrustListView extends BasicWindow {
MessageDialogButton.OK) MessageDialogButton.OK)
}) })
Button distrustButton = new Button("Distrust",{ Button distrustButton = new Button("Distrust",{
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.DISTRUSTED)) String reason = TextInputDialog.showDialog(textGUI, "Reason", "Enter reason (optional)", "")
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.DISTRUSTED, reason : reason))
MessageDialog.showMessageDialog(textGUI, "Marked Distrusted", persona.getHumanReadableName() + "has been marked distrusted", MessageDialog.showMessageDialog(textGUI, "Marked Distrusted", persona.getHumanReadableName() + "has been marked distrusted",
MessageDialogButton.OK) MessageDialogButton.OK)
}) })

View File

@ -17,8 +17,8 @@ class TrustModel {
this.guiThread = guiThread this.guiThread = guiThread
this.core = core this.core = core
modelTrusted = new TableModel("Trusted Users") modelTrusted = new TableModel("Trusted Users","Reason")
modelDistrusted = new TableModel("Distrusted Users") modelDistrusted = new TableModel("Distrusted Users","Reason")
modelSubscriptions = new TableModel("Name","Trusted","Distrusted","Status","Last Updated") modelSubscriptions = new TableModel("Name","Trusted","Distrusted","Status","Last Updated")
core.eventBus.register(TrustEvent.class, this) core.eventBus.register(TrustEvent.class, this)
@ -57,11 +57,11 @@ class TrustModel {
subsRows.times { modelSubscriptions.removeRow(0) } subsRows.times { modelSubscriptions.removeRow(0) }
core.trustService.good.values().each { core.trustService.good.values().each {
modelTrusted.addRow(new PersonaWrapper(it)) modelTrusted.addRow(new PersonaWrapper(it.persona),it.reason)
} }
core.trustService.bad.values().each { core.trustService.bad.values().each {
modelDistrusted.addRow(new PersonaWrapper(it)) modelDistrusted.addRow(new PersonaWrapper(it.persona),it.reason)
} }
core.trustSubscriber.remoteTrustLists.values().each { core.trustSubscriber.remoteTrustLists.values().each {

View File

@ -11,6 +11,7 @@ import com.googlecode.lanterna.gui2.Window
import com.googlecode.lanterna.gui2.dialogs.MessageDialog import com.googlecode.lanterna.gui2.dialogs.MessageDialog
import com.googlecode.lanterna.gui2.dialogs.MessageDialogBuilder import com.googlecode.lanterna.gui2.dialogs.MessageDialogBuilder
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton
import com.googlecode.lanterna.gui2.dialogs.TextInputDialog
import com.googlecode.lanterna.gui2.GridLayout.Alignment import com.googlecode.lanterna.gui2.GridLayout.Alignment
import com.googlecode.lanterna.gui2.Label import com.googlecode.lanterna.gui2.Label
import com.googlecode.lanterna.gui2.table.Table import com.googlecode.lanterna.gui2.table.Table
@ -44,14 +45,14 @@ class TrustView extends BasicWindow {
Panel topPanel = new Panel() Panel topPanel = new Panel()
topPanel.setLayoutManager(new GridLayout(2)) topPanel.setLayoutManager(new GridLayout(2))
trusted = new Table("Trusted Users") trusted = new Table("Trusted Users","Reason")
trusted.setCellSelection(false) trusted.setCellSelection(false)
trusted.setSelectAction({trustedActions()}) trusted.setSelectAction({trustedActions()})
trusted.setTableModel(model.modelTrusted) trusted.setTableModel(model.modelTrusted)
trusted.setVisibleRows(tableSize) trusted.setVisibleRows(tableSize)
topPanel.addComponent(trusted, layoutData) topPanel.addComponent(trusted, layoutData)
distrusted = new Table("Distrusted users") distrusted = new Table("Distrusted users","Reason")
distrusted.setCellSelection(false) distrusted.setCellSelection(false)
distrusted.setSelectAction({distrustedActions()}) distrusted.setSelectAction({distrustedActions()})
distrusted.setTableModel(model.modelDistrusted) distrusted.setTableModel(model.modelDistrusted)
@ -106,7 +107,8 @@ class TrustView extends BasicWindow {
MessageDialogButton.OK) MessageDialogButton.OK)
}) })
Button markDistrusted = new Button("Mark Distrusted", { Button markDistrusted = new Button("Mark Distrusted", {
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.DISTRUSTED)) String reason = TextInputDialog.showDialog(textGUI, "Reason", "Enter reason (optional)", "")
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.DISTRUSTED, reason : reason))
MessageDialog.showMessageDialog(textGUI, "Marked Distrusted", persona.getHumanReadableName() + "has been marked distrusted", MessageDialog.showMessageDialog(textGUI, "Marked Distrusted", persona.getHumanReadableName() + "has been marked distrusted",
MessageDialogButton.OK) MessageDialogButton.OK)
}) })
@ -122,7 +124,7 @@ class TrustView extends BasicWindow {
} }
private void distrustedActions() { private void distrustedActions() {
int selectedRow = trusted.getSelectedRow() int selectedRow = distrusted.getSelectedRow()
def row = model.modelDistrusted.getRow(selectedRow) def row = model.modelDistrusted.getRow(selectedRow)
Persona persona = row[0].persona Persona persona = row[0].persona
@ -138,7 +140,8 @@ class TrustView extends BasicWindow {
MessageDialogButton.OK) MessageDialogButton.OK)
}) })
Button markDistrusted = new Button("Mark Trusted", { Button markDistrusted = new Button("Mark Trusted", {
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.TRUSTED)) String reason = TextInputDialog.showDialog(textGUI, "Reason", "Enter reason (optional)", "")
core.eventBus.publish(new TrustEvent(persona : persona, level : TrustLevel.TRUSTED, reason : reason))
MessageDialog.showMessageDialog(textGUI, "Marked Trusted", persona.getHumanReadableName() + "has been marked trusted", MessageDialog.showMessageDialog(textGUI, "Marked Trusted", persona.getHumanReadableName() + "has been marked trusted",
MessageDialogButton.OK) MessageDialogButton.OK)
}) })