jeudi 1 août 2019

Are there any design pattern for private chatting between 2 people?

I want to create a conversation between 2 people. I implemented a sending message part but have no idea how to implement a viewing message. So, each other people can see the messages other sent.

Should I create 1 more array in inbox class like incoming_inbox that contains the messages the other people sent to ?

Or there is any design pattern which can help me solve this problem ?

class Receiver:
    def __init__(self, sender_obj, receiver_email):
        """
        :param sender_obj: obj
        :param receiver_email: string
        """
        self.messages = []
        self.sender_email = sender_obj.getEmail()
        self.receiver_email = receiver_email

Class Account:

    def sendMessage(self, receiver_email, message):
        """

        :param receiver_email: string
        :param message: string
        :return: receiver
        """
        receiver = Receiver(self, receiver_email)
        receiver.addMessage(message) #Receiver has array that contains a lot of messages
        self.inbox.addReceiver(receiver) #Inbox has array that contains a lot of receiver

        return receiver 

Aucun commentaire:

Enregistrer un commentaire