Skip to content

Commit

Permalink
bruig: show mediate ID requests in list of kx attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
miki authored and miki-totefu committed Oct 11, 2024
1 parent 5778917 commit 711b0c0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
6 changes: 5 additions & 1 deletion bruig/flutterui/bruig/lib/components/interactive_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ class UserAvatarFromID extends StatelessWidget {
class UserNickFromID extends StatelessWidget {
final String uid;
final TextSize? textSize;
const UserNickFromID(this.uid, {this.textSize, super.key});
final String nickAlternative;
const UserNickFromID(this.uid,
{this.textSize, this.nickAlternative = "", super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -264,6 +266,8 @@ class UserNickFromID extends StatelessWidget {
nick = chat.nick;
} else if (uid == client.publicID) {
nick = "me (${client.nick})";
} else {
nick = nickAlternative;
}
return Txt(nick, size: textSize);
}
Expand Down
24 changes: 22 additions & 2 deletions bruig/flutterui/bruig/lib/screens/list_kxs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ class _ListKXsScreenState extends State<ListKXsScreen> {
void listKXs() async {
try {
var newKXs = await Golib.listKXs();
var newMIs = await Golib.listMediateIDRequests();

// Add the mediate ID requests as if they were KX attempts to simplify
// the report.
newKXs.addAll(newMIs.map((mi) => KXData(
PublicIdentity("", "", mi.target),
"",
"",
"",
"",
KXStage.mediateID,
mi.date,
null,
false,
mi.mediator)));

newKXs.sortBy((v) => v.timestamp);
newKXs.reverseRange(0, newKXs.length);
setState(() => kxs = newKXs);
Expand All @@ -34,6 +50,10 @@ class _ListKXsScreenState extends State<ListKXsScreen> {
}
}

String kxTargetID(KXData kx) =>
kx.invitee?.identity ?? kx.public?.identity ?? "";
String kxTargetNick(KXData kx) => kx.invitee?.nick ?? kx.public?.nick ?? "";

@override
void initState() {
super.initState();
Expand All @@ -56,8 +76,8 @@ class _ListKXsScreenState extends State<ListKXsScreen> {
["Stage", "${kx.stage}"],
["Updated", "${kx.timestamp}"],
["Initial RV", Copyable(kx.initialRV)],
["Target Nick", kx.invitee?.nick ?? ""],
["Target ID", Copyable(kx.invitee?.identity ?? "")],
["Target ID", Copyable(kxTargetID(kx))],
["Target Nick", kxTargetNick(kx)],
["Mediator ID", Copyable(kx.mediatorID ?? "")],
[
"Mediator",
Expand Down
29 changes: 18 additions & 11 deletions bruig/flutterui/plugin/lib/definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,7 @@ enum KXStage {
step2IdKX,
@JsonValue(2)
step3IDKX,
mediateID,
}

@JsonSerializable()
Expand Down Expand Up @@ -2261,6 +2262,17 @@ class KXData {
factory KXData.fromJson(Map<String, dynamic> json) => _$KXDataFromJson(json);
}

@JsonSerializable()
class MediateIDRequest {
final String mediator;
final String target;
final DateTime date;

MediateIDRequest(this.mediator, this.target, this.date);
factory MediateIDRequest.fromJson(Map<String, dynamic> json) =>
_$MediateIDRequestFromJson(json);
}

mixin NtfStreams {
StreamController<RemoteUser> ntfAcceptedInvites =
StreamController<RemoteUser>();
Expand Down Expand Up @@ -3295,17 +3307,11 @@ abstract class PluginPlatform {
return (res as List).map<String>((v) => v as String).toList();
}

Future<List<KXData>> listKXs() async {
// jsonToList(await asyncCall(CTListKXs, null), KXData.fromJson);
var res = await asyncCall(
CTListKXs, null);
if (res == null) {
return List.empty();
}
return (res as List)
.map<KXData>((v) => KXData.fromJson(v))
.toList();
}
Future<List<KXData>> listKXs() async =>
jsonToList(await asyncCall(CTListKXs, null), KXData.fromJson);

Future<List<MediateIDRequest>> listMediateIDRequests() async => jsonToList(
await asyncCall(CTListMIRequests, null), MediateIDRequest.fromJson);
}

const int CTUnknown = 0x00;
Expand Down Expand Up @@ -3441,6 +3447,7 @@ const int CTSubAllPosts = 0x8d;
const int CTUpdateUINotificationsCfg = 0x8e;
const int CTGCListUnkxdMembers = 0x8f;
const int CTListKXs = 0x90;
const int CTListMIRequests = 0x91;

const int notificationsStartID = 0x1000;

Expand Down
14 changes: 14 additions & 0 deletions bruig/flutterui/plugin/lib/definitions.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bruig/golib/command_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,9 @@ func handleClientCmd(cc *clientCtx, cmd *cmd) (interface{}, error) {

case CTListKXs:
return c.ListKXs()

case CTListMIRequests:
return c.ListMediateIDs()
}
return nil, nil

Expand Down
1 change: 1 addition & 0 deletions bruig/golib/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const (
CTUpdateUINotificationsCfg = 0x8e
CTGCListUnkxdMembers = 0x8f
CTListKXs = 0x90
CTListMIRequests = 0x91

NTInviteReceived = 0x1001
NTInviteAccepted = 0x1002
Expand Down

0 comments on commit 711b0c0

Please sign in to comment.