diff --git a/main.go b/main.go index 85a7d6c..72a3494 100644 --- a/main.go +++ b/main.go @@ -439,6 +439,7 @@ func main() { client.SetDmHandler(func(client *oasisSdk.XmppClient, msg *oasisSdk.XMPPChatMessage) { correction := false userJidStr := msg.From.Bare().String() + fmt.Println(userJidStr) tab, ok := chatTabs[userJidStr] if ok { str := *msg.CleanedBody @@ -474,6 +475,7 @@ func main() { if msg.Reply == nil { replyID = "PICLIENT:UNAVAILABLE" } else { + fmt.Println("Received reply in DM") replyID = msg.Reply.ID } @@ -500,16 +502,15 @@ func main() { tab.Messages = append(tab.Messages, myMessage) fyne.Do(func() { - UITabs[userJidStr].Scroller.Refresh() + //UITabs[userJidStr].Scroller.Refresh() if scrollDownOnNewMessage { - UITabs[userJidStr].Scroller.ScrollToBottom() + //UITabs[userJidStr].Scroller.ScrollToBottom() } }) } }) client.SetGroupChatHandler(func(client *oasisSdk.XmppClient, muc *muc.Channel, msg *oasisSdk.XMPPChatMessage) { - // HACK: IGNORING ALL MESSAGES FROM CLASSIC MUC HISTORY IN PREPARATION OF MAM SUPPORT ignore := false correction := false important := false @@ -533,6 +534,8 @@ func main() { var ImageID string = "" mucJidStr := msg.From.Bare().String() if tab, ok := chatTabs[mucJidStr]; ok { + chatInfo.Objects[0] = widget.NewLabel(fmt.Sprintf("[!] %s", mucJidStr)) + chatInfo.Refresh() chatTabs[mucJidStr].Muc = muc str := *msg.CleanedBody if strings.Contains(str, login.DisplayName) { @@ -631,6 +634,8 @@ func main() { bareAcc := from.Bare() tab, ok := chatTabs[bareAcc.String()] if !ok { + // User presence + addChatTab(false, bareAcc, client.Login.DisplayName) return } @@ -703,6 +708,17 @@ func main() { a = app.New() w = a.NewWindow("pi") + w.SetCloseIntercept(func() { + dialog.ShowConfirm("Close pi", "You hit the close button. Do you want Pi to close completely (confirm) or minimize to the tray? (cancel)", func(b bool) { + if b { + w.Close() + a.Quit() + log.Fatalln("Goodbye!") + } else { + w.Hide() + } + }, w) + }) w.Resize(fyne.NewSize(500, 500)) entry := NewCustomMultiLineEntry() @@ -763,6 +779,23 @@ func main() { } }, w) + + } else if text == "@here" && chatTabs[activeMucJid].isMuc { + tab := chatTabs[activeMucJid] + dialog.ShowConfirm("WARNING", fmt.Sprintf("There are %d members in this room.\nYou are about to mention every single one of them.\nYou may be punished if you are not a moderator of this chat.\nWould you like to continue?", len(tab.Members)), func(b bool) { + + if b { + text = "" + for name := range tab.Members { + text = fmt.Sprintf("%s %s", text, jid.MustParse(name).Resourcepart()) + } + + err = client.SendText(jid.MustParse(activeMucJid).Bare(), text) + if err != nil { + dialog.ShowError(err, w) + } + } + }, w) } else { err = client.SendText(jid.MustParse(activeMucJid).Bare(), text) @@ -1050,6 +1083,7 @@ func main() { AppTabs.Items[0].Content = myScroller AppTabs.Items[0].Text = "Bookmarks" AppTabs.SelectIndex(0) + chatSidebar.Hidden = true //d := dialog.NewCustom("manage bookmarks", "cancel", myScroller, w) //d.Show() @@ -1152,6 +1186,40 @@ func main() { entry.Text = old }) + kai := fyne.NewMenuItem("kai cenat beg", func() { + old := entry.Text + entry.Text = "chat will you subscribe to save the kai cenat mafiathon 3" + SendCallback() + entry.Text = old + }) + + mipipiemi := fyne.NewMenuItem("mi pipi e mi", func() { + old := entry.Text + entry.Text = "mi pipi e mi" + SendCallback() + entry.Text = old + }) + + exposed_suffix := fyne.NewMenuItem(".exposed", func() { + selectedScroller, ok := AppTabs.Selected().Content.(*widget.List) + if !ok { + return + } + var activeChatJid string + for jid, tabData := range UITabs { + if tabData.Scroller == selectedScroller { + activeChatJid = jid + } + } + + LatestMessage := chatTabs[activeChatJid].Messages[len(chatTabs[activeChatJid].Messages)-1] + + old := entry.Text + entry.Text = fmt.Sprintf("%s.exposed", LatestMessage.Content) + SendCallback() + entry.Text = old + }) + mycurrenttime := fyne.NewMenuItem("Current time", func() { entry.Text = fmt.Sprintf("It is currently %s", time.Now().Format(time.RFC850)) SendCallback() @@ -1208,7 +1276,7 @@ func main() { } }) - menu_jokes := fyne.NewMenu("Δ", mycurrenttime, hafjag, hotfuck, agree, mycurrentplayingsong) + menu_jokes := fyne.NewMenu("Δ", mycurrenttime, mycurrentplayingsong, hafjag, hotfuck, agree, kai, mipipiemi, exposed_suffix) bit := fyne.NewMenuItem("mark selected message as read", func() { selectedScroller, ok := AppTabs.Selected().Content.(*widget.List) if !ok { @@ -1299,7 +1367,7 @@ func main() { desk, ok := a.(desktop.App) if ok { - desk.SetSystemTrayMenu(menu_help) + desk.SetSystemTrayMenu(fyne.NewMenu("", fyne.NewMenuItem("show", w.Show))) } AppTabs = container.NewAppTabs( @@ -1307,7 +1375,7 @@ func main() { pi This tab will be used for displaying certain actions, such as - managing your bookmarks configuring rooms. + managing your bookmarks and configuring rooms. `)), ) @@ -1320,6 +1388,10 @@ func main() { } AppTabs.OnSelected = func(ti *container.TabItem) { + if AppTabs.Selected() == AppTabs.Items[0] { + chatSidebar.Hidden = true + return + } selectedScroller, ok := AppTabs.Selected().Content.(*widget.List) if !ok { return @@ -1335,53 +1407,65 @@ func main() { tab := chatTabs[activeChatJid] UITab := UITabs[activeChatJid] - if tab.isMuc { - //chatInfo = *container.NewHBox(widget.NewLabel(tab.Muc.Addr().String())) - } else { - chatInfo = *container.NewHBox(widget.NewLabel(tab.Jid.String())) - } chatSidebar = *UITab.Sidebar - box := container.NewVBox(widget.NewRichTextFromMarkdown("# "+activeChatJid), widget.NewLabel(fmt.Sprintf("%d members ", len(tab.Members)))) - chatSidebar.Objects = []fyne.CanvasObject{} + if tab.isMuc { + box := container.NewVBox(widget.NewRichTextFromMarkdown("# "+activeChatJid), widget.NewLabel(fmt.Sprintf("%d members ", len(tab.Members)))) + chatSidebar.Objects = []fyne.CanvasObject{} - for name := range tab.Members { - gen, _ := identicon.New("github", 5, 3) - userjid, err := jid.Parse(name) - if err != nil { - fmt.Println("ERROR: " + err.Error()) - continue // unrecoverable - } - nickname := userjid.Resourcepart() - if nickname == "" { - continue // we got the MUC presence, do not include it in the member list - } - ii, err := gen.Draw(nickname) - mention := func() { - entry.SetText(fmt.Sprintf("%s %s", entry.Text, nickname)) - } - if err != nil { - fmt.Println("ERROR: " + err.Error()) - box.Add(container.NewHBox(widget.NewLabel(nickname), widget.NewButton("Mention", mention))) - } else { - im := ii.Image(25) - imageWidget := canvas.NewImageFromImage(im) - imageWidget.FillMode = canvas.ImageFillOriginal - imageWidget.Refresh() - nickLabel := widget.NewLabel(nickname) - nickLabel.Selectable = true - box.Add(container.NewHBox(imageWidget, nickLabel)) - } + for name, p := range tab.Members { + gen, _ := identicon.New("github", 5, 3) + userjid, err := jid.Parse(name) + if err != nil { + fmt.Println("ERROR: " + err.Error()) + continue // unrecoverable + } + nickname := userjid.Resourcepart() + if nickname == "" { + continue // we got the MUC presence, do not include it in the member list + } + ii, err := gen.Draw(nickname) + mention := func() { + entry.SetText(fmt.Sprintf("%s %s", entry.Text, nickname)) + } + if err != nil { + fmt.Println("ERROR: " + err.Error()) + box.Add(container.NewHBox(widget.NewLabel(nickname), widget.NewButton("Mention", mention))) + } else { + im := ii.Image(25) + imageWidget := canvas.NewImageFromImage(im) + imageWidget.FillMode = canvas.ImageFillOriginal + imageWidget.Refresh() + nickLabel := widget.NewLabel(nickname) + nickLabel.Selectable = true + box.Add(container.NewHBox(imageWidget, nickLabel)) + if p.Status != "" { + s := widget.NewLabel(fmt.Sprintf("\"%s\"", p.Status)) + s.Importance = widget.WarningImportance + s.TextStyle = fyne.TextStyle{ + Bold: false, + Italic: true, + Monospace: false, + } + s.Truncation = fyne.TextTruncateEllipsis + box.Add(s) + } + } + + } + chatSidebar = *container.NewGridWithColumns(1, container.NewVScroll(box)) + } else { + chatSidebar = *container.NewVBox(widget.NewRichTextFromMarkdown("# " + activeChatJid)) } - chatSidebar = *container.NewGridWithColumns(1, container.NewVScroll(box)) + chatSidebar.Hidden = false chatSidebar.Refresh() } - // HACK - disable chatsidebar because it's currently very buggy chatSidebar.Hidden = false statBar.SetText("") + chatInfo = *container.NewHBox(widget.NewLabel("")) w.SetContent(container.NewVSplit(container.NewVSplit(container.NewHSplit(AppTabs, &chatSidebar), container.NewHSplit(entry, container.NewGridWithRows(1, sendbtn, replybtn))), container.NewHSplit(&statBar, &chatInfo))) w.ShowAndRun() }