]> git.giacomolli.uk - onechat/blobdiff - whatsapp_batch.go
Separate multiline Go statements
[onechat] / whatsapp_batch.go
index 08dfb6aec76733faf0d58e8774836e9166cd4783..dcdd712a8fdf2e938e3842e5bf2966dd0cb8a62c 100644 (file)
@@ -27,6 +27,27 @@ type WhatsAppBatch struct {
        Messages []WhatsAppMessage `json:"messages"`
 }
 
        Messages []WhatsAppMessage `json:"messages"`
 }
 
+// WhatsAppChat is a chat: its ID, its name, and whether it is a group.
+type WhatsAppChat struct {
+       ID    string `json:"id"`
+       Name  string `json:"name"`
+       Group bool   `json:"group,omitempty"`
+}
+
+// WhatsAppMessage is one message of a batch: its ID, the name of its sender,
+// its WhatsApp time, and its text. Mine marks a message of the user. Mention
+// and Reply mark a message that mentions the user or replies to a message of
+// the user.
+type WhatsAppMessage struct {
+       ID      string    `json:"id"`
+       Sender  string    `json:"sender"`
+       Time    time.Time `json:"time"`
+       Text    string    `json:"text"`
+       Mine    bool      `json:"mine,omitempty"`
+       Mention bool      `json:"mention,omitempty"`
+       Reply   bool      `json:"reply,omitempty"`
+}
+
 // Turn tells if the batch starts a turn: a private batch with a message of
 // another person, or a group batch with a message of another person that
 // mentions the user or replies to a message of the user.
 // Turn tells if the batch starts a turn: a private batch with a message of
 // another person, or a group batch with a message of another person that
 // mentions the user or replies to a message of the user.
@@ -40,7 +61,8 @@ func (b WhatsAppBatch) Turn() bool {
 // The first line starts with [WhatsApp] and names the chat, its ID, and the day
 // of the first message. Each message has a line with its time and its sender,
 // and the messages of the user have the sender You. A batch that starts a turn
 // The first line starts with [WhatsApp] and names the chat, its ID, and the day
 // of the first message. Each message has a line with its time and its sender,
 // and the messages of the user have the sender You. A batch that starts a turn
-// ends with the line about the empty reply.
+// ends with the line about the empty reply. Image markers start on their own
+// lines so that the shared image reader can find them.
 func (b WhatsAppBatch) Text(location *time.Location) string {
        kind := "private chat"
        if b.Chat.Group {
 func (b WhatsAppBatch) Text(location *time.Location) string {
        kind := "private chat"
        if b.Chat.Group {
@@ -59,7 +81,12 @@ func (b WhatsAppBatch) Text(location *time.Location) string {
                        sender += " (replies to you)"
                }
 
                        sender += " (replies to you)"
                }
 
-               lines = append(lines, message.Time.In(location).Format("15:04")+" "+sender+": "+message.Text)
+               prefix := message.Time.In(location).Format("15:04") + " " + sender + ":"
+               if len(imageFiles(message.Text)) > 0 {
+                       lines = append(lines, prefix, message.Text)
+               } else {
+                       lines = append(lines, prefix+" "+message.Text)
+               }
        }
 
        if b.Turn() {
        }
 
        if b.Turn() {
@@ -68,24 +95,3 @@ func (b WhatsAppBatch) Text(location *time.Location) string {
 
        return strings.Join(lines, "\n")
 }
 
        return strings.Join(lines, "\n")
 }
-
-// WhatsAppChat is a chat: its ID, its name, and whether it is a group.
-type WhatsAppChat struct {
-       ID    string `json:"id"`
-       Name  string `json:"name"`
-       Group bool   `json:"group,omitempty"`
-}
-
-// WhatsAppMessage is one text message of a batch: its ID, the name of its
-// sender, its WhatsApp time, and its text. Mine marks a message of the user.
-// Mention and Reply mark a message that mentions the user or replies to a
-// message of the user.
-type WhatsAppMessage struct {
-       ID      string    `json:"id"`
-       Sender  string    `json:"sender"`
-       Time    time.Time `json:"time"`
-       Text    string    `json:"text"`
-       Mine    bool      `json:"mine,omitempty"`
-       Mention bool      `json:"mention,omitempty"`
-       Reply   bool      `json:"reply,omitempty"`
-}