For now? I'm experimenting on an old concept.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Split WS messages into client and server types

+22 -51
+20 -49
client/src/lumina_client.gleam
··· 42 42 UserUpdatedControlledPasswordField, UserUpdatedControlledUsernameField, 43 43 WSTryReconnect, WebSocketIncomingMessage, WsDisconnectDefinitive, 44 44 } 45 - 46 45 import lumina_client/view.{view} 47 46 import lumina_client/view/homepage 48 47 import lustre ··· 700 699 Register(..) -> #(model, effect.none()) 701 700 } 702 701 } 703 - // Ws messages we can't receive 704 - Ok(RegisterPrecheck(..)) 705 - | Ok(Undecodable) 706 - | Ok(LoginAuthenticationRequest(..)) 707 - | Ok(OwnUserInformationRequest) 708 - | Ok(TimeLineRequest(..)) 709 - | Ok(RegisterRequest(..)) -> { 710 - #(model, effect.none()) 711 - } 712 702 Ok(TimeLineResponse( 713 703 timeline_name:, 714 704 timeline_id:, ··· 795 785 ) 796 786 #(model, effect.none()) 797 787 } 788 + Ok(Undecodable) -> 789 + panic as "Received message that was explicitly marked as undecodable, this should not happen 790 + as the decoder should have returned an error instead of Undecodable. Check the decoder implementation and the logs 791 + for the raw message." 798 792 } 799 793 lustre_websocket.OnBinaryMessage(msg) -> { 800 794 console.warn( ··· 864 858 865 859 // WS Message decoding --------------------------------------------------------- 866 860 867 - type WsMsg { 861 + type WsMsgFromServer { 868 862 Greeting(greeting: String) 869 - RegisterPrecheck( 870 - email: String, 871 - username: String, 872 - // Password only once? Yes, the equal password check is done in the view/update themselves. 873 - password: String, 874 - ) 875 863 RegisterPrecheckResponse(ok: Bool, why: String) 876 - RegisterRequest(email: String, username: String, password: String) 877 - LoginAuthenticationRequest(email_username: String, password: String) 878 864 AuthenticationSuccess(username: String, token: String) 879 865 AuthenticationFailure 880 - OwnUserInformationRequest 881 - TimeLineRequest(timeline_name: String, page: Int) 882 866 TimeLineResponse( 883 867 timeline_name: String, 884 868 timeline_id: String, ··· 903 887 Undecodable 904 888 } 905 889 906 - fn encode_ws_msg(message: WsMsg) -> json.Json { 890 + type WsMsgFromClient { 891 + OwnUserInformationRequest 892 + LoginAuthenticationRequest(email_username: String, password: String) 893 + RegisterRequest(email: String, username: String, password: String) 894 + TimeLineRequest(timeline_name: String, page: Int) 895 + RegisterPrecheck( 896 + email: String, 897 + username: String, 898 + // Password only once? Yes, the equal password check is done in the view/update themselves. 899 + password: String, 900 + ) 901 + } 902 + 903 + fn encode_ws_msg(message: WsMsgFromClient) -> json.Json { 907 904 case message { 908 905 OwnUserInformationRequest -> 909 906 json.object([#("type", json.string("own_user_information_request"))]) ··· 934 931 #("by_name", json.string(timeline_name)), 935 932 #("page", json.int(page)), 936 933 ]) 937 - // And the client should never have to encode the next few: 938 - Greeting(..) 939 - | Undecodable 940 - | RegisterPrecheckResponse(..) 941 - | AuthenticationFailure 942 - | AuthenticationSuccess(..) 943 - | TimeLineResponse(..) 944 - | OwnUserInformationResponse(..) -> 945 - json.object([#("type", json.string("unknown"))]) 946 934 } 947 935 } 948 936 ··· 970 958 } 971 959 } 972 960 973 - fn ws_msg_decoder(variant: String) -> decode.Decoder(WsMsg) { 961 + fn ws_msg_decoder(variant: String) -> decode.Decoder(WsMsgFromServer) { 974 962 case variant { 975 963 "auth_success" -> { 976 964 use username <- decode.field("username", decode.string) ··· 981 969 decode.success(AuthenticationFailure) 982 970 } 983 971 "unknown" -> decode.success(Undecodable) 984 - "login_authentication_request" -> { 985 - use email_username <- decode.field("email_username", decode.string) 986 - use password <- decode.field("password", decode.string) 987 - decode.success(LoginAuthenticationRequest(email_username, password)) 988 - } 989 - "register_request" -> { 990 - use email <- decode.field("email", decode.string) 991 - use username <- decode.field("username", decode.string) 992 - use password <- decode.field("password", decode.string) 993 - decode.success(RegisterRequest(email, username, password)) 994 - } 995 - "register_precheck" -> { 996 - use email <- decode.field("email", decode.string) 997 - use username <- decode.field("username", decode.string) 998 - use password <- decode.field("password", decode.string) 999 - decode.success(RegisterPrecheck(email, username, password)) 1000 - } 1001 972 "register_precheck_response" -> { 1002 973 use ok <- decode.field("ok", decode.bool) 1003 974 use why <- decode.field("why", decode.string)
+2 -2
client/src/lumina_client/view/homepage.gleam
··· 818 818 element.text("User settings will be here eventually."), 819 819 ]), 820 820 ) 821 - "mdl-postedit" -> { 821 + "mdl-postedit" -> 822 822 CentralSmall( 823 823 "mdl-postedit", 824 824 "New Post", ··· 826 826 True, 827 827 params:, 828 828 ) 829 - } 829 + 830 830 _ -> NoModal 831 831 } 832 832 }