6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-24 07:48:19 +00:00

fix: outbox-subscribe (#131)

Co-authored-by: Jon Lundy <jon@xuu.cc>
Co-authored-by: xuu <me@sour.is>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/131
Co-authored-by: xuu <xuu@noreply@mills.io>
Co-committed-by: xuu <xuu@noreply@mills.io>
This commit is contained in:
xuu 2022-04-03 01:03:45 +00:00 committed by James Mills
parent 35c4ecca6f
commit 5b01e82897
2 changed files with 18 additions and 9 deletions

@ -123,6 +123,7 @@ func (h *SaltyChat) connect(ctx app.Context) {
return
case msg := <-inboxCh:
// passing both the message and the text in case we need the message key at some point
ctx.NewActionWithValue(saltyChatRecvMessageAction, msg, app.T("text", msg.Text))
case msg := <-outboxCh:
// passing both the message and the text in case we need the message key at some point
@ -139,7 +140,7 @@ func (h *SaltyChat) incomingMessage(ctx app.Context, action app.Action) {
h.dialog.ShowDialog("incoming message error", err.Error())
return
}
log.Print("in: ", s)
=
switch s := s.(type) {
case *lextwt.SaltyText:
user := s.User.String()
@ -168,19 +169,27 @@ func (h *SaltyChat) outgoingMessage(ctx app.Context, action app.Action) {
h.dialog.ShowDialog("outgoing message error", err.Error())
return
}
log.Print("out:", s)
friend := ""
switch s := s.(type) {
case *lextwt.SaltyText:
friend := s.User.String()
friend = s.User.String()
storage.ContactsLocalStorage(ctx).Add(friend)
storage.ConversationsLocalStorage(ctx, friend).
Append(string(saltyim.PackMessage(client.Me(), s.LiteralText())))
}
// only update when incoming user's message is the active chat
if h.friend == friend {
h.chatBox.UpdateMessages(ctx)
} else {
// TODO: Creates some initial content of the new chat
// to give the user a change to Accept/Reject the contact.
log.Printf("new incoming chat from %s", friend)
}
}
func (h *SaltyChat) Render() app.UI {
topBar := &bar.TopAppBar{Title: "Salty IM",
Navigation: []app.HTMLButton{icon.MIMenu.Button().OnClick(func(ctx app.Context, e app.Event) {
h.navigation.drawer.ActionOpen(ctx)
@ -238,9 +247,9 @@ func (h *SaltyChat) handleSendMessage(ctx app.Context, e app.Event) {
h.chatBox.User = h.friend
ctx.Async(func() {
if err := client.Send(h.friend, msg); err == nil {
storage.ConversationsLocalStorage(ctx, h.friend).
Append(string(saltyim.PackMessage(client.Me(), msg)))
h.chatBox.UpdateMessages(ctx)
// storage.ConversationsLocalStorage(ctx, h.friend).
// Append(string(saltyim.PackMessage(client.Me(), msg)))
// h.chatBox.UpdateMessages(ctx)
} else {
h.dialog.ShowDialog("error sending message", err.Error())
}

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2ec05cfce9cd986c818ce909a2b0048f032f71df80c50497f15d3c7aaf1e9ef2
size 28584522
oid sha256:dfc1cdc5ff7fd12413b61cea7f7411a75c64b19e861ad4734db46a45b19a0a5e
size 28572009