1use {crate::utils::CommandSyntax, crate::*};
2
3use std::fmt::Write;
4#[derive(Debug, Clone, PartialEq)]
20#[cfg_attr(feature = "bon", derive(::bon::Builder))]
21pub struct ApiCreateMyAddress {
22 pub user_id: i64,
23}
24
25impl CommandSyntax for ApiCreateMyAddress {
26 const COMMAND_BUF_SIZE: usize = 64;
27
28 fn append_command_syntax(&self, buf: &mut String) {
29 buf.push_str("/_address ");
30 write!(buf, "{}", self.user_id).unwrap();
31 }
32}
33
34#[derive(Debug, Clone, PartialEq)]
50#[cfg_attr(feature = "bon", derive(::bon::Builder))]
51pub struct ApiDeleteMyAddress {
52 pub user_id: i64,
53}
54
55impl CommandSyntax for ApiDeleteMyAddress {
56 const COMMAND_BUF_SIZE: usize = 64;
57
58 fn append_command_syntax(&self, buf: &mut String) {
59 buf.push_str("/_delete_address ");
60 write!(buf, "{}", self.user_id).unwrap();
61 }
62}
63
64#[derive(Debug, Clone, PartialEq)]
80#[cfg_attr(feature = "bon", derive(::bon::Builder))]
81pub struct ApiShowMyAddress {
82 pub user_id: i64,
83}
84
85impl CommandSyntax for ApiShowMyAddress {
86 const COMMAND_BUF_SIZE: usize = 64;
87
88 fn append_command_syntax(&self, buf: &mut String) {
89 buf.push_str("/_show_address ");
90 write!(buf, "{}", self.user_id).unwrap();
91 }
92}
93
94#[derive(Debug, Clone, PartialEq)]
110#[cfg_attr(feature = "bon", derive(::bon::Builder))]
111pub struct ApiSetProfileAddress {
112 pub user_id: i64,
113 pub enable: bool,
114}
115
116impl ApiSetProfileAddress {
117 pub fn new(user_id: i64) -> Self {
119 Self {
120 user_id,
121 enable: false,
122 }
123 }
124}
125
126impl CommandSyntax for ApiSetProfileAddress {
127 const COMMAND_BUF_SIZE: usize = 64;
128
129 fn append_command_syntax(&self, buf: &mut String) {
130 buf.push_str("/_profile_address ");
131 write!(buf, "{}", self.user_id).unwrap();
132 buf.push(' ');
133 if self.enable {
134 buf.push_str("on");
135 } else {
136 buf.push_str("off");
137 }
138 }
139}
140
141#[derive(Debug, Clone, PartialEq)]
157#[cfg_attr(feature = "bon", derive(::bon::Builder))]
158pub struct ApiSetAddressSettings {
159 pub user_id: i64,
160 pub settings: AddressSettings,
161}
162
163impl CommandSyntax for ApiSetAddressSettings {
164 const COMMAND_BUF_SIZE: usize = 1024;
165
166 fn append_command_syntax(&self, buf: &mut String) {
167 buf.push_str("/_address_settings ");
168 write!(buf, "{}", self.user_id).unwrap();
169 buf.push(' ');
170 unsafe {
172 serde_json::to_writer(buf.as_mut_vec(), &self.settings).unwrap();
173 }
174 }
175}
176
177#[derive(Debug, Clone, PartialEq)]
193#[cfg_attr(feature = "bon", derive(::bon::Builder))]
194pub struct ApiSendMessages {
195 pub send_ref: ChatRef,
196 pub live_message: bool,
197 pub ttl: Option<i32>,
198 pub composed_messages: Vec<ComposedMessage>,
199}
200
201impl ApiSendMessages {
202 pub fn new(send_ref: ChatRef, composed_messages: Vec<ComposedMessage>) -> Self {
204 Self {
205 send_ref,
206 live_message: false,
207 ttl: None,
208 composed_messages,
209 }
210 }
211}
212
213impl CommandSyntax for ApiSendMessages {
214 const COMMAND_BUF_SIZE: usize = 1024;
215
216 fn append_command_syntax(&self, buf: &mut String) {
217 buf.push_str("/_send ");
218 self.send_ref.append_command_syntax(buf);
219 if self.live_message {
220 buf.push(' ');
221 buf.push_str("live=");
222 buf.push_str("on");
223 }
224 if let Some(ttl) = &self.ttl {
225 buf.push(' ');
226 buf.push_str("ttl=");
227 write!(buf, "{}", ttl).unwrap();
228 }
229 buf.push(' ');
230 buf.push_str("json ");
231 unsafe {
233 serde_json::to_writer(buf.as_mut_vec(), &self.composed_messages).unwrap();
234 }
235 }
236}
237
238#[derive(Debug, Clone, PartialEq)]
254#[cfg_attr(feature = "bon", derive(::bon::Builder))]
255pub struct ApiUpdateChatItem {
256 pub chat_ref: ChatRef,
257 pub chat_item_id: i64,
258 pub live_message: bool,
259 pub updated_message: UpdatedMessage,
260}
261
262impl ApiUpdateChatItem {
263 pub fn new(chat_ref: ChatRef, chat_item_id: i64, updated_message: UpdatedMessage) -> Self {
265 Self {
266 chat_ref,
267 chat_item_id,
268 live_message: false,
269 updated_message,
270 }
271 }
272}
273
274impl CommandSyntax for ApiUpdateChatItem {
275 const COMMAND_BUF_SIZE: usize = 1024;
276
277 fn append_command_syntax(&self, buf: &mut String) {
278 buf.push_str("/_update ");
279 buf.push_str("item ");
280 self.chat_ref.append_command_syntax(buf);
281 buf.push(' ');
282 write!(buf, "{}", self.chat_item_id).unwrap();
283 if self.live_message {
284 buf.push(' ');
285 buf.push_str("live=");
286 buf.push_str("on");
287 }
288 buf.push(' ');
289 buf.push_str("json ");
290 unsafe {
292 serde_json::to_writer(buf.as_mut_vec(), &self.updated_message).unwrap();
293 }
294 }
295}
296
297#[derive(Debug, Clone, PartialEq)]
313#[cfg_attr(feature = "bon", derive(::bon::Builder))]
314pub struct ApiDeleteChatItem {
315 pub chat_ref: ChatRef,
316 pub chat_item_ids: Vec<i64>,
317 pub delete_mode: CIDeleteMode,
318}
319
320impl CommandSyntax for ApiDeleteChatItem {
321 const COMMAND_BUF_SIZE: usize = 256;
322
323 fn append_command_syntax(&self, buf: &mut String) {
324 buf.push_str("/_delete ");
325 buf.push_str("item ");
326 self.chat_ref.append_command_syntax(buf);
327 buf.push(' ');
328 let mut iter = self.chat_item_ids.iter();
329 if let Some(el) = iter.next() {
330 write!(buf, "{el}").unwrap();
331 }
332 for el in iter {
333 buf.push(',');
334 write!(buf, "{el}").unwrap();
335 }
336 buf.push(' ');
337 match self.delete_mode {
338 CIDeleteMode::Broadcast => {
339 buf.push_str("broadcast");
340 }
341 CIDeleteMode::Internal => {
342 buf.push_str("internal");
343 }
344 CIDeleteMode::InternalMark => {
345 buf.push_str("internalMark");
346 }
347 CIDeleteMode::History => {
348 buf.push_str("history");
349 }
350 }
351 }
352}
353
354#[derive(Debug, Clone, PartialEq)]
370#[cfg_attr(feature = "bon", derive(::bon::Builder))]
371pub struct ApiDeleteMemberChatItem {
372 pub group_id: i64,
373 pub chat_item_ids: Vec<i64>,
374}
375
376impl CommandSyntax for ApiDeleteMemberChatItem {
377 const COMMAND_BUF_SIZE: usize = 256;
378
379 fn append_command_syntax(&self, buf: &mut String) {
380 buf.push_str("/_delete ");
381 buf.push_str("member ");
382 buf.push_str("item ");
383 buf.push('#');
384 write!(buf, "{}", self.group_id).unwrap();
385 buf.push(' ');
386 let mut iter = self.chat_item_ids.iter();
387 if let Some(el) = iter.next() {
388 write!(buf, "{el}").unwrap();
389 }
390 for el in iter {
391 buf.push(',');
392 write!(buf, "{el}").unwrap();
393 }
394 }
395}
396
397#[derive(Debug, Clone, PartialEq)]
413#[cfg_attr(feature = "bon", derive(::bon::Builder))]
414pub struct ApiChatItemReaction {
415 pub chat_ref: ChatRef,
416 pub chat_item_id: i64,
417 pub add: bool,
418 pub reaction: MsgReaction,
419}
420
421impl ApiChatItemReaction {
422 pub fn new(chat_ref: ChatRef, chat_item_id: i64, reaction: MsgReaction) -> Self {
424 Self {
425 chat_ref,
426 chat_item_id,
427 add: false,
428 reaction,
429 }
430 }
431}
432
433impl CommandSyntax for ApiChatItemReaction {
434 const COMMAND_BUF_SIZE: usize = 1024;
435
436 fn append_command_syntax(&self, buf: &mut String) {
437 buf.push_str("/_reaction ");
438 self.chat_ref.append_command_syntax(buf);
439 buf.push(' ');
440 write!(buf, "{}", self.chat_item_id).unwrap();
441 buf.push(' ');
442 if self.add {
443 buf.push_str("on");
444 } else {
445 buf.push_str("off");
446 }
447 buf.push(' ');
448 unsafe {
450 serde_json::to_writer(buf.as_mut_vec(), &self.reaction).unwrap();
451 }
452 }
453}
454
455#[derive(Debug, Clone, PartialEq)]
471#[cfg_attr(feature = "bon", derive(::bon::Builder))]
472pub struct ReceiveFile {
473 pub file_id: i64,
474 pub user_approved_relays: bool,
475 pub store_encrypted: Option<bool>,
476 pub file_inline: Option<bool>,
477 pub file_path: Option<String>,
478}
479
480impl ReceiveFile {
481 pub fn new(file_id: i64) -> Self {
483 Self {
484 file_id,
485 user_approved_relays: false,
486 store_encrypted: None,
487 file_inline: None,
488 file_path: None,
489 }
490 }
491}
492
493impl CommandSyntax for ReceiveFile {
494 const COMMAND_BUF_SIZE: usize = 256;
495
496 fn append_command_syntax(&self, buf: &mut String) {
497 buf.push_str("/freceive ");
498 write!(buf, "{}", self.file_id).unwrap();
499 if self.user_approved_relays {
500 buf.push(' ');
501 buf.push_str("approved_relays=");
502 buf.push_str("on");
503 }
504 if let Some(store_encrypted) = &self.store_encrypted {
505 buf.push(' ');
506 buf.push_str("encrypt=");
507 if *store_encrypted {
508 buf.push_str("on");
509 } else {
510 buf.push_str("off");
511 }
512 }
513 if let Some(file_inline) = &self.file_inline {
514 buf.push(' ');
515 buf.push_str("inline=");
516 if *file_inline {
517 buf.push_str("on");
518 } else {
519 buf.push_str("off");
520 }
521 }
522 if let Some(file_path) = &self.file_path {
523 buf.push(' ');
524 write!(buf, "{}", file_path).unwrap();
525 }
526 }
527}
528
529#[derive(Debug, Clone, PartialEq)]
545#[cfg_attr(feature = "bon", derive(::bon::Builder))]
546pub struct CancelFile {
547 pub file_id: i64,
548}
549
550impl CommandSyntax for CancelFile {
551 const COMMAND_BUF_SIZE: usize = 64;
552
553 fn append_command_syntax(&self, buf: &mut String) {
554 buf.push_str("/fcancel ");
555 write!(buf, "{}", self.file_id).unwrap();
556 }
557}
558
559#[derive(Debug, Clone, PartialEq)]
575#[cfg_attr(feature = "bon", derive(::bon::Builder))]
576pub struct ApiAddMember {
577 pub group_id: i64,
578 pub contact_id: i64,
579 pub member_role: GroupMemberRole,
580}
581
582impl CommandSyntax for ApiAddMember {
583 const COMMAND_BUF_SIZE: usize = 256;
584
585 fn append_command_syntax(&self, buf: &mut String) {
586 buf.push_str("/_add ");
587 buf.push('#');
588 write!(buf, "{}", self.group_id).unwrap();
589 buf.push(' ');
590 write!(buf, "{}", self.contact_id).unwrap();
591 buf.push(' ');
592 match self.member_role {
593 GroupMemberRole::Relay => {
594 buf.push_str("relay");
595 }
596 GroupMemberRole::Observer => {
597 buf.push_str("observer");
598 }
599 GroupMemberRole::Author => {
600 buf.push_str("author");
601 }
602 GroupMemberRole::Member => {
603 buf.push_str("member");
604 }
605 GroupMemberRole::Moderator => {
606 buf.push_str("moderator");
607 }
608 GroupMemberRole::Admin => {
609 buf.push_str("admin");
610 }
611 GroupMemberRole::Owner => {
612 buf.push_str("owner");
613 }
614 }
615 }
616}
617
618#[derive(Debug, Clone, PartialEq)]
634#[cfg_attr(feature = "bon", derive(::bon::Builder))]
635pub struct ApiJoinGroup {
636 pub group_id: i64,
637}
638
639impl CommandSyntax for ApiJoinGroup {
640 const COMMAND_BUF_SIZE: usize = 64;
641
642 fn append_command_syntax(&self, buf: &mut String) {
643 buf.push_str("/_join ");
644 buf.push('#');
645 write!(buf, "{}", self.group_id).unwrap();
646 }
647}
648
649#[derive(Debug, Clone, PartialEq)]
665#[cfg_attr(feature = "bon", derive(::bon::Builder))]
666pub struct ApiAcceptMember {
667 pub group_id: i64,
668 pub group_member_id: i64,
669 pub member_role: GroupMemberRole,
670}
671
672impl CommandSyntax for ApiAcceptMember {
673 const COMMAND_BUF_SIZE: usize = 256;
674
675 fn append_command_syntax(&self, buf: &mut String) {
676 buf.push_str("/_accept ");
677 buf.push_str("member ");
678 buf.push('#');
679 write!(buf, "{}", self.group_id).unwrap();
680 buf.push(' ');
681 write!(buf, "{}", self.group_member_id).unwrap();
682 buf.push(' ');
683 match self.member_role {
684 GroupMemberRole::Relay => {
685 buf.push_str("relay");
686 }
687 GroupMemberRole::Observer => {
688 buf.push_str("observer");
689 }
690 GroupMemberRole::Author => {
691 buf.push_str("author");
692 }
693 GroupMemberRole::Member => {
694 buf.push_str("member");
695 }
696 GroupMemberRole::Moderator => {
697 buf.push_str("moderator");
698 }
699 GroupMemberRole::Admin => {
700 buf.push_str("admin");
701 }
702 GroupMemberRole::Owner => {
703 buf.push_str("owner");
704 }
705 }
706 }
707}
708
709#[derive(Debug, Clone, PartialEq)]
725#[cfg_attr(feature = "bon", derive(::bon::Builder))]
726pub struct ApiMembersRole {
727 pub group_id: i64,
728 pub group_member_ids: Vec<i64>,
729 pub member_role: GroupMemberRole,
730}
731
732impl CommandSyntax for ApiMembersRole {
733 const COMMAND_BUF_SIZE: usize = 256;
734
735 fn append_command_syntax(&self, buf: &mut String) {
736 buf.push_str("/_member ");
737 buf.push_str("role ");
738 buf.push('#');
739 write!(buf, "{}", self.group_id).unwrap();
740 buf.push(' ');
741 let mut iter = self.group_member_ids.iter();
742 if let Some(el) = iter.next() {
743 write!(buf, "{el}").unwrap();
744 }
745 for el in iter {
746 buf.push(',');
747 write!(buf, "{el}").unwrap();
748 }
749 buf.push(' ');
750 match self.member_role {
751 GroupMemberRole::Relay => {
752 buf.push_str("relay");
753 }
754 GroupMemberRole::Observer => {
755 buf.push_str("observer");
756 }
757 GroupMemberRole::Author => {
758 buf.push_str("author");
759 }
760 GroupMemberRole::Member => {
761 buf.push_str("member");
762 }
763 GroupMemberRole::Moderator => {
764 buf.push_str("moderator");
765 }
766 GroupMemberRole::Admin => {
767 buf.push_str("admin");
768 }
769 GroupMemberRole::Owner => {
770 buf.push_str("owner");
771 }
772 }
773 }
774}
775
776#[derive(Debug, Clone, PartialEq)]
792#[cfg_attr(feature = "bon", derive(::bon::Builder))]
793pub struct ApiBlockMembersForAll {
794 pub group_id: i64,
795 pub group_member_ids: Vec<i64>,
796 pub blocked: bool,
797}
798
799impl ApiBlockMembersForAll {
800 pub fn new(group_id: i64, group_member_ids: Vec<i64>) -> Self {
802 Self {
803 group_id,
804 group_member_ids,
805 blocked: false,
806 }
807 }
808}
809
810impl CommandSyntax for ApiBlockMembersForAll {
811 const COMMAND_BUF_SIZE: usize = 256;
812
813 fn append_command_syntax(&self, buf: &mut String) {
814 buf.push_str("/_block ");
815 buf.push('#');
816 write!(buf, "{}", self.group_id).unwrap();
817 buf.push(' ');
818 let mut iter = self.group_member_ids.iter();
819 if let Some(el) = iter.next() {
820 write!(buf, "{el}").unwrap();
821 }
822 for el in iter {
823 buf.push(',');
824 write!(buf, "{el}").unwrap();
825 }
826 buf.push(' ');
827 buf.push_str("blocked=");
828 if self.blocked {
829 buf.push_str("on");
830 } else {
831 buf.push_str("off");
832 }
833 }
834}
835
836#[derive(Debug, Clone, PartialEq)]
852#[cfg_attr(feature = "bon", derive(::bon::Builder))]
853pub struct ApiRemoveMembers {
854 pub group_id: i64,
855 pub group_member_ids: Vec<i64>,
856 pub with_messages: bool,
857}
858
859impl ApiRemoveMembers {
860 pub fn new(group_id: i64, group_member_ids: Vec<i64>) -> Self {
862 Self {
863 group_id,
864 group_member_ids,
865 with_messages: false,
866 }
867 }
868}
869
870impl CommandSyntax for ApiRemoveMembers {
871 const COMMAND_BUF_SIZE: usize = 256;
872
873 fn append_command_syntax(&self, buf: &mut String) {
874 buf.push_str("/_remove ");
875 buf.push('#');
876 write!(buf, "{}", self.group_id).unwrap();
877 buf.push(' ');
878 let mut iter = self.group_member_ids.iter();
879 if let Some(el) = iter.next() {
880 write!(buf, "{el}").unwrap();
881 }
882 for el in iter {
883 buf.push(',');
884 write!(buf, "{el}").unwrap();
885 }
886 if self.with_messages {
887 buf.push(' ');
888 buf.push_str("messages=");
889 buf.push_str("on");
890 }
891 }
892}
893
894#[derive(Debug, Clone, PartialEq)]
910#[cfg_attr(feature = "bon", derive(::bon::Builder))]
911pub struct ApiLeaveGroup {
912 pub group_id: i64,
913}
914
915impl CommandSyntax for ApiLeaveGroup {
916 const COMMAND_BUF_SIZE: usize = 64;
917
918 fn append_command_syntax(&self, buf: &mut String) {
919 buf.push_str("/_leave ");
920 buf.push('#');
921 write!(buf, "{}", self.group_id).unwrap();
922 }
923}
924
925#[derive(Debug, Clone, PartialEq)]
941#[cfg_attr(feature = "bon", derive(::bon::Builder))]
942pub struct ApiListMembers {
943 pub group_id: i64,
944}
945
946impl CommandSyntax for ApiListMembers {
947 const COMMAND_BUF_SIZE: usize = 64;
948
949 fn append_command_syntax(&self, buf: &mut String) {
950 buf.push_str("/_members ");
951 buf.push('#');
952 write!(buf, "{}", self.group_id).unwrap();
953 }
954}
955
956#[derive(Debug, Clone, PartialEq)]
972#[cfg_attr(feature = "bon", derive(::bon::Builder))]
973pub struct ApiNewGroup {
974 pub user_id: i64,
975 pub incognito: bool,
976 pub group_profile: GroupProfile,
977}
978
979impl ApiNewGroup {
980 pub fn new(user_id: i64, group_profile: GroupProfile) -> Self {
982 Self {
983 user_id,
984 incognito: false,
985 group_profile,
986 }
987 }
988}
989
990impl CommandSyntax for ApiNewGroup {
991 const COMMAND_BUF_SIZE: usize = 1024;
992
993 fn append_command_syntax(&self, buf: &mut String) {
994 buf.push_str("/_group ");
995 write!(buf, "{}", self.user_id).unwrap();
996 if self.incognito {
997 buf.push(' ');
998 buf.push_str("incognito=");
999 buf.push_str("on");
1000 }
1001 buf.push(' ');
1002 unsafe {
1004 serde_json::to_writer(buf.as_mut_vec(), &self.group_profile).unwrap();
1005 }
1006 }
1007}
1008
1009#[derive(Debug, Clone, PartialEq)]
1025#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1026pub struct ApiNewPublicGroup {
1027 pub user_id: i64,
1028 pub incognito: bool,
1029 pub relay_ids: Vec<i64>,
1030 pub group_profile: GroupProfile,
1031}
1032
1033impl ApiNewPublicGroup {
1034 pub fn new(user_id: i64, relay_ids: Vec<i64>, group_profile: GroupProfile) -> Self {
1036 Self {
1037 user_id,
1038 incognito: false,
1039 relay_ids,
1040 group_profile,
1041 }
1042 }
1043}
1044
1045impl CommandSyntax for ApiNewPublicGroup {
1046 const COMMAND_BUF_SIZE: usize = 1024;
1047
1048 fn append_command_syntax(&self, buf: &mut String) {
1049 buf.push_str("/_public ");
1050 buf.push_str("group ");
1051 write!(buf, "{}", self.user_id).unwrap();
1052 if self.incognito {
1053 buf.push(' ');
1054 buf.push_str("incognito=");
1055 buf.push_str("on");
1056 }
1057 buf.push(' ');
1058 let mut iter = self.relay_ids.iter();
1059 if let Some(el) = iter.next() {
1060 write!(buf, "{el}").unwrap();
1061 }
1062 for el in iter {
1063 buf.push(',');
1064 write!(buf, "{el}").unwrap();
1065 }
1066 buf.push(' ');
1067 unsafe {
1069 serde_json::to_writer(buf.as_mut_vec(), &self.group_profile).unwrap();
1070 }
1071 }
1072}
1073
1074#[derive(Debug, Clone, PartialEq)]
1090#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1091pub struct ApiGetGroupRelays {
1092 pub group_id: i64,
1093}
1094
1095impl CommandSyntax for ApiGetGroupRelays {
1096 const COMMAND_BUF_SIZE: usize = 64;
1097
1098 fn append_command_syntax(&self, buf: &mut String) {
1099 buf.push_str("/_get ");
1100 buf.push_str("relays ");
1101 buf.push('#');
1102 write!(buf, "{}", self.group_id).unwrap();
1103 }
1104}
1105
1106#[derive(Debug, Clone, PartialEq)]
1122#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1123pub struct ApiAddGroupRelays {
1124 pub group_id: i64,
1125 pub relay_ids: Vec<i64>,
1126}
1127
1128impl CommandSyntax for ApiAddGroupRelays {
1129 const COMMAND_BUF_SIZE: usize = 256;
1130
1131 fn append_command_syntax(&self, buf: &mut String) {
1132 buf.push_str("/_add ");
1133 buf.push_str("relays ");
1134 buf.push('#');
1135 write!(buf, "{}", self.group_id).unwrap();
1136 buf.push(' ');
1137 let mut iter = self.relay_ids.iter();
1138 if let Some(el) = iter.next() {
1139 write!(buf, "{el}").unwrap();
1140 }
1141 for el in iter {
1142 buf.push(',');
1143 write!(buf, "{el}").unwrap();
1144 }
1145 }
1146}
1147
1148#[derive(Debug, Clone, PartialEq)]
1164#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1165pub struct ApiAllowRelayGroup {
1166 pub group_id: i64,
1167}
1168
1169impl CommandSyntax for ApiAllowRelayGroup {
1170 const COMMAND_BUF_SIZE: usize = 64;
1171
1172 fn append_command_syntax(&self, buf: &mut String) {
1173 buf.push_str("/_relay ");
1174 buf.push_str("allow ");
1175 buf.push('#');
1176 write!(buf, "{}", self.group_id).unwrap();
1177 }
1178}
1179
1180#[derive(Debug, Clone, PartialEq)]
1196#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1197pub struct ApiUpdateGroupProfile {
1198 pub group_id: i64,
1199 pub group_profile: GroupProfile,
1200}
1201
1202impl CommandSyntax for ApiUpdateGroupProfile {
1203 const COMMAND_BUF_SIZE: usize = 1024;
1204
1205 fn append_command_syntax(&self, buf: &mut String) {
1206 buf.push_str("/_group_profile ");
1207 buf.push('#');
1208 write!(buf, "{}", self.group_id).unwrap();
1209 buf.push(' ');
1210 unsafe {
1212 serde_json::to_writer(buf.as_mut_vec(), &self.group_profile).unwrap();
1213 }
1214 }
1215}
1216
1217#[derive(Debug, Clone, PartialEq)]
1233#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1234pub struct ApiCreateGroupLink {
1235 pub group_id: i64,
1236 pub member_role: GroupMemberRole,
1237}
1238
1239impl CommandSyntax for ApiCreateGroupLink {
1240 const COMMAND_BUF_SIZE: usize = 64;
1241
1242 fn append_command_syntax(&self, buf: &mut String) {
1243 buf.push_str("/_create ");
1244 buf.push_str("link ");
1245 buf.push('#');
1246 write!(buf, "{}", self.group_id).unwrap();
1247 buf.push(' ');
1248 match self.member_role {
1249 GroupMemberRole::Relay => {
1250 buf.push_str("relay");
1251 }
1252 GroupMemberRole::Observer => {
1253 buf.push_str("observer");
1254 }
1255 GroupMemberRole::Author => {
1256 buf.push_str("author");
1257 }
1258 GroupMemberRole::Member => {
1259 buf.push_str("member");
1260 }
1261 GroupMemberRole::Moderator => {
1262 buf.push_str("moderator");
1263 }
1264 GroupMemberRole::Admin => {
1265 buf.push_str("admin");
1266 }
1267 GroupMemberRole::Owner => {
1268 buf.push_str("owner");
1269 }
1270 }
1271 }
1272}
1273
1274#[derive(Debug, Clone, PartialEq)]
1290#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1291pub struct ApiGroupLinkMemberRole {
1292 pub group_id: i64,
1293 pub member_role: GroupMemberRole,
1294}
1295
1296impl CommandSyntax for ApiGroupLinkMemberRole {
1297 const COMMAND_BUF_SIZE: usize = 64;
1298
1299 fn append_command_syntax(&self, buf: &mut String) {
1300 buf.push_str("/_set ");
1301 buf.push_str("link ");
1302 buf.push_str("role ");
1303 buf.push('#');
1304 write!(buf, "{}", self.group_id).unwrap();
1305 buf.push(' ');
1306 match self.member_role {
1307 GroupMemberRole::Relay => {
1308 buf.push_str("relay");
1309 }
1310 GroupMemberRole::Observer => {
1311 buf.push_str("observer");
1312 }
1313 GroupMemberRole::Author => {
1314 buf.push_str("author");
1315 }
1316 GroupMemberRole::Member => {
1317 buf.push_str("member");
1318 }
1319 GroupMemberRole::Moderator => {
1320 buf.push_str("moderator");
1321 }
1322 GroupMemberRole::Admin => {
1323 buf.push_str("admin");
1324 }
1325 GroupMemberRole::Owner => {
1326 buf.push_str("owner");
1327 }
1328 }
1329 }
1330}
1331
1332#[derive(Debug, Clone, PartialEq)]
1348#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1349pub struct ApiDeleteGroupLink {
1350 pub group_id: i64,
1351}
1352
1353impl CommandSyntax for ApiDeleteGroupLink {
1354 const COMMAND_BUF_SIZE: usize = 64;
1355
1356 fn append_command_syntax(&self, buf: &mut String) {
1357 buf.push_str("/_delete ");
1358 buf.push_str("link ");
1359 buf.push('#');
1360 write!(buf, "{}", self.group_id).unwrap();
1361 }
1362}
1363
1364#[derive(Debug, Clone, PartialEq)]
1380#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1381pub struct ApiGetGroupLink {
1382 pub group_id: i64,
1383}
1384
1385impl CommandSyntax for ApiGetGroupLink {
1386 const COMMAND_BUF_SIZE: usize = 64;
1387
1388 fn append_command_syntax(&self, buf: &mut String) {
1389 buf.push_str("/_get ");
1390 buf.push_str("link ");
1391 buf.push('#');
1392 write!(buf, "{}", self.group_id).unwrap();
1393 }
1394}
1395
1396#[derive(Debug, Clone, PartialEq)]
1412#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1413pub struct ApiAddContact {
1414 pub user_id: i64,
1415 pub incognito: bool,
1416}
1417
1418impl ApiAddContact {
1419 pub fn new(user_id: i64) -> Self {
1421 Self {
1422 user_id,
1423 incognito: false,
1424 }
1425 }
1426}
1427
1428impl CommandSyntax for ApiAddContact {
1429 const COMMAND_BUF_SIZE: usize = 64;
1430
1431 fn append_command_syntax(&self, buf: &mut String) {
1432 buf.push_str("/_connect ");
1433 write!(buf, "{}", self.user_id).unwrap();
1434 if self.incognito {
1435 buf.push(' ');
1436 buf.push_str("incognito=");
1437 buf.push_str("on");
1438 }
1439 }
1440}
1441
1442#[derive(Debug, Clone, PartialEq)]
1458#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1459pub struct ApiConnectPlan {
1460 pub user_id: i64,
1461 pub connection_link: Option<String>,
1462 pub resolve_known: bool,
1463 pub link_owner_sig: Option<LinkOwnerSig>,
1464}
1465
1466impl ApiConnectPlan {
1467 pub fn new(user_id: i64) -> Self {
1469 Self {
1470 user_id,
1471 connection_link: None,
1472 resolve_known: false,
1473 link_owner_sig: None,
1474 }
1475 }
1476}
1477
1478impl CommandSyntax for ApiConnectPlan {
1479 const COMMAND_BUF_SIZE: usize = 256;
1480
1481 fn append_command_syntax(&self, buf: &mut String) {
1482 buf.push_str("/_connect ");
1483 buf.push_str("plan ");
1484 write!(buf, "{}", self.user_id).unwrap();
1485 buf.push(' ');
1486 write!(
1487 buf,
1488 "{}",
1489 self.connection_link.as_deref().unwrap_or_default()
1490 )
1491 .unwrap();
1492 }
1493}
1494
1495#[derive(Debug, Clone, PartialEq)]
1511#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1512pub struct ApiConnect {
1513 pub user_id: i64,
1514 pub incognito: bool,
1515 pub prepared_link: Option<CreatedConnLink>,
1516}
1517
1518impl ApiConnect {
1519 pub fn new(user_id: i64) -> Self {
1521 Self {
1522 user_id,
1523 incognito: false,
1524 prepared_link: None,
1525 }
1526 }
1527}
1528
1529impl CommandSyntax for ApiConnect {
1530 const COMMAND_BUF_SIZE: usize = 256;
1531
1532 fn append_command_syntax(&self, buf: &mut String) {
1533 buf.push_str("/_connect ");
1534 write!(buf, "{}", self.user_id).unwrap();
1535 if let Some(prepared_link) = &self.prepared_link {
1536 buf.push(' ');
1537 prepared_link.append_command_syntax(buf);
1538 }
1539 }
1540}
1541
1542#[derive(Debug, Clone, PartialEq)]
1558#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1559pub struct Connect {
1560 pub incognito: bool,
1561 pub conn_link: Option<String>,
1562}
1563
1564impl Connect {
1565 pub fn new() -> Self {
1567 Self {
1568 incognito: false,
1569 conn_link: None,
1570 }
1571 }
1572}
1573
1574impl CommandSyntax for Connect {
1575 const COMMAND_BUF_SIZE: usize = 64;
1576
1577 fn append_command_syntax(&self, buf: &mut String) {
1578 buf.push_str("/connect");
1579 if let Some(conn_link) = &self.conn_link {
1580 buf.push(' ');
1581 write!(buf, "{}", conn_link).unwrap();
1582 }
1583 }
1584}
1585
1586#[derive(Debug, Clone, PartialEq)]
1602#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1603pub struct ApiAcceptContact {
1604 pub contact_req_id: i64,
1605}
1606
1607impl CommandSyntax for ApiAcceptContact {
1608 const COMMAND_BUF_SIZE: usize = 64;
1609
1610 fn append_command_syntax(&self, buf: &mut String) {
1611 buf.push_str("/_accept ");
1612 write!(buf, "{}", self.contact_req_id).unwrap();
1613 }
1614}
1615
1616#[derive(Debug, Clone, PartialEq)]
1632#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1633pub struct ApiRejectContact {
1634 pub contact_req_id: i64,
1635}
1636
1637impl CommandSyntax for ApiRejectContact {
1638 const COMMAND_BUF_SIZE: usize = 64;
1639
1640 fn append_command_syntax(&self, buf: &mut String) {
1641 buf.push_str("/_reject ");
1642 write!(buf, "{}", self.contact_req_id).unwrap();
1643 }
1644}
1645
1646#[derive(Debug, Clone, PartialEq)]
1662#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1663pub struct ApiListContacts {
1664 pub user_id: i64,
1665}
1666
1667impl CommandSyntax for ApiListContacts {
1668 const COMMAND_BUF_SIZE: usize = 64;
1669
1670 fn append_command_syntax(&self, buf: &mut String) {
1671 buf.push_str("/_contacts ");
1672 write!(buf, "{}", self.user_id).unwrap();
1673 }
1674}
1675
1676#[derive(Debug, Clone, PartialEq)]
1692#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1693pub struct ApiListGroups {
1694 pub user_id: i64,
1695 pub contact_id: Option<i64>,
1696 pub search: Option<String>,
1697}
1698
1699impl ApiListGroups {
1700 pub fn new(user_id: i64) -> Self {
1702 Self {
1703 user_id,
1704 contact_id: None,
1705 search: None,
1706 }
1707 }
1708}
1709
1710impl CommandSyntax for ApiListGroups {
1711 const COMMAND_BUF_SIZE: usize = 256;
1712
1713 fn append_command_syntax(&self, buf: &mut String) {
1714 buf.push_str("/_groups ");
1715 write!(buf, "{}", self.user_id).unwrap();
1716 if let Some(contact_id) = &self.contact_id {
1717 buf.push(' ');
1718 buf.push('@');
1719 write!(buf, "{}", contact_id).unwrap();
1720 }
1721 if let Some(search) = &self.search {
1722 buf.push(' ');
1723 write!(buf, "{}", search).unwrap();
1724 }
1725 }
1726}
1727
1728#[derive(Debug, Clone, PartialEq)]
1744#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1745pub struct ApiGetChats {
1746 pub user_id: i64,
1747 pub pending_connections: bool,
1748 pub pagination: PaginationByTime,
1749 pub query: ChatListQuery,
1750}
1751
1752impl ApiGetChats {
1753 pub fn new(user_id: i64, pagination: PaginationByTime, query: ChatListQuery) -> Self {
1755 Self {
1756 user_id,
1757 pending_connections: false,
1758 pagination,
1759 query,
1760 }
1761 }
1762}
1763
1764impl CommandSyntax for ApiGetChats {
1765 const COMMAND_BUF_SIZE: usize = 1024;
1766
1767 fn append_command_syntax(&self, buf: &mut String) {
1768 buf.push_str("/_get ");
1769 buf.push_str("chats ");
1770 write!(buf, "{}", self.user_id).unwrap();
1771 if self.pending_connections {
1772 buf.push(' ');
1773 buf.push_str("pcc=");
1774 buf.push_str("on");
1775 }
1776 buf.push(' ');
1777 self.pagination.append_command_syntax(buf);
1778 buf.push(' ');
1779 unsafe {
1781 serde_json::to_writer(buf.as_mut_vec(), &self.query).unwrap();
1782 }
1783 }
1784}
1785
1786#[derive(Debug, Clone, PartialEq)]
1802#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1803pub struct ApiDeleteChat {
1804 pub chat_ref: ChatRef,
1805 pub chat_delete_mode: ChatDeleteMode,
1806}
1807
1808impl CommandSyntax for ApiDeleteChat {
1809 const COMMAND_BUF_SIZE: usize = 64;
1810
1811 fn append_command_syntax(&self, buf: &mut String) {
1812 buf.push_str("/_delete ");
1813 self.chat_ref.append_command_syntax(buf);
1814 buf.push(' ');
1815 self.chat_delete_mode.append_command_syntax(buf);
1816 }
1817}
1818
1819#[derive(Debug, Clone, PartialEq)]
1835#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1836pub struct ApiSetGroupCustomData {
1837 pub group_id: i64,
1838 pub custom_data: Option<JsonObject>,
1839}
1840
1841impl ApiSetGroupCustomData {
1842 pub fn new(group_id: i64) -> Self {
1844 Self {
1845 group_id,
1846 custom_data: None,
1847 }
1848 }
1849}
1850
1851impl CommandSyntax for ApiSetGroupCustomData {
1852 const COMMAND_BUF_SIZE: usize = 1024;
1853
1854 fn append_command_syntax(&self, buf: &mut String) {
1855 buf.push_str("/_set ");
1856 buf.push_str("custom ");
1857 buf.push('#');
1858 write!(buf, "{}", self.group_id).unwrap();
1859 if let Some(custom_data) = &self.custom_data {
1860 buf.push(' ');
1861 unsafe {
1863 serde_json::to_writer(buf.as_mut_vec(), &custom_data).unwrap();
1864 }
1865 }
1866 }
1867}
1868
1869#[derive(Debug, Clone, PartialEq)]
1885#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1886pub struct ApiSetContactCustomData {
1887 pub contact_id: i64,
1888 pub custom_data: Option<JsonObject>,
1889}
1890
1891impl ApiSetContactCustomData {
1892 pub fn new(contact_id: i64) -> Self {
1894 Self {
1895 contact_id,
1896 custom_data: None,
1897 }
1898 }
1899}
1900
1901impl CommandSyntax for ApiSetContactCustomData {
1902 const COMMAND_BUF_SIZE: usize = 1024;
1903
1904 fn append_command_syntax(&self, buf: &mut String) {
1905 buf.push_str("/_set ");
1906 buf.push_str("custom ");
1907 buf.push('@');
1908 write!(buf, "{}", self.contact_id).unwrap();
1909 if let Some(custom_data) = &self.custom_data {
1910 buf.push(' ');
1911 unsafe {
1913 serde_json::to_writer(buf.as_mut_vec(), &custom_data).unwrap();
1914 }
1915 }
1916 }
1917}
1918
1919#[derive(Debug, Clone, PartialEq)]
1935#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1936pub struct ApiSetUserAutoAcceptMemberContacts {
1937 pub user_id: i64,
1938 pub on_off: bool,
1939}
1940
1941impl ApiSetUserAutoAcceptMemberContacts {
1942 pub fn new(user_id: i64) -> Self {
1944 Self {
1945 user_id,
1946 on_off: false,
1947 }
1948 }
1949}
1950
1951impl CommandSyntax for ApiSetUserAutoAcceptMemberContacts {
1952 const COMMAND_BUF_SIZE: usize = 64;
1953
1954 fn append_command_syntax(&self, buf: &mut String) {
1955 buf.push_str("/_set ");
1956 buf.push_str("accept ");
1957 buf.push_str("member ");
1958 buf.push_str("contacts ");
1959 write!(buf, "{}", self.user_id).unwrap();
1960 buf.push(' ');
1961 if self.on_off {
1962 buf.push_str("on");
1963 } else {
1964 buf.push_str("off");
1965 }
1966 }
1967}
1968
1969#[derive(Debug, Clone, PartialEq)]
1985#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1986pub struct ShowActiveUser {}
1987
1988impl CommandSyntax for ShowActiveUser {
1989 const COMMAND_BUF_SIZE: usize = 0;
1990
1991 fn append_command_syntax(&self, buf: &mut String) {
1992 buf.push_str("/user");
1993 }
1994}
1995
1996#[derive(Debug, Clone, PartialEq)]
2012#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2013pub struct CreateActiveUser {
2014 pub new_user: NewUser,
2015}
2016
2017impl CommandSyntax for CreateActiveUser {
2018 const COMMAND_BUF_SIZE: usize = 1024;
2019
2020 fn append_command_syntax(&self, buf: &mut String) {
2021 buf.push_str("/_create ");
2022 buf.push_str("user ");
2023 unsafe {
2025 serde_json::to_writer(buf.as_mut_vec(), &self.new_user).unwrap();
2026 }
2027 }
2028}
2029
2030#[derive(Debug, Clone, PartialEq)]
2046#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2047pub struct ListUsers {}
2048
2049impl CommandSyntax for ListUsers {
2050 const COMMAND_BUF_SIZE: usize = 0;
2051
2052 fn append_command_syntax(&self, buf: &mut String) {
2053 buf.push_str("/users");
2054 }
2055}
2056
2057#[derive(Debug, Clone, PartialEq)]
2073#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2074pub struct ApiSetActiveUser {
2075 pub user_id: i64,
2076 pub view_pwd: Option<String>,
2077}
2078
2079impl ApiSetActiveUser {
2080 pub fn new(user_id: i64) -> Self {
2082 Self {
2083 user_id,
2084 view_pwd: None,
2085 }
2086 }
2087}
2088
2089impl CommandSyntax for ApiSetActiveUser {
2090 const COMMAND_BUF_SIZE: usize = 1024;
2091
2092 fn append_command_syntax(&self, buf: &mut String) {
2093 buf.push_str("/_user ");
2094 write!(buf, "{}", self.user_id).unwrap();
2095 if let Some(view_pwd) = &self.view_pwd {
2096 buf.push(' ');
2097 unsafe {
2099 serde_json::to_writer(buf.as_mut_vec(), &view_pwd).unwrap();
2100 }
2101 }
2102 }
2103}
2104
2105#[derive(Debug, Clone, PartialEq)]
2121#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2122pub struct ApiDeleteUser {
2123 pub user_id: i64,
2124 pub del_smp_queues: bool,
2125 pub view_pwd: Option<String>,
2126}
2127
2128impl ApiDeleteUser {
2129 pub fn new(user_id: i64) -> Self {
2131 Self {
2132 user_id,
2133 del_smp_queues: false,
2134 view_pwd: None,
2135 }
2136 }
2137}
2138
2139impl CommandSyntax for ApiDeleteUser {
2140 const COMMAND_BUF_SIZE: usize = 1024;
2141
2142 fn append_command_syntax(&self, buf: &mut String) {
2143 buf.push_str("/_delete ");
2144 buf.push_str("user ");
2145 write!(buf, "{}", self.user_id).unwrap();
2146 buf.push(' ');
2147 buf.push_str("del_smp=");
2148 if self.del_smp_queues {
2149 buf.push_str("on");
2150 } else {
2151 buf.push_str("off");
2152 }
2153 if let Some(view_pwd) = &self.view_pwd {
2154 buf.push(' ');
2155 unsafe {
2157 serde_json::to_writer(buf.as_mut_vec(), &view_pwd).unwrap();
2158 }
2159 }
2160 }
2161}
2162
2163#[derive(Debug, Clone, PartialEq)]
2179#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2180pub struct ApiUpdateProfile {
2181 pub user_id: i64,
2182 pub profile: Profile,
2183}
2184
2185impl CommandSyntax for ApiUpdateProfile {
2186 const COMMAND_BUF_SIZE: usize = 1024;
2187
2188 fn append_command_syntax(&self, buf: &mut String) {
2189 buf.push_str("/_profile ");
2190 write!(buf, "{}", self.user_id).unwrap();
2191 buf.push(' ');
2192 unsafe {
2194 serde_json::to_writer(buf.as_mut_vec(), &self.profile).unwrap();
2195 }
2196 }
2197}
2198
2199#[derive(Debug, Clone, PartialEq)]
2215#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2216pub struct ApiSetContactPrefs {
2217 pub contact_id: i64,
2218 pub preferences: Preferences,
2219}
2220
2221impl CommandSyntax for ApiSetContactPrefs {
2222 const COMMAND_BUF_SIZE: usize = 1024;
2223
2224 fn append_command_syntax(&self, buf: &mut String) {
2225 buf.push_str("/_set ");
2226 buf.push_str("prefs ");
2227 buf.push('@');
2228 write!(buf, "{}", self.contact_id).unwrap();
2229 buf.push(' ');
2230 unsafe {
2232 serde_json::to_writer(buf.as_mut_vec(), &self.preferences).unwrap();
2233 }
2234 }
2235}
2236
2237#[derive(Debug, Clone, PartialEq)]
2253#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2254pub struct StartChat {
2255 pub main_app: bool,
2256 pub enable_snd_files: bool,
2257}
2258
2259impl StartChat {
2260 pub fn new() -> Self {
2262 Self {
2263 main_app: false,
2264 enable_snd_files: false,
2265 }
2266 }
2267}
2268
2269impl CommandSyntax for StartChat {
2270 const COMMAND_BUF_SIZE: usize = 64;
2271
2272 fn append_command_syntax(&self, buf: &mut String) {
2273 buf.push_str("/_start");
2274 }
2275}
2276
2277#[derive(Debug, Clone, PartialEq)]
2293#[cfg_attr(feature = "bon", derive(::bon::Builder))]
2294pub struct ApiStopChat {}
2295
2296impl CommandSyntax for ApiStopChat {
2297 const COMMAND_BUF_SIZE: usize = 0;
2298
2299 fn append_command_syntax(&self, buf: &mut String) {
2300 buf.push_str("/_stop");
2301 }
2302}